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 "chromeos/obsolete_logging.h" | 13 #include "chromeos/obsolete_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 LibcurlHttpFetcher() | 23 LibcurlHttpFetcher() |
24 : curl_multi_handle_(NULL), curl_handle_(NULL), | 24 : curl_multi_handle_(NULL), curl_handle_(NULL), |
25 timeout_source_(NULL), transfer_in_progress_(false), | 25 timeout_source_(NULL), transfer_in_progress_(false), |
26 idle_ms_(1000) {} | 26 retry_count_(0), idle_ms_(1000) {} |
27 | 27 |
28 // Cleans up all internal state. Does not notify delegate | 28 // Cleans up all internal state. Does not notify delegate |
29 ~LibcurlHttpFetcher(); | 29 ~LibcurlHttpFetcher(); |
30 | 30 |
31 // Begins the transfer if it hasn't already begun. | 31 // Begins the transfer if it hasn't already begun. |
32 virtual void BeginTransfer(const std::string& url); | 32 virtual void BeginTransfer(const std::string& url); |
33 | 33 |
34 // If the transfer is in progress, aborts the transfer early. | 34 // If the transfer is in progress, aborts the transfer early. |
35 // The transfer cannot be resumed. | 35 // The transfer cannot be resumed. |
36 virtual void TerminateTransfer(); | 36 virtual void TerminateTransfer(); |
(...skipping 29 matching lines...) Expand all Loading... |
66 static gboolean StaticFDCallback(GIOChannel *source, | 66 static gboolean StaticFDCallback(GIOChannel *source, |
67 GIOCondition condition, | 67 GIOCondition condition, |
68 gpointer data) { | 68 gpointer data) { |
69 return reinterpret_cast<LibcurlHttpFetcher*>(data)->FDCallback(source, | 69 return reinterpret_cast<LibcurlHttpFetcher*>(data)->FDCallback(source, |
70 condition); | 70 condition); |
71 } | 71 } |
72 gboolean TimeoutCallback(); | 72 gboolean TimeoutCallback(); |
73 static gboolean StaticTimeoutCallback(gpointer data) { | 73 static gboolean StaticTimeoutCallback(gpointer data) { |
74 return reinterpret_cast<LibcurlHttpFetcher*>(data)->TimeoutCallback(); | 74 return reinterpret_cast<LibcurlHttpFetcher*>(data)->TimeoutCallback(); |
75 } | 75 } |
| 76 |
| 77 gboolean RetryTimeoutCallback(); |
| 78 static gboolean StaticRetryTimeoutCallback(void* arg) { |
| 79 return static_cast<LibcurlHttpFetcher*>(arg)->RetryTimeoutCallback(); |
| 80 } |
76 | 81 |
77 // Calls into curl_multi_perform to let libcurl do its work. Returns after | 82 // Calls into curl_multi_perform to let libcurl do its work. Returns after |
78 // curl_multi_perform is finished, which may actually be after more than | 83 // curl_multi_perform is finished, which may actually be after more than |
79 // one call to curl_multi_perform. This method will set up the glib run | 84 // one call to curl_multi_perform. This method will set up the glib run |
80 // loop with sources for future work that libcurl will do. | 85 // loop with sources for future work that libcurl will do. |
81 // This method will not block. | 86 // This method will not block. |
82 // Returns true if we should resume immediately after this call. | 87 // Returns true if we should resume immediately after this call. |
83 bool CurlPerformOnce(); | 88 bool CurlPerformOnce(); |
84 | 89 |
85 // Sets up glib main loop sources as needed by libcurl. This is generally | 90 // Sets up glib main loop sources as needed by libcurl. This is generally |
(...skipping 30 matching lines...) Expand all Loading... |
116 | 121 |
117 // The transfer size. -1 if not known. | 122 // The transfer size. -1 if not known. |
118 off_t transfer_size_; | 123 off_t transfer_size_; |
119 | 124 |
120 // How many bytes have been downloaded and sent to the delegate. | 125 // How many bytes have been downloaded and sent to the delegate. |
121 off_t bytes_downloaded_; | 126 off_t bytes_downloaded_; |
122 | 127 |
123 // If we resumed an earlier transfer, data offset that we used for the | 128 // If we resumed an earlier transfer, data offset that we used for the |
124 // new connection. 0 otherwise. | 129 // new connection. 0 otherwise. |
125 off_t resume_offset_; | 130 off_t resume_offset_; |
| 131 |
| 132 // Number of resumes performed. |
| 133 int retry_count_; |
126 | 134 |
127 long idle_ms_; | 135 long idle_ms_; |
128 DISALLOW_COPY_AND_ASSIGN(LibcurlHttpFetcher); | 136 DISALLOW_COPY_AND_ASSIGN(LibcurlHttpFetcher); |
129 }; | 137 }; |
130 | 138 |
131 } // namespace chromeos_update_engine | 139 } // namespace chromeos_update_engine |
132 | 140 |
133 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ | 141 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ |
OLD | NEW |