| 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> | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 21 | #include <string> | 
|  | 22 |  | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 23 | #include <gtest/gtest_prod.h>  // for FRIEND_TEST | 
|  | 24 |  | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 25 | #include <brillo/message_loops/message_loop.h> | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 26 |  | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 27 | #include "update_engine/libcros_proxy.h" | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 28 | #include "update_engine/proxy_resolver.h" | 
|  | 29 |  | 
|  | 30 | namespace chromeos_update_engine { | 
|  | 31 |  | 
|  | 32 | extern const char kLibCrosServiceName[]; | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 33 | extern const char kLibCrosProxyResolveName[]; | 
|  | 34 | extern const char kLibCrosProxyResolveSignalInterface[]; | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 35 |  | 
|  | 36 | class ChromeBrowserProxyResolver : public ProxyResolver { | 
|  | 37 | public: | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 38 | explicit ChromeBrowserProxyResolver(LibCrosProxy* libcros_proxy); | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 39 | ~ChromeBrowserProxyResolver() override; | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 40 |  | 
|  | 41 | // Initialize the ProxyResolver using the provided DBus proxies. | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 42 | bool Init(); | 
|  | 43 |  | 
| Alex Deymo | 3582194 | 2017-02-05 04:36:02 +0000 | [diff] [blame] | 44 | ProxyRequestId GetProxiesForUrl(const std::string& url, | 
|  | 45 | const ProxiesResolvedFn& callback) override; | 
|  | 46 | bool CancelProxyRequest(ProxyRequestId request) override; | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 47 |  | 
|  | 48 | private: | 
|  | 49 | FRIEND_TEST(ChromeBrowserProxyResolverTest, ParseTest); | 
|  | 50 | FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest); | 
| Alex Deymo | 3582194 | 2017-02-05 04:36:02 +0000 | [diff] [blame] | 51 | struct ProxyRequestData { | 
|  | 52 | brillo::MessageLoop::TaskId timeout_id; | 
|  | 53 | ProxiesResolvedFn callback; | 
|  | 54 | }; | 
|  | 55 | typedef std::multimap<std::string, std::unique_ptr<ProxyRequestData>> | 
| Ben Chan | f9cb98c | 2014-09-21 18:31:30 -0700 | [diff] [blame] | 56 | CallbacksMap; | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 57 |  | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 58 | // Called when the signal in UpdateEngineLibcrosProxyResolvedInterface is | 
|  | 59 | // connected. | 
|  | 60 | void OnSignalConnected(const std::string& interface_name, | 
|  | 61 | const std::string& signal_name, | 
|  | 62 | bool successful); | 
|  | 63 |  | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 64 | // Handle a reply from Chrome: | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 65 | void OnProxyResolvedSignal(const std::string& source_url, | 
|  | 66 | const std::string& proxy_info, | 
|  | 67 | const std::string& error_message); | 
|  | 68 |  | 
| Alex Deymo | 3582194 | 2017-02-05 04:36:02 +0000 | [diff] [blame] | 69 | // Handle no reply. The |request| pointer points to the ProxyRequestData in | 
|  | 70 | // the |callbacks_| map that triggered this timeout. | 
|  | 71 | void HandleTimeout(std::string source_url, ProxyRequestData* request); | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 72 |  | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 73 | // Parses a string-encoded list of proxies and returns a deque | 
|  | 74 | // of individual proxies. The last one will always be kNoProxy. | 
|  | 75 | static std::deque<std::string> ParseProxyString(const std::string& input); | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 76 |  | 
| Alex Deymo | 3582194 | 2017-02-05 04:36:02 +0000 | [diff] [blame] | 77 | // Process a proxy response by calling all the callbacks associated with the | 
|  | 78 | // passed |source_url|. All the timeouts associated with these callbacks will | 
|  | 79 | // be removed. | 
|  | 80 | void ProcessUrlResponse(const std::string& source_url, | 
|  | 81 | const std::deque<std::string>& proxies); | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 82 |  | 
| Gilad Arnold | 1877c39 | 2012-02-10 11:34:33 -0800 | [diff] [blame] | 83 | // Shutdown the dbus proxy object. | 
|  | 84 | void Shutdown(); | 
|  | 85 |  | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 86 | // DBus proxies to request a HTTP proxy resolution. The request is done in the | 
|  | 87 | // service_interface_proxy() interface and the response is received as a | 
|  | 88 | // signal in the ue_proxy_resolved_interface(). | 
|  | 89 | LibCrosProxy* libcros_proxy_; | 
|  | 90 |  | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 91 | int timeout_; | 
| Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 92 | CallbacksMap callbacks_; | 
|  | 93 | DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver); | 
|  | 94 | }; | 
|  | 95 |  | 
|  | 96 | }  // namespace chromeos_update_engine | 
|  | 97 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 98 | #endif  // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ |