| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2010 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 16 |  | 
|  | 17 | #include "update_engine/proxy_resolver.h" | 
|  | 18 |  | 
| Alex Vakulenko | 4906c1c | 2014-08-21 13:17:44 -0700 | [diff] [blame] | 19 | #include <base/bind.h> | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 20 | #include <base/location.h> | 
| Alex Vakulenko | 4906c1c | 2014-08-21 13:17:44 -0700 | [diff] [blame] | 21 |  | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 22 | using brillo::MessageLoop; | 
| Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 23 | using std::deque; | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 24 | using std::string; | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 25 |  | 
|  | 26 | namespace chromeos_update_engine { | 
|  | 27 |  | 
|  | 28 | const char kNoProxy[] = "direct://"; | 
|  | 29 |  | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 30 | DirectProxyResolver::~DirectProxyResolver() { | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 31 | if (idle_callback_id_ != MessageLoop::kTaskIdNull) { | 
|  | 32 | // The DirectProxyResolver is instantiated as part of the UpdateAttempter | 
|  | 33 | // which is also instantiated by default by the FakeSystemState, even when | 
|  | 34 | // it is not used. We check the manage_shares_id_ before calling the | 
|  | 35 | // MessageLoop::current() since the unit test using a FakeSystemState may | 
|  | 36 | // have not define a MessageLoop for the current thread. | 
|  | 37 | MessageLoop::current()->CancelTask(idle_callback_id_); | 
|  | 38 | idle_callback_id_ = MessageLoop::kTaskIdNull; | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 39 | } | 
|  | 40 | } | 
|  | 41 |  | 
| Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 42 | bool DirectProxyResolver::GetProxiesForUrl(const string& url, | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 43 | ProxiesResolvedFn callback, | 
|  | 44 | void* data) { | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 45 | idle_callback_id_ = MessageLoop::current()->PostTask( | 
|  | 46 | FROM_HERE, | 
|  | 47 | base::Bind( | 
|  | 48 | &DirectProxyResolver::ReturnCallback, | 
|  | 49 | base::Unretained(this), | 
|  | 50 | callback, | 
|  | 51 | data)); | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 52 | return true; | 
|  | 53 | } | 
|  | 54 |  | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 55 | void DirectProxyResolver::ReturnCallback(ProxiesResolvedFn callback, | 
|  | 56 | void* data) { | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 57 | idle_callback_id_ = MessageLoop::kTaskIdNull; | 
| Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 58 |  | 
|  | 59 | // Initialize proxy pool with as many proxies as indicated (all identical). | 
| Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 60 | deque<string> proxies(num_proxies_, kNoProxy); | 
| Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 61 |  | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 62 | (*callback)(proxies, data); | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 |  | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 66 | }  // namespace chromeos_update_engine |