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 #include "update_engine/libcurl_http_fetcher.h" | 5 #include "update_engine/libcurl_http_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include <base/logging.h> | 10 #include <base/logging.h> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 // http work. | 21 // http work. |
22 | 22 |
23 namespace chromeos_update_engine { | 23 namespace chromeos_update_engine { |
24 | 24 |
25 namespace { | 25 namespace { |
26 const int kMaxRetriesCount = 20; | 26 const int kMaxRetriesCount = 20; |
27 const char kCACertificatesPath[] = "/usr/share/update_engine/ca-certificates"; | 27 const char kCACertificatesPath[] = "/usr/share/update_engine/ca-certificates"; |
28 } // namespace {} | 28 } // namespace {} |
29 | 29 |
30 LibcurlHttpFetcher::~LibcurlHttpFetcher() { | 30 LibcurlHttpFetcher::~LibcurlHttpFetcher() { |
31 LOG_IF(ERROR, transfer_in_progress_) | |
32 << "Destroying the fetcher while a transfer is in progress."; | |
31 CleanUp(); | 33 CleanUp(); |
32 } | 34 } |
33 | 35 |
34 // On error, returns false. | 36 // On error, returns false. |
35 bool LibcurlHttpFetcher::ConnectionIsExpensive() const { | 37 bool LibcurlHttpFetcher::ConnectionIsExpensive() const { |
36 if (force_connection_type_) | 38 if (force_connection_type_) |
37 return forced_expensive_connection_; | 39 return forced_expensive_connection_; |
38 NetworkConnectionType type; | 40 NetworkConnectionType type; |
39 ConcreteDbusGlib dbus_iface; | 41 ConcreteDbusGlib dbus_iface; |
40 TEST_AND_RETURN_FALSE(FlimFlamProxy::GetConnectionType(&dbus_iface, &type)); | 42 TEST_AND_RETURN_FALSE(FlimFlamProxy::GetConnectionType(&dbus_iface, &type)); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // Begins the transfer, which must not have already been started. | 130 // Begins the transfer, which must not have already been started. |
129 void LibcurlHttpFetcher::BeginTransfer(const std::string& url) { | 131 void LibcurlHttpFetcher::BeginTransfer(const std::string& url) { |
130 transfer_size_ = -1; | 132 transfer_size_ = -1; |
131 resume_offset_ = 0; | 133 resume_offset_ = 0; |
132 retry_count_ = 0; | 134 retry_count_ = 0; |
133 http_response_code_ = 0; | 135 http_response_code_ = 0; |
134 ResumeTransfer(url); | 136 ResumeTransfer(url); |
135 CurlPerformOnce(); | 137 CurlPerformOnce(); |
136 } | 138 } |
137 | 139 |
140 void LibcurlHttpFetcher::ForceTransferTermination() { | |
141 CleanUp(); | |
142 if (delegate_) { | |
143 // Note that after the callback returns this object may be destroyed. | |
adlr
2010/11/17 21:33:50
this comment seems important, maybe it should also
petkov
2010/11/17 21:47:54
You mean in the docstring for the ForceTransferTer
| |
144 delegate_->TransferTerminated(this); | |
145 } | |
146 } | |
147 | |
138 void LibcurlHttpFetcher::TerminateTransfer() { | 148 void LibcurlHttpFetcher::TerminateTransfer() { |
139 if (in_write_callback_) | 149 if (in_write_callback_) { |
140 terminate_requested_ = true; | 150 terminate_requested_ = true; |
141 else | 151 } else { |
142 CleanUp(); | 152 ForceTransferTermination(); |
153 } | |
143 } | 154 } |
144 | 155 |
145 void LibcurlHttpFetcher::CurlPerformOnce() { | 156 void LibcurlHttpFetcher::CurlPerformOnce() { |
146 CHECK(transfer_in_progress_); | 157 CHECK(transfer_in_progress_); |
147 int running_handles = 0; | 158 int running_handles = 0; |
148 CURLMcode retcode = CURLM_CALL_MULTI_PERFORM; | 159 CURLMcode retcode = CURLM_CALL_MULTI_PERFORM; |
149 | 160 |
150 // libcurl may request that we immediately call curl_multi_perform after it | 161 // libcurl may request that we immediately call curl_multi_perform after it |
151 // returns, so we do. libcurl promises that curl_multi_perform will not block. | 162 // returns, so we do. libcurl promises that curl_multi_perform will not block. |
152 while (CURLM_CALL_MULTI_PERFORM == retcode) { | 163 while (CURLM_CALL_MULTI_PERFORM == retcode) { |
153 retcode = curl_multi_perform(curl_multi_handle_, &running_handles); | 164 retcode = curl_multi_perform(curl_multi_handle_, &running_handles); |
154 if (terminate_requested_) { | 165 if (terminate_requested_) { |
155 CleanUp(); | 166 ForceTransferTermination(); |
156 return; | 167 return; |
157 } | 168 } |
158 } | 169 } |
159 if (0 == running_handles) { | 170 if (0 == running_handles) { |
160 GetHttpResponseCode(); | 171 GetHttpResponseCode(); |
161 if (http_response_code_) { | 172 if (http_response_code_) { |
162 LOG(INFO) << "HTTP response code: " << http_response_code_; | 173 LOG(INFO) << "HTTP response code: " << http_response_code_; |
163 } else { | 174 } else { |
164 LOG(ERROR) << "Unable to get http response code."; | 175 LOG(ERROR) << "Unable to get http response code."; |
165 } | 176 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 void LibcurlHttpFetcher::GetHttpResponseCode() { | 379 void LibcurlHttpFetcher::GetHttpResponseCode() { |
369 long http_response_code = 0; | 380 long http_response_code = 0; |
370 if (curl_easy_getinfo(curl_handle_, | 381 if (curl_easy_getinfo(curl_handle_, |
371 CURLINFO_RESPONSE_CODE, | 382 CURLINFO_RESPONSE_CODE, |
372 &http_response_code) == CURLE_OK) { | 383 &http_response_code) == CURLE_OK) { |
373 http_response_code_ = static_cast<int>(http_response_code); | 384 http_response_code_ = static_cast<int>(http_response_code); |
374 } | 385 } |
375 } | 386 } |
376 | 387 |
377 } // namespace chromeos_update_engine | 388 } // namespace chromeos_update_engine |
OLD | NEW |