Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: libcurl_http_fetcher.cc

Issue 3021003: AU: minor fixes requested in http://codereview.chromium.org/3010009 (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libcurl_http_fetcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "update_engine/libcurl_http_fetcher.h" 5 #include "update_engine/libcurl_http_fetcher.h"
6 #include <algorithm> 6 #include <algorithm>
7 #include "chromeos/obsolete_logging.h" 7 #include "chromeos/obsolete_logging.h"
8 8
9 using std::max; 9 using std::max;
10 using std::make_pair; 10 using std::make_pair;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 resume_offset_ = 0; 72 resume_offset_ = 0;
73 retry_count_ = 0; 73 retry_count_ = 0;
74 ResumeTransfer(url); 74 ResumeTransfer(url);
75 CurlPerformOnce(); 75 CurlPerformOnce();
76 } 76 }
77 77
78 void LibcurlHttpFetcher::TerminateTransfer() { 78 void LibcurlHttpFetcher::TerminateTransfer() {
79 CleanUp(); 79 CleanUp();
80 } 80 }
81 81
82 bool LibcurlHttpFetcher::CurlPerformOnce() { 82 void LibcurlHttpFetcher::CurlPerformOnce() {
83 CHECK(transfer_in_progress_); 83 CHECK(transfer_in_progress_);
84 int running_handles = 0; 84 int running_handles = 0;
85 CURLMcode retcode = CURLM_CALL_MULTI_PERFORM; 85 CURLMcode retcode = CURLM_CALL_MULTI_PERFORM;
86 86
87 // libcurl may request that we immediately call curl_multi_perform after it 87 // libcurl may request that we immediately call curl_multi_perform after it
88 // returns, so we do. libcurl promises that curl_multi_perform will not block. 88 // returns, so we do. libcurl promises that curl_multi_perform will not block.
89 while (CURLM_CALL_MULTI_PERFORM == retcode) { 89 while (CURLM_CALL_MULTI_PERFORM == retcode) {
90 retcode = curl_multi_perform(curl_multi_handle_, &running_handles); 90 retcode = curl_multi_perform(curl_multi_handle_, &running_handles);
91 } 91 }
92 if (0 == running_handles) { 92 if (0 == running_handles) {
(...skipping 16 matching lines...) Expand all
109 << bytes_downloaded_ << " bytes, but transfer_size_ is " 109 << bytes_downloaded_ << " bytes, but transfer_size_ is "
110 << transfer_size_ << ". retry_count: " << retry_count_; 110 << transfer_size_ << ". retry_count: " << retry_count_;
111 if (retry_count_ > kMaxRetriesCount) { 111 if (retry_count_ > kMaxRetriesCount) {
112 if (delegate_) 112 if (delegate_)
113 delegate_->TransferComplete(this, false); // success 113 delegate_->TransferComplete(this, false); // success
114 } else { 114 } else {
115 g_timeout_add(5 * 1000, 115 g_timeout_add(5 * 1000,
116 &LibcurlHttpFetcher::StaticRetryTimeoutCallback, 116 &LibcurlHttpFetcher::StaticRetryTimeoutCallback,
117 this); 117 this);
118 } 118 }
119 return false; 119 return;
120 } else { 120 } else {
121 if (delegate_) { 121 if (delegate_) {
122 // success is when http_response_code is 200 122 // success is when http_response_code is 200
123 delegate_->TransferComplete(this, http_response_code == 200); 123 delegate_->TransferComplete(this, http_response_code == 200);
124 } 124 }
125 } 125 }
126 } else { 126 } else {
127 // set up callback 127 // set up callback
128 SetupMainloopSources(); 128 SetupMainloopSources();
129 } 129 }
130 return false;
131 } 130 }
132 131
133 size_t LibcurlHttpFetcher::LibcurlWrite(void *ptr, size_t size, size_t nmemb) { 132 size_t LibcurlHttpFetcher::LibcurlWrite(void *ptr, size_t size, size_t nmemb) {
134 { 133 {
135 double transfer_size_double; 134 double transfer_size_double;
136 CHECK_EQ(curl_easy_getinfo(curl_handle_, 135 CHECK_EQ(curl_easy_getinfo(curl_handle_,
137 CURLINFO_CONTENT_LENGTH_DOWNLOAD, 136 CURLINFO_CONTENT_LENGTH_DOWNLOAD,
138 &transfer_size_double), CURLE_OK); 137 &transfer_size_double), CURLE_OK);
139 off_t new_transfer_size = static_cast<off_t>(transfer_size_double); 138 off_t new_transfer_size = static_cast<off_t>(transfer_size_double);
140 if (new_transfer_size > 0) { 139 if (new_transfer_size > 0) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 return true; 250 return true;
252 } 251 }
253 252
254 gboolean LibcurlHttpFetcher::RetryTimeoutCallback() { 253 gboolean LibcurlHttpFetcher::RetryTimeoutCallback() {
255 ResumeTransfer(url_); 254 ResumeTransfer(url_);
256 CurlPerformOnce(); 255 CurlPerformOnce();
257 return FALSE; // Don't have glib auto call this callback again 256 return FALSE; // Don't have glib auto call this callback again
258 } 257 }
259 258
260 gboolean LibcurlHttpFetcher::TimeoutCallback() { 259 gboolean LibcurlHttpFetcher::TimeoutCallback() {
260 // We always return true, even if we don't want glib to cll us back.
petkov 2010/07/17 04:32:43 typo: cll
261 // We will remove the event source separately if we don't want to
262 // be called back.
261 if (!transfer_in_progress_) 263 if (!transfer_in_progress_)
262 return TRUE; 264 return TRUE;
263 // Since we will return false from this function, which tells glib to
264 // destroy the timeout callback, we must NULL it out here. This way, when
265 // setting up callback sources again, we won't try to delete this (doomed)
266 // timeout callback then.
267 // TODO(adlr): optimize by checking if we can keep this timeout callback.
268 //timeout_source_ = NULL;
269 CurlPerformOnce(); 265 CurlPerformOnce();
270 return TRUE; 266 return TRUE;
271 } 267 }
272 268
273 void LibcurlHttpFetcher::CleanUp() { 269 void LibcurlHttpFetcher::CleanUp() {
274 if (timeout_source_) { 270 if (timeout_source_) {
275 g_source_destroy(timeout_source_); 271 g_source_destroy(timeout_source_);
276 timeout_source_ = NULL; 272 timeout_source_ = NULL;
277 } 273 }
278 274
(...skipping 13 matching lines...) Expand all
292 curl_handle_ = NULL; 288 curl_handle_ = NULL;
293 } 289 }
294 if (curl_multi_handle_) { 290 if (curl_multi_handle_) {
295 CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK); 291 CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK);
296 curl_multi_handle_ = NULL; 292 curl_multi_handle_ = NULL;
297 } 293 }
298 transfer_in_progress_ = false; 294 transfer_in_progress_ = false;
299 } 295 }
300 296
301 } // namespace chromeos_update_engine 297 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « libcurl_http_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698