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/http_fetcher.cc b/http_fetcher.cc
index 5d00660..7d9297a 100644
--- a/http_fetcher.cc
+++ b/http_fetcher.cc
@@ -4,11 +4,19 @@
#include "update_engine/http_fetcher.h"
+using google::protobuf::Closure;
using std::deque;
using std::string;
namespace chromeos_update_engine {
+HttpFetcher::~HttpFetcher() {
+ if (no_resolver_idle_id_) {
+ g_source_remove(no_resolver_idle_id_);
+ no_resolver_idle_id_ = 0;
+ }
+}
+
void HttpFetcher::SetPostData(const void* data, size_t size) {
post_data_set_ = true;
post_data_.clear();
@@ -17,15 +25,24 @@
}
// Proxy methods to set the proxies, then to pop them off.
-void HttpFetcher::ResolveProxiesForUrl(const string& url) {
+bool HttpFetcher::ResolveProxiesForUrl(const string& url, Closure* callback) {
if (!proxy_resolver_) {
LOG(INFO) << "Not resolving proxies (no proxy resolver).";
- return;
+ no_resolver_idle_id_ = g_idle_add(utils::GlibRunClosure, callback);
+ return true;
}
- deque<string> proxies;
- if (proxy_resolver_->GetProxiesForUrl(url, &proxies)) {
+ callback_ = callback;
+ return proxy_resolver_->GetProxiesForUrl(url,
+ &HttpFetcher::StaticProxiesResolved,
+ this);
+}
+
+void HttpFetcher::ProxiesResolved(const std::deque<std::string>& proxies) {
+ no_resolver_idle_id_ = 0;
+ if (!proxies.empty())
SetProxies(proxies);
- }
+ callback_->Run();
+ callback_ = NULL;
}
} // namespace chromeos_update_engine