Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/http_fetcher.h" |
| 6 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame^] | 7 | using google::protobuf::Closure; |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 8 | using std::deque; |
| 9 | using std::string; |
| 10 | |
| 11 | namespace chromeos_update_engine { |
| 12 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame^] | 13 | HttpFetcher::~HttpFetcher() { |
| 14 | if (no_resolver_idle_id_) { |
| 15 | g_source_remove(no_resolver_idle_id_); |
| 16 | no_resolver_idle_id_ = 0; |
| 17 | } |
| 18 | } |
| 19 | |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 20 | void HttpFetcher::SetPostData(const void* data, size_t size) { |
| 21 | post_data_set_ = true; |
| 22 | post_data_.clear(); |
| 23 | const char *char_data = reinterpret_cast<const char*>(data); |
| 24 | post_data_.insert(post_data_.end(), char_data, char_data + size); |
| 25 | } |
| 26 | |
| 27 | // Proxy methods to set the proxies, then to pop them off. |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame^] | 28 | bool HttpFetcher::ResolveProxiesForUrl(const string& url, Closure* callback) { |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 29 | if (!proxy_resolver_) { |
| 30 | LOG(INFO) << "Not resolving proxies (no proxy resolver)."; |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame^] | 31 | no_resolver_idle_id_ = g_idle_add(utils::GlibRunClosure, callback); |
| 32 | return true; |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 33 | } |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame^] | 34 | callback_ = callback; |
| 35 | return proxy_resolver_->GetProxiesForUrl(url, |
| 36 | &HttpFetcher::StaticProxiesResolved, |
| 37 | this); |
| 38 | } |
| 39 | |
| 40 | void HttpFetcher::ProxiesResolved(const std::deque<std::string>& proxies) { |
| 41 | no_resolver_idle_id_ = 0; |
| 42 | if (!proxies.empty()) |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 43 | SetProxies(proxies); |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame^] | 44 | callback_->Run(); |
| 45 | callback_ = NULL; |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | } // namespace chromeos_update_engine |