| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2010 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 16 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_PROXY_RESOLVER_H_ | 
|  | 18 | #define UPDATE_ENGINE_PROXY_RESOLVER_H_ | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 19 |  | 
| Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 20 | #include <deque> | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 21 | #include <string> | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 22 |  | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 23 | #include <base/logging.h> | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 24 | #include <brillo/message_loops/message_loop.h> | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 25 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 26 | #include "update_engine/common/utils.h" | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 27 |  | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 28 | namespace chromeos_update_engine { | 
|  | 29 |  | 
|  | 30 | extern const char kNoProxy[]; | 
|  | 31 |  | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 32 | // Callback for a call to GetProxiesForUrl(). | 
|  | 33 | // Resultant proxies are in |out_proxy|. Each will be in one of the | 
|  | 34 | // following forms: | 
|  | 35 | // http://<host>[:<port>] - HTTP proxy | 
|  | 36 | // socks{4,5}://<host>[:<port>] - SOCKS4/5 proxy | 
|  | 37 | // kNoProxy - no proxy | 
| Alex Deymo | 3582194 | 2017-02-05 04:36:02 +0000 | [diff] [blame] | 38 | typedef base::Callback<void(const std::deque<std::string>& proxies)> | 
|  | 39 | ProxiesResolvedFn; | 
|  | 40 |  | 
|  | 41 | // An id that identifies a proxy request. Used to cancel an ongoing request | 
|  | 42 | // before the callback is called. | 
|  | 43 | typedef brillo::MessageLoop::TaskId ProxyRequestId; | 
|  | 44 |  | 
|  | 45 | // A constant identifying an invalid ProxyRequestId. | 
|  | 46 | extern const ProxyRequestId kProxyRequestIdNull; | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 47 |  | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 48 | class ProxyResolver { | 
|  | 49 | public: | 
|  | 50 | ProxyResolver() {} | 
|  | 51 | virtual ~ProxyResolver() {} | 
|  | 52 |  | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 53 | // Finds proxies for the given URL and returns them via the callback. | 
| Alex Deymo | 3582194 | 2017-02-05 04:36:02 +0000 | [diff] [blame] | 54 | // Returns the id of the pending request on success or kProxyRequestIdNull | 
|  | 55 | // otherwise. | 
|  | 56 | virtual ProxyRequestId GetProxiesForUrl( | 
|  | 57 | const std::string& url, const ProxiesResolvedFn& callback) = 0; | 
|  | 58 |  | 
|  | 59 | // Cancel the proxy resolution request initiated by GetProxiesForUrl(). The | 
|  | 60 | // |request| value must be the one provided by GetProxiesForUrl(). | 
|  | 61 | virtual bool CancelProxyRequest(ProxyRequestId request) = 0; | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 62 |  | 
|  | 63 | private: | 
|  | 64 | DISALLOW_COPY_AND_ASSIGN(ProxyResolver); | 
|  | 65 | }; | 
|  | 66 |  | 
|  | 67 | // Always says to not use a proxy | 
|  | 68 | class DirectProxyResolver : public ProxyResolver { | 
|  | 69 | public: | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 70 | DirectProxyResolver() = default; | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 71 | ~DirectProxyResolver() override; | 
| Alex Deymo | 3582194 | 2017-02-05 04:36:02 +0000 | [diff] [blame] | 72 | ProxyRequestId GetProxiesForUrl(const std::string& url, | 
|  | 73 | const ProxiesResolvedFn& callback) override; | 
|  | 74 | bool CancelProxyRequest(ProxyRequestId request) override; | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 75 |  | 
| Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 76 | // Set the number of direct (non-) proxies to be returned by resolver. | 
|  | 77 | // The default value is 1; higher numbers are currently used in testing. | 
|  | 78 | inline void set_num_proxies(size_t num_proxies) { | 
|  | 79 | num_proxies_ = num_proxies; | 
|  | 80 | } | 
|  | 81 |  | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 82 | private: | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 83 | // The ID of the main loop callback. | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 84 | brillo::MessageLoop::TaskId idle_callback_id_{ | 
|  | 85 | brillo::MessageLoop::kTaskIdNull}; | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 86 |  | 
| Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 87 | // Number of direct proxies to return on resolved list; currently used for | 
|  | 88 | // testing. | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 89 | size_t num_proxies_{1}; | 
| Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 90 |  | 
| Andrew de los Reyes | f3ed8e7 | 2011-02-16 10:35:46 -0800 | [diff] [blame] | 91 | // The MainLoop callback, from here we return to the client. | 
| Alex Deymo | 3582194 | 2017-02-05 04:36:02 +0000 | [diff] [blame] | 92 | void ReturnCallback(const ProxiesResolvedFn& callback); | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 93 | DISALLOW_COPY_AND_ASSIGN(DirectProxyResolver); | 
|  | 94 | }; | 
|  | 95 |  | 
|  | 96 | }  // namespace chromeos_update_engine | 
|  | 97 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 98 | #endif  // UPDATE_ENGINE_PROXY_RESOLVER_H_ |