AU: Manual proxy support
Utilize the ChromeProxyResolver to resolve proxies in our network
requests. This means the following changes:
- HttpFetcher classes take a ProxyResolver* in their ctor. Also, a few
useful functions in HttpFetcher to allow subclasses to iterate
through the proxies.
- LibcurlHttpFetcher support for using the ProxyResolver. It will
attempt to use each proxy in the order specified. If any data comes
in from any proxy, it won't continue down the list and will continue
to use that proxy for its lifetime.
- UpdateAttempter can choose, for a given update session, whether or
not to use the ChromeProxyResolver or DirectProxyResolver. For now,
the logic is: for automatic checks, 80% of the time use
ChromeProxyResolver, 20% DirectProxyResolver. For manual checks, the
first 19 manual checks in a row use Chrome, then once it uses
Direct, then starts over again. The idea is that the updater doesn't
necessarily trust Chrome, so some requests should skip it. If a
manual check is performed, the user likely wants her proxy settings
honored, so use them, but don't allow frequent manual checks to
starve out usage of the DirectProxyResolver.
- Updates to tests
BUG=3167
TEST=unittests, tested on device
Review URL: http://codereview.chromium.org/5205002
Change-Id: Iee0f589e5b28d4b804afe1f5b6729ba066d48d62
diff --git a/http_fetcher.cc b/http_fetcher.cc
new file mode 100644
index 0000000..5d00660
--- /dev/null
+++ b/http_fetcher.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "update_engine/http_fetcher.h"
+
+using std::deque;
+using std::string;
+
+namespace chromeos_update_engine {
+
+void HttpFetcher::SetPostData(const void* data, size_t size) {
+ post_data_set_ = true;
+ post_data_.clear();
+ const char *char_data = reinterpret_cast<const char*>(data);
+ post_data_.insert(post_data_.end(), char_data, char_data + size);
+}
+
+// Proxy methods to set the proxies, then to pop them off.
+void HttpFetcher::ResolveProxiesForUrl(const string& url) {
+ if (!proxy_resolver_) {
+ LOG(INFO) << "Not resolving proxies (no proxy resolver).";
+ return;
+ }
+ deque<string> proxies;
+ if (proxy_resolver_->GetProxiesForUrl(url, &proxies)) {
+ SetProxies(proxies);
+ }
+}
+
+} // namespace chromeos_update_engine