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 | |
Alex Vakulenko | 4906c1c | 2014-08-21 13:17:44 -0700 | [diff] [blame] | 7 | #include <base/bind.h> |
| 8 | |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 9 | using std::deque; |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 10 | using std::string; |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 11 | |
| 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | const char kNoProxy[] = "direct://"; |
| 15 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 16 | DirectProxyResolver::~DirectProxyResolver() { |
| 17 | if (idle_callback_id_) { |
| 18 | g_source_remove(idle_callback_id_); |
| 19 | idle_callback_id_ = 0; |
| 20 | } |
| 21 | } |
| 22 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 23 | bool DirectProxyResolver::GetProxiesForUrl(const string& url, |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 24 | ProxiesResolvedFn callback, |
| 25 | void* data) { |
Alex Vakulenko | 4906c1c | 2014-08-21 13:17:44 -0700 | [diff] [blame] | 26 | base::Closure* closure = new base::Closure(base::Bind( |
Alex Deymo | c4acdf4 | 2014-05-28 21:07:10 -0700 | [diff] [blame] | 27 | &DirectProxyResolver::ReturnCallback, |
Alex Vakulenko | 4906c1c | 2014-08-21 13:17:44 -0700 | [diff] [blame] | 28 | base::Unretained(this), |
Alex Deymo | c4acdf4 | 2014-05-28 21:07:10 -0700 | [diff] [blame] | 29 | callback, |
Alex Vakulenko | 4906c1c | 2014-08-21 13:17:44 -0700 | [diff] [blame] | 30 | data)); |
Alex Deymo | c4acdf4 | 2014-05-28 21:07:10 -0700 | [diff] [blame] | 31 | idle_callback_id_ = g_idle_add_full( |
| 32 | G_PRIORITY_DEFAULT, |
| 33 | utils::GlibRunClosure, |
| 34 | closure, |
| 35 | utils::GlibDestroyClosure); |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 36 | return true; |
| 37 | } |
| 38 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 39 | void DirectProxyResolver::ReturnCallback(ProxiesResolvedFn callback, |
| 40 | void* data) { |
| 41 | idle_callback_id_ = 0; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 42 | |
| 43 | // Initialize proxy pool with as many proxies as indicated (all identical). |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 44 | deque<string> proxies(num_proxies_, kNoProxy); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 45 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 46 | (*callback)(proxies, data); |
| 47 | } |
| 48 | |
| 49 | |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 50 | } // namespace chromeos_update_engine |