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> |
Jeffrey Kardatzke | cf5f1f1 | 2017-10-02 16:08:44 -0700 | [diff] [blame] | 23 | #include <vector> |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 24 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 25 | #include <base/memory/weak_ptr.h> |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 26 | |
Sen Jiang | d8be4b5 | 2018-09-18 16:06:57 -0700 | [diff] [blame] | 27 | #include "update_engine/common/proxy_resolver.h" |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 28 | |
| 29 | namespace chromeos_update_engine { |
| 30 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 31 | class ChromeBrowserProxyResolver : public ProxyResolver { |
| 32 | public: |
Jeffrey Kardatzke | cf5f1f1 | 2017-10-02 16:08:44 -0700 | [diff] [blame] | 33 | ChromeBrowserProxyResolver(); |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 34 | ~ChromeBrowserProxyResolver() override; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 35 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 36 | // ProxyResolver: |
| 37 | ProxyRequestId GetProxiesForUrl(const std::string& url, |
| 38 | const ProxiesResolvedFn& callback) override; |
| 39 | bool CancelProxyRequest(ProxyRequestId request) override; |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 40 | |
Jeffrey Kardatzke | cf5f1f1 | 2017-10-02 16:08:44 -0700 | [diff] [blame] | 41 | private: |
| 42 | // Callback for calls made by GetProxiesForUrl(). |
| 43 | void OnGetChromeProxyServers(ProxyRequestId request_id, |
| 44 | bool success, |
| 45 | const std::vector<std::string>& proxies); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 46 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 47 | // Finds the callback identified by |request_id| in |pending_callbacks_|, |
| 48 | // passes |proxies| to it, and deletes it. Does nothing if the request has |
| 49 | // been cancelled. |
| 50 | void RunCallback(ProxyRequestId request_id, |
| 51 | const std::deque<std::string>& proxies); |
| 52 | |
Daniel Erat | 941cf23 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 53 | // Next ID to return from GetProxiesForUrl(). |
| 54 | ProxyRequestId next_request_id_; |
| 55 | |
| 56 | // Callbacks that were passed to GetProxiesForUrl() but haven't yet been run. |
| 57 | std::map<ProxyRequestId, ProxiesResolvedFn> pending_callbacks_; |
| 58 | |
| 59 | base::WeakPtrFactory<ChromeBrowserProxyResolver> weak_ptr_factory_; |
| 60 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 61 | DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver); |
| 62 | }; |
| 63 | |
| 64 | } // namespace chromeos_update_engine |
| 65 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 66 | #endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ |