blob: c6ba03b65965a149297833f35417db7f339e074f [file] [log] [blame]
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -08001// 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 Vakulenko4906c1c2014-08-21 13:17:44 -07007#include <base/bind.h>
8
Andrew de los Reyes45168102010-11-22 11:13:50 -08009using std::deque;
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080010using std::string;
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080011
12namespace chromeos_update_engine {
13
14const char kNoProxy[] = "direct://";
15
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080016DirectProxyResolver::~DirectProxyResolver() {
17 if (idle_callback_id_) {
18 g_source_remove(idle_callback_id_);
19 idle_callback_id_ = 0;
20 }
21}
22
Alex Deymof329b932014-10-30 01:37:48 -070023bool DirectProxyResolver::GetProxiesForUrl(const string& url,
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080024 ProxiesResolvedFn callback,
25 void* data) {
Alex Vakulenko4906c1c2014-08-21 13:17:44 -070026 base::Closure* closure = new base::Closure(base::Bind(
Alex Deymoc4acdf42014-05-28 21:07:10 -070027 &DirectProxyResolver::ReturnCallback,
Alex Vakulenko4906c1c2014-08-21 13:17:44 -070028 base::Unretained(this),
Alex Deymoc4acdf42014-05-28 21:07:10 -070029 callback,
Alex Vakulenko4906c1c2014-08-21 13:17:44 -070030 data));
Alex Deymoc4acdf42014-05-28 21:07:10 -070031 idle_callback_id_ = g_idle_add_full(
32 G_PRIORITY_DEFAULT,
33 utils::GlibRunClosure,
34 closure,
35 utils::GlibDestroyClosure);
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080036 return true;
37}
38
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080039void DirectProxyResolver::ReturnCallback(ProxiesResolvedFn callback,
40 void* data) {
41 idle_callback_id_ = 0;
Gilad Arnold9bedeb52011-11-17 16:19:57 -080042
43 // Initialize proxy pool with as many proxies as indicated (all identical).
Alex Deymof329b932014-10-30 01:37:48 -070044 deque<string> proxies(num_proxies_, kNoProxy);
Gilad Arnold9bedeb52011-11-17 16:19:57 -080045
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080046 (*callback)(proxies, data);
47}
48
49
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080050} // namespace chromeos_update_engine