blob: 43754beb6b981e78f36db40039075a6ddfb32967 [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
Andrew de los Reyes45168102010-11-22 11:13:50 -08007using std::deque;
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -08008using std::string;
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -08009
10namespace chromeos_update_engine {
11
12const char kNoProxy[] = "direct://";
13
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080014DirectProxyResolver::~DirectProxyResolver() {
15 if (idle_callback_id_) {
16 g_source_remove(idle_callback_id_);
17 idle_callback_id_ = 0;
18 }
19}
20
21bool 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 Reyes9cd120d2010-11-18 17:50:03 -080030 return true;
31}
32
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080033void DirectProxyResolver::ReturnCallback(ProxiesResolvedFn callback,
34 void* data) {
35 idle_callback_id_ = 0;
Gilad Arnold9bedeb52011-11-17 16:19:57 -080036
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 Reyesf3ed8e72011-02-16 10:35:46 -080040 (*callback)(proxies, data);
41}
42
43
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080044} // namespace chromeos_update_engine