Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <curl/curl.h> | 10 #include <curl/curl.h> |
| 11 #include <glib.h> | 11 #include <glib.h> |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "update_engine/http_fetcher.h" | 14 #include "update_engine/http_fetcher.h" |
| 15 | 15 |
| 16 // This is a concrete implementation of HttpFetcher that uses libcurl to do the | 16 // This is a concrete implementation of HttpFetcher that uses libcurl to do the |
| 17 // http work. | 17 // http work. |
| 18 | 18 |
| 19 namespace chromeos_update_engine { | 19 namespace chromeos_update_engine { |
| 20 | 20 |
| 21 class LibcurlHttpFetcher : public HttpFetcher { | 21 class LibcurlHttpFetcher : public HttpFetcher { |
| 22 public: | 22 public: |
| 23 static const int kMaxRedirects = 10; | 23 static const int kMaxRedirects = 10; |
| 24 | 24 |
| 25 LibcurlHttpFetcher() | 25 LibcurlHttpFetcher(ProxyResolver* proxy_resolver) |
|
petkov
2010/11/19 05:37:15
explicit?
adlr
2010/11/20 02:52:29
Done.
| |
| 26 : curl_multi_handle_(NULL), | 26 : HttpFetcher(proxy_resolver), |
| 27 curl_multi_handle_(NULL), | |
| 27 curl_handle_(NULL), | 28 curl_handle_(NULL), |
| 28 timeout_source_(NULL), | 29 timeout_source_(NULL), |
| 29 transfer_in_progress_(false), | 30 transfer_in_progress_(false), |
| 30 transfer_size_(0), | 31 transfer_size_(0), |
| 31 bytes_downloaded_(0), | 32 bytes_downloaded_(0), |
| 32 resume_offset_(0), | 33 resume_offset_(0), |
| 33 retry_count_(0), | 34 retry_count_(0), |
| 34 retry_seconds_(60), | 35 retry_seconds_(60), |
| 35 idle_seconds_(1), | 36 idle_seconds_(1), |
| 36 force_connection_type_(false), | 37 force_connection_type_(false), |
| 37 forced_expensive_connection_(false), | 38 forced_expensive_connection_(false), |
| 38 force_build_type_(false), | 39 force_build_type_(false), |
| 39 forced_official_build_(false), | 40 forced_official_build_(false), |
| 40 in_write_callback_(false), | 41 in_write_callback_(false), |
| 42 sent_byte_(false), | |
| 41 terminate_requested_(false) {} | 43 terminate_requested_(false) {} |
| 42 | 44 |
| 43 // Cleans up all internal state. Does not notify delegate | 45 // Cleans up all internal state. Does not notify delegate |
| 44 ~LibcurlHttpFetcher(); | 46 ~LibcurlHttpFetcher(); |
| 45 | 47 |
| 46 void SetOffset(off_t offset) { bytes_downloaded_ = offset; } | 48 void SetOffset(off_t offset) { bytes_downloaded_ = offset; } |
| 47 | 49 |
| 48 // Begins the transfer if it hasn't already begun. | 50 // Begins the transfer if it hasn't already begun. |
| 49 virtual void BeginTransfer(const std::string& url); | 51 virtual void BeginTransfer(const std::string& url); |
| 50 | 52 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 bool force_connection_type_; | 193 bool force_connection_type_; |
| 192 bool forced_expensive_connection_; | 194 bool forced_expensive_connection_; |
| 193 | 195 |
| 194 // If true, assume the build is official or not, according to | 196 // If true, assume the build is official or not, according to |
| 195 // forced_official_build_. Useful for testing. | 197 // forced_official_build_. Useful for testing. |
| 196 bool force_build_type_; | 198 bool force_build_type_; |
| 197 bool forced_official_build_; | 199 bool forced_official_build_; |
| 198 | 200 |
| 199 // If true, we are currently performing a write callback on the delegate. | 201 // If true, we are currently performing a write callback on the delegate. |
| 200 bool in_write_callback_; | 202 bool in_write_callback_; |
| 203 | |
| 204 // If true, we have returned at least one byte in the write callback | |
| 205 // to the delegate. | |
| 206 bool sent_byte_; | |
| 201 | 207 |
| 202 // We can't clean everything up while we're in a write callback, so | 208 // We can't clean everything up while we're in a write callback, so |
| 203 // if we get a terminate request, queue it until we can handle it. | 209 // if we get a terminate request, queue it until we can handle it. |
| 204 bool terminate_requested_; | 210 bool terminate_requested_; |
| 205 | 211 |
| 206 DISALLOW_COPY_AND_ASSIGN(LibcurlHttpFetcher); | 212 DISALLOW_COPY_AND_ASSIGN(LibcurlHttpFetcher); |
| 207 }; | 213 }; |
| 208 | 214 |
| 209 } // namespace chromeos_update_engine | 215 } // namespace chromeos_update_engine |
| 210 | 216 |
| 211 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ | 217 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ |
| OLD | NEW |