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: |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame^] | 49 | DirectProxyResolver() : idle_callback_id_(0) {} |
| 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 | |
| 55 | private: |
Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame^] | 56 | // The ID of the idle main loop callback |
| 57 | guint idle_callback_id_; |
| 58 | |
| 59 | // The MainLoop callback, from here we return to the client. |
| 60 | void ReturnCallback(ProxiesResolvedFn callback, void* data); |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 61 | DISALLOW_COPY_AND_ASSIGN(DirectProxyResolver); |
| 62 | }; |
| 63 | |
| 64 | } // namespace chromeos_update_engine |
| 65 | |
| 66 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PROXY_RESOLVER_H__ |