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/proxy_resolver.cc b/proxy_resolver.cc
index 4ec8d1e..26dff7b 100644
--- a/proxy_resolver.cc
+++ b/proxy_resolver.cc
@@ -11,11 +11,32 @@
 
 const char kNoProxy[] = "direct://";
 
-bool DirectProxyResolver::GetProxiesForUrl(const string& url,
-                                           deque<string>* out_proxies) {
-  out_proxies->clear();
-  out_proxies->push_back(kNoProxy);
+DirectProxyResolver::~DirectProxyResolver() {
+  if (idle_callback_id_) {
+    g_source_remove(idle_callback_id_);
+    idle_callback_id_ = 0;
+  }
+}
+
+bool DirectProxyResolver::GetProxiesForUrl(const std::string& url,
+                                           ProxiesResolvedFn callback,
+                                           void* data) {
+  google::protobuf::Closure* closure =
+      google::protobuf::NewCallback(this,
+                                    &DirectProxyResolver::ReturnCallback,
+                                    callback,
+                                    data);
+  idle_callback_id_ = g_idle_add(utils::GlibRunClosure, closure);
   return true;
 }
 
+void DirectProxyResolver::ReturnCallback(ProxiesResolvedFn callback,
+                                         void* data) {
+  idle_callback_id_ = 0;
+  std::deque<std::string> proxies;
+  proxies.push_back(kNoProxy);
+  (*callback)(proxies, data);
+}
+
+
 }  // namespace chromeos_update_engine