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> |
11 | 11 |
12 #include "update_engine/chrome_proxy_resolver.h" | 12 #include "update_engine/chrome_proxy_resolver.h" |
13 #include "update_engine/dbus_interface.h" | 13 #include "update_engine/dbus_interface.h" |
14 #include "update_engine/flimflam_proxy.h" | 14 #include "update_engine/flimflam_proxy.h" |
15 #include "update_engine/utils.h" | 15 #include "update_engine/utils.h" |
16 | 16 |
| 17 using google::protobuf::NewCallback; |
17 using std::max; | 18 using std::max; |
18 using std::make_pair; | 19 using std::make_pair; |
19 using std::string; | 20 using std::string; |
20 | 21 |
21 // This is a concrete implementation of HttpFetcher that uses libcurl to do the | 22 // This is a concrete implementation of HttpFetcher that uses libcurl to do the |
22 // http work. | 23 // http work. |
23 | 24 |
24 namespace chromeos_update_engine { | 25 namespace chromeos_update_engine { |
25 | 26 |
26 namespace { | 27 namespace { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 "HIGH:!ADH"), | 145 "HIGH:!ADH"), |
145 CURLE_OK); | 146 CURLE_OK); |
146 } | 147 } |
147 | 148 |
148 CHECK_EQ(curl_multi_add_handle(curl_multi_handle_, curl_handle_), CURLM_OK); | 149 CHECK_EQ(curl_multi_add_handle(curl_multi_handle_, curl_handle_), CURLM_OK); |
149 transfer_in_progress_ = true; | 150 transfer_in_progress_ = true; |
150 } | 151 } |
151 | 152 |
152 // Begins the transfer, which must not have already been started. | 153 // Begins the transfer, which must not have already been started. |
153 void LibcurlHttpFetcher::BeginTransfer(const std::string& url) { | 154 void LibcurlHttpFetcher::BeginTransfer(const std::string& url) { |
| 155 CHECK(!transfer_in_progress_); |
| 156 url_ = url; |
| 157 if (!ResolveProxiesForUrl( |
| 158 url_, |
| 159 NewCallback(this, &LibcurlHttpFetcher::ProxiesResolved))) { |
| 160 LOG(ERROR) << "Couldn't resolve proxies"; |
| 161 if (delegate_) |
| 162 delegate_->TransferComplete(this, false); |
| 163 } |
| 164 } |
| 165 |
| 166 void LibcurlHttpFetcher::ProxiesResolved() { |
154 transfer_size_ = -1; | 167 transfer_size_ = -1; |
155 resume_offset_ = 0; | 168 resume_offset_ = 0; |
156 retry_count_ = 0; | 169 retry_count_ = 0; |
157 no_network_retry_count_ = 0; | 170 no_network_retry_count_ = 0; |
158 http_response_code_ = 0; | 171 http_response_code_ = 0; |
159 terminate_requested_ = false; | 172 terminate_requested_ = false; |
160 ResolveProxiesForUrl(url); | 173 ResumeTransfer(url_); |
161 ResumeTransfer(url); | |
162 CurlPerformOnce(); | 174 CurlPerformOnce(); |
163 } | 175 } |
164 | 176 |
165 void LibcurlHttpFetcher::ForceTransferTermination() { | 177 void LibcurlHttpFetcher::ForceTransferTermination() { |
166 CleanUp(); | 178 CleanUp(); |
167 if (delegate_) { | 179 if (delegate_) { |
168 // Note that after the callback returns this object may be destroyed. | 180 // Note that after the callback returns this object may be destroyed. |
169 delegate_->TransferTerminated(this); | 181 delegate_->TransferTerminated(this); |
170 } | 182 } |
171 } | 183 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 void LibcurlHttpFetcher::GetHttpResponseCode() { | 453 void LibcurlHttpFetcher::GetHttpResponseCode() { |
442 long http_response_code = 0; | 454 long http_response_code = 0; |
443 if (curl_easy_getinfo(curl_handle_, | 455 if (curl_easy_getinfo(curl_handle_, |
444 CURLINFO_RESPONSE_CODE, | 456 CURLINFO_RESPONSE_CODE, |
445 &http_response_code) == CURLE_OK) { | 457 &http_response_code) == CURLE_OK) { |
446 http_response_code_ = static_cast<int>(http_response_code); | 458 http_response_code_ = static_cast<int>(http_response_code); |
447 } | 459 } |
448 } | 460 } |
449 | 461 |
450 } // namespace chromeos_update_engine | 462 } // namespace chromeos_update_engine |
OLD | NEW |