AU: Make proxy resolution asynchronous.
This doesn't change proxy resolution overall (we still use settings
stored in the session manager), but it changes the implementation in
the updater to be asynchronous. The clients of the proxy resolver now
give a callback to be called when the proxies are known.
This is anticipation of a switch to using Chrome to resolve proxies,
which will need to be asynchronous.
BUG=chromium-os:12079
TEST=unittests; tested update on device w/ and w/o proxy settings
Review URL: http://codereview.chromium.org/6516026
Change-Id: Icc5c08e3abf4381be55d8d555020d4c630a07fd6
diff --git a/chrome_proxy_resolver.cc b/chrome_proxy_resolver.cc
index 66bc5dc..1deab11 100644
--- a/chrome_proxy_resolver.cc
+++ b/chrome_proxy_resolver.cc
@@ -10,6 +10,9 @@
#include "update_engine/utils.h"
+using google::protobuf::Closure;
+using google::protobuf::NewCallback;
+using std::deque;
using std::string;
using std::vector;
@@ -24,16 +27,32 @@
bool ChromeProxyResolver::GetProxiesForUrl(
const std::string& url,
- std::deque<std::string>* out_proxies) {
+ ProxiesResolvedFn callback,
+ void* data) {
+ ChromeProxyResolverClosureArgs args;
+ args.url = url;
+ args.callback = callback;
+ args.data = data;
+ Closure* closure = NewCallback(this,
+ &ChromeProxyResolver::GetProxiesForUrlCallback,
+ args);
+ g_idle_add(utils::GlibRunClosure, closure);
+ return true;
+}
+
+void ChromeProxyResolver::GetProxiesForUrlCallback(
+ ChromeProxyResolverClosureArgs args) {
+ deque<string> proxies;
// First, query dbus for the currently stored settings
DBusGProxy* proxy = DbusProxy();
- TEST_AND_RETURN_FALSE(proxy);
- string json_settings;
- TEST_AND_RETURN_FALSE(GetJsonProxySettings(proxy, &json_settings));
- LOG(INFO) << "got settings:" << json_settings;
- TEST_AND_RETURN_FALSE(
- GetProxiesForUrlWithSettings(url, json_settings, out_proxies));
- return true;
+ if (proxy) {
+ string json_settings;
+ if (GetJsonProxySettings(proxy, &json_settings)) {
+ LOG(INFO) << "got settings:" << json_settings;
+ GetProxiesForUrlWithSettings(args.url, json_settings, &proxies);
+ }
+ }
+ (*args.callback)(proxies, args.data);
}
bool ChromeProxyResolver::GetJsonProxySettings(DBusGProxy* proxy,