Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 1 | // Copyright (c) 2010 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/proxy_resolver.h" |
| 6 | |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 7 | using std::deque; |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 8 | using std::string; |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 9 | |
| 10 | namespace chromeos_update_engine { |
| 11 | |
| 12 | const char kNoProxy[] = "direct://"; |
| 13 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 14 | DirectProxyResolver::~DirectProxyResolver() { |
| 15 | if (idle_callback_id_) { |
| 16 | g_source_remove(idle_callback_id_); |
| 17 | idle_callback_id_ = 0; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | bool DirectProxyResolver::GetProxiesForUrl(const std::string& url, |
| 22 | ProxiesResolvedFn callback, |
| 23 | void* data) { |
| 24 | google::protobuf::Closure* closure = |
| 25 | google::protobuf::NewCallback(this, |
| 26 | &DirectProxyResolver::ReturnCallback, |
| 27 | callback, |
| 28 | data); |
| 29 | idle_callback_id_ = g_idle_add(utils::GlibRunClosure, closure); |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 30 | return true; |
| 31 | } |
| 32 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 33 | void DirectProxyResolver::ReturnCallback(ProxiesResolvedFn callback, |
| 34 | void* data) { |
| 35 | idle_callback_id_ = 0; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 36 | |
| 37 | // Initialize proxy pool with as many proxies as indicated (all identical). |
| 38 | std::deque<std::string> proxies(num_proxies_, kNoProxy); |
| 39 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 40 | (*callback)(proxies, data); |
| 41 | } |
| 42 | |
| 43 | |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 44 | } // namespace chromeos_update_engine |