Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2011 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 | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 16 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ |
| 18 | #define UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 19 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 20 | #include <deque> |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 21 | #include <map> |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 22 | #include <string> |
| 23 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 24 | #include <base/memory/weak_ptr.h> |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 25 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 26 | #include "update_engine/proxy_resolver.h" |
| 27 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 28 | namespace brillo { |
| 29 | class Error; |
| 30 | } // namespace brillo |
| 31 | |
| 32 | namespace org { |
| 33 | namespace chromium { |
| 34 | class NetworkProxyServiceInterfaceProxyInterface; |
| 35 | } // namespace chromium |
| 36 | } // namespace org |
| 37 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 38 | namespace chromeos_update_engine { |
| 39 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 40 | class ChromeBrowserProxyResolver : public ProxyResolver { |
| 41 | public: |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 42 | explicit ChromeBrowserProxyResolver( |
| 43 | org::chromium::NetworkProxyServiceInterfaceProxyInterface* dbus_proxy); |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 44 | ~ChromeBrowserProxyResolver() override; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 45 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 46 | // Parses a string-encoded list of proxies and returns a deque |
| 47 | // of individual proxies. The last one will always be kNoProxy. |
| 48 | static std::deque<std::string> ParseProxyString(const std::string& input); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 49 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 50 | // ProxyResolver: |
| 51 | ProxyRequestId GetProxiesForUrl(const std::string& url, |
| 52 | const ProxiesResolvedFn& callback) override; |
| 53 | bool CancelProxyRequest(ProxyRequestId request) override; |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 54 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 55 | private: |
| 56 | // Callback for successful D-Bus calls made by GetProxiesForUrl(). |
| 57 | void OnResolveProxyResponse(ProxyRequestId request_id, |
| 58 | const std::string& proxy_info, |
| 59 | const std::string& error_message); |
Gilad Arnold | 1877c39 | 2012-02-10 11:34:33 -0800 | [diff] [blame] | 60 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 61 | // Callback for failed D-Bus calls made by GetProxiesForUrl(). |
| 62 | void OnResolveProxyError(ProxyRequestId request_id, brillo::Error* error); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 63 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 64 | // Finds the callback identified by |request_id| in |pending_callbacks_|, |
| 65 | // passes |proxies| to it, and deletes it. Does nothing if the request has |
| 66 | // been cancelled. |
| 67 | void RunCallback(ProxyRequestId request_id, |
| 68 | const std::deque<std::string>& proxies); |
| 69 | |
| 70 | // D-Bus proxy for resolving network proxies. |
| 71 | org::chromium::NetworkProxyServiceInterfaceProxyInterface* dbus_proxy_; |
| 72 | |
| 73 | // Next ID to return from GetProxiesForUrl(). |
| 74 | ProxyRequestId next_request_id_; |
| 75 | |
| 76 | // Callbacks that were passed to GetProxiesForUrl() but haven't yet been run. |
| 77 | std::map<ProxyRequestId, ProxiesResolvedFn> pending_callbacks_; |
| 78 | |
| 79 | base::WeakPtrFactory<ChromeBrowserProxyResolver> weak_ptr_factory_; |
| 80 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver); |
| 82 | }; |
| 83 | |
| 84 | } // namespace chromeos_update_engine |
| 85 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 86 | #endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ |