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/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index 16d0239..e46bf8e 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -14,6 +14,7 @@
#include "update_engine/flimflam_proxy.h"
#include "update_engine/utils.h"
+using google::protobuf::NewCallback;
using std::max;
using std::make_pair;
using std::string;
@@ -151,14 +152,25 @@
// Begins the transfer, which must not have already been started.
void LibcurlHttpFetcher::BeginTransfer(const std::string& url) {
+ CHECK(!transfer_in_progress_);
+ url_ = url;
+ if (!ResolveProxiesForUrl(
+ url_,
+ NewCallback(this, &LibcurlHttpFetcher::ProxiesResolved))) {
+ LOG(ERROR) << "Couldn't resolve proxies";
+ if (delegate_)
+ delegate_->TransferComplete(this, false);
+ }
+}
+
+void LibcurlHttpFetcher::ProxiesResolved() {
transfer_size_ = -1;
resume_offset_ = 0;
retry_count_ = 0;
no_network_retry_count_ = 0;
http_response_code_ = 0;
terminate_requested_ = false;
- ResolveProxiesForUrl(url);
- ResumeTransfer(url);
+ ResumeTransfer(url_);
CurlPerformOnce();
}