blob: 9d6b73a7a10975fcba5884a60172d0c10b573a3a [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_PROXY_RESOLVER_H_
6#define UPDATE_ENGINE_PROXY_RESOLVER_H_
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -08007
Andrew de los Reyes45168102010-11-22 11:13:50 -08008#include <deque>
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -08009#include <string>
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080010
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080011#include <base/logging.h>
Alex Deymo60ca1a72015-06-18 18:19:15 -070012#include <chromeos/message_loops/message_loop.h>
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080013
14#include "update_engine/utils.h"
15
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080016namespace chromeos_update_engine {
17
18extern const char kNoProxy[];
19
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080020// Callback for a call to GetProxiesForUrl().
21// Resultant proxies are in |out_proxy|. Each will be in one of the
22// following forms:
23// http://<host>[:<port>] - HTTP proxy
24// socks{4,5}://<host>[:<port>] - SOCKS4/5 proxy
25// kNoProxy - no proxy
26typedef void (*ProxiesResolvedFn)(const std::deque<std::string>& proxies,
27 void* data);
28
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080029class ProxyResolver {
30 public:
31 ProxyResolver() {}
32 virtual ~ProxyResolver() {}
33
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080034 // Finds proxies for the given URL and returns them via the callback.
35 // |data| will be passed to the callback.
36 // Returns true on success.
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080037 virtual bool GetProxiesForUrl(const std::string& url,
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080038 ProxiesResolvedFn callback,
39 void* data) = 0;
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080040
41 private:
42 DISALLOW_COPY_AND_ASSIGN(ProxyResolver);
43};
44
45// Always says to not use a proxy
46class DirectProxyResolver : public ProxyResolver {
47 public:
Alex Deymo60ca1a72015-06-18 18:19:15 -070048 DirectProxyResolver() = default;
Alex Deymo610277e2014-11-11 21:18:11 -080049 ~DirectProxyResolver() override;
50 bool GetProxiesForUrl(const std::string& url,
51 ProxiesResolvedFn callback,
52 void* data) override;
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080053
Gilad Arnold9bedeb52011-11-17 16:19:57 -080054 // Set the number of direct (non-) proxies to be returned by resolver.
55 // The default value is 1; higher numbers are currently used in testing.
56 inline void set_num_proxies(size_t num_proxies) {
57 num_proxies_ = num_proxies;
58 }
59
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080060 private:
Alex Deymo60ca1a72015-06-18 18:19:15 -070061 // The ID of the main loop callback.
62 chromeos::MessageLoop::TaskId idle_callback_id_{
63 chromeos::MessageLoop::kTaskIdNull};
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080064
Gilad Arnold9bedeb52011-11-17 16:19:57 -080065 // Number of direct proxies to return on resolved list; currently used for
66 // testing.
Alex Deymo60ca1a72015-06-18 18:19:15 -070067 size_t num_proxies_{1};
Gilad Arnold9bedeb52011-11-17 16:19:57 -080068
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
Gilad Arnoldcf175a02014-07-10 16:48:47 -070076#endif // UPDATE_ENGINE_PROXY_RESOLVER_H_