blob: fb960738060ff7b7a37be5f856c4dacaafe1f05c [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#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PROXY_RESOLVER_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_PROXY_RESOLVER_H__
7
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -08008
Andrew de los Reyes45168102010-11-22 11:13:50 -08009#include <deque>
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080010#include <string>
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080011
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080012#include <base/logging.h>
13#include <google/protobuf/stubs/common.h>
14
15#include "update_engine/utils.h"
16
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080017namespace chromeos_update_engine {
18
19extern const char kNoProxy[];
20
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080021// Callback for a call to GetProxiesForUrl().
22// Resultant proxies are in |out_proxy|. Each will be in one of the
23// following forms:
24// http://<host>[:<port>] - HTTP proxy
25// socks{4,5}://<host>[:<port>] - SOCKS4/5 proxy
26// kNoProxy - no proxy
27typedef void (*ProxiesResolvedFn)(const std::deque<std::string>& proxies,
28 void* data);
29
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080030class ProxyResolver {
31 public:
32 ProxyResolver() {}
33 virtual ~ProxyResolver() {}
34
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080035 // Finds proxies for the given URL and returns them via the callback.
36 // |data| will be passed to the callback.
37 // Returns true on success.
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080038 virtual bool GetProxiesForUrl(const std::string& url,
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080039 ProxiesResolvedFn callback,
40 void* data) = 0;
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080041
42 private:
43 DISALLOW_COPY_AND_ASSIGN(ProxyResolver);
44};
45
46// Always says to not use a proxy
47class DirectProxyResolver : public ProxyResolver {
48 public:
Gilad Arnold9bedeb52011-11-17 16:19:57 -080049 DirectProxyResolver() : idle_callback_id_(0), num_proxies_(1) {}
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080050 virtual ~DirectProxyResolver();
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080051 virtual bool GetProxiesForUrl(const std::string& url,
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080052 ProxiesResolvedFn callback,
53 void* data);
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080054
Gilad Arnold9bedeb52011-11-17 16:19:57 -080055 // Set the number of direct (non-) proxies to be returned by resolver.
56 // The default value is 1; higher numbers are currently used in testing.
57 inline void set_num_proxies(size_t num_proxies) {
58 num_proxies_ = num_proxies;
59 }
60
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080061 private:
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080062 // The ID of the idle main loop callback
63 guint idle_callback_id_;
64
Gilad Arnold9bedeb52011-11-17 16:19:57 -080065 // Number of direct proxies to return on resolved list; currently used for
66 // testing.
67 size_t num_proxies_;
68
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080069 // The MainLoop callback, from here we return to the client.
70 void ReturnCallback(ProxiesResolvedFn callback, void* data);
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080071 DISALLOW_COPY_AND_ASSIGN(DirectProxyResolver);
72};
73
74} // namespace chromeos_update_engine
75
76#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PROXY_RESOLVER_H__