Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 1 | // 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 Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 8 | |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 9 | #include <deque> |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 10 | #include <string> |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 11 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 12 | #include <base/logging.h> |
| 13 | #include <google/protobuf/stubs/common.h> |
| 14 | |
| 15 | #include "update_engine/utils.h" |
| 16 | |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 17 | namespace chromeos_update_engine { |
| 18 | |
| 19 | extern const char kNoProxy[]; |
| 20 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 21 | // 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 |
| 27 | typedef void (*ProxiesResolvedFn)(const std::deque<std::string>& proxies, |
| 28 | void* data); |
| 29 | |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 30 | class ProxyResolver { |
| 31 | public: |
| 32 | ProxyResolver() {} |
| 33 | virtual ~ProxyResolver() {} |
| 34 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 35 | // 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 Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 38 | virtual bool GetProxiesForUrl(const std::string& url, |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 39 | ProxiesResolvedFn callback, |
| 40 | void* data) = 0; |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 41 | |
| 42 | private: |
| 43 | DISALLOW_COPY_AND_ASSIGN(ProxyResolver); |
| 44 | }; |
| 45 | |
| 46 | // Always says to not use a proxy |
| 47 | class DirectProxyResolver : public ProxyResolver { |
| 48 | public: |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 49 | DirectProxyResolver() : idle_callback_id_(0), num_proxies_(1) {} |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 50 | virtual ~DirectProxyResolver(); |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 51 | virtual bool GetProxiesForUrl(const std::string& url, |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 52 | ProxiesResolvedFn callback, |
| 53 | void* data); |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 54 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 55 | // 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 Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 61 | private: |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 62 | // The ID of the idle main loop callback |
| 63 | guint idle_callback_id_; |
| 64 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 65 | // Number of direct proxies to return on resolved list; currently used for |
| 66 | // testing. |
| 67 | size_t num_proxies_; |
| 68 | |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 69 | // The MainLoop callback, from here we return to the client. |
| 70 | void ReturnCallback(ProxiesResolvedFn callback, void* data); |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(DirectProxyResolver); |
| 72 | }; |
| 73 | |
| 74 | } // namespace chromeos_update_engine |
| 75 | |
| 76 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PROXY_RESOLVER_H__ |