Chromium Code Reviews| Index: http_fetcher.h |
| diff --git a/http_fetcher.h b/http_fetcher.h |
| index 6d8608b62996f72d7d198983917471f360dc3913..cb9f0c5d75d9b457e21f572bd6a738b64877c23a 100644 |
| --- a/http_fetcher.h |
| +++ b/http_fetcher.h |
| @@ -5,10 +5,15 @@ |
| #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ |
| #define CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ |
| +#include <deque> |
| #include <string> |
| #include <vector> |
| + |
| #include <glib.h> |
| -#include "base/basictypes.h" |
| +#include <base/basictypes.h> |
|
petkov
2010/11/19 05:37:15
sort
adlr
2010/11/20 02:52:29
Done.
|
| +#include <base/logging.h> |
| + |
| +#include "update_engine/proxy_resolver.h" |
| // This class is a simple wrapper around an HTTP library (libcurl). We can |
| // easily mock out this interface for testing. |
| @@ -23,10 +28,12 @@ class HttpFetcherDelegate; |
| class HttpFetcher { |
| public: |
| - HttpFetcher() |
| + explicit HttpFetcher(ProxyResolver* proxy_resolver) |
|
petkov
2010/11/19 05:37:15
a brief docstring might be useful -- can proxy_res
adlr
2010/11/20 02:52:29
decided to allow NULL and documented it as such.
|
| : post_data_set_(false), |
| http_response_code_(0), |
| - delegate_(NULL) {} |
| + delegate_(NULL), |
| + proxies_(1, kNoProxy), |
| + proxy_resolver_(proxy_resolver) {} |
| virtual ~HttpFetcher() {} |
| void set_delegate(HttpFetcherDelegate* delegate) { delegate_ = delegate; } |
| @@ -42,6 +49,28 @@ class HttpFetcher { |
| post_data_.insert(post_data_.end(), char_data, char_data + size); |
| } |
| + // Proxy methods to set the proxies, then to pop them off. |
| + void ResolveProxiesForUrl(const std::string& url) { |
| + if (!proxy_resolver_) { |
|
petkov
2010/11/19 05:37:15
Lots of code for a header file. I'd suggest move a
adlr
2010/11/20 02:52:29
Done.
|
| + LOG(ERROR) << "Missing proxy resolver!"; |
|
petkov
2010/11/19 05:37:15
Why an ERROR? Maybe just default to kNoProxy. If n
adlr
2010/11/20 02:52:29
fixed. NULL now legal
|
| + } |
| + std::vector<std::string> proxies; |
| + if (!proxy_resolver_->GetProxiesForUrl(url, &proxies)) { |
| + // just do direct |
| + proxies.push_back(kNoProxy); |
| + } |
| + SetProxies(proxies); |
| + } |
| + void SetProxies(const std::vector<std::string>& proxies) { |
| + proxies_.clear(); |
| + proxies_.insert(proxies_.begin(), proxies.begin(), proxies.end()); |
|
petkov
2010/11/19 05:37:15
you could probably just proxies_.assign(begin, end
adlr
2010/11/20 02:52:29
Done.
|
| + } |
| + const std::string& CurrentProxy() const { |
| + return proxies_.front(); |
| + } |
| + bool HasProxy() const { return !proxies_.empty(); } |
| + void PopProxy() { proxies_.pop_front(); } |
| + |
| // Downloading should resume from this offset |
| virtual void SetOffset(off_t offset) = 0; |
| @@ -84,6 +113,12 @@ class HttpFetcher { |
| // The delegate; may be NULL. |
| HttpFetcherDelegate* delegate_; |
| + |
| + // Proxy servers |
| + std::deque<std::string> proxies_; |
| + |
| + ProxyResolver* const proxy_resolver_; |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(HttpFetcher); |
| }; |