Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ |
| 6 | #define UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 7 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 8 | #include <deque> |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 9 | #include <map> |
| 10 | #include <string> |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 11 | #include <utility> |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 12 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 14 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 15 | #include <chromeos/message_loops/message_loop.h> |
| 16 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 17 | #include "update_engine/dbus_proxies.h" |
| 18 | #include "update_engine/libcros_proxy.h" |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 19 | #include "update_engine/proxy_resolver.h" |
| 20 | |
| 21 | namespace chromeos_update_engine { |
| 22 | |
| 23 | extern const char kLibCrosServiceName[]; |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 24 | extern const char kLibCrosProxyResolveName[]; |
| 25 | extern const char kLibCrosProxyResolveSignalInterface[]; |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 26 | |
| 27 | class ChromeBrowserProxyResolver : public ProxyResolver { |
| 28 | public: |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 29 | explicit ChromeBrowserProxyResolver(LibCrosProxy* libcros_proxy); |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 30 | ~ChromeBrowserProxyResolver() override; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 31 | |
| 32 | // Initialize the ProxyResolver using the provided DBus proxies. |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 33 | bool Init(); |
| 34 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 35 | bool GetProxiesForUrl(const std::string& url, |
| 36 | ProxiesResolvedFn callback, |
| 37 | void* data) override; |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 38 | |
| 39 | private: |
| 40 | FRIEND_TEST(ChromeBrowserProxyResolverTest, ParseTest); |
| 41 | FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest); |
Ben Chan | f9cb98c | 2014-09-21 18:31:30 -0700 | [diff] [blame] | 42 | typedef std::multimap<std::string, std::pair<ProxiesResolvedFn, void*>> |
| 43 | CallbacksMap; |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 44 | typedef std::multimap<std::string, chromeos::MessageLoop::TaskId> TimeoutsMap; |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 45 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 46 | // Called when the signal in UpdateEngineLibcrosProxyResolvedInterface is |
| 47 | // connected. |
| 48 | void OnSignalConnected(const std::string& interface_name, |
| 49 | const std::string& signal_name, |
| 50 | bool successful); |
| 51 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 52 | // Handle a reply from Chrome: |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 53 | void OnProxyResolvedSignal(const std::string& source_url, |
| 54 | const std::string& proxy_info, |
| 55 | const std::string& error_message); |
| 56 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 57 | // Handle no reply: |
| 58 | void HandleTimeout(std::string source_url); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 59 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 60 | // Parses a string-encoded list of proxies and returns a deque |
| 61 | // of individual proxies. The last one will always be kNoProxy. |
| 62 | static std::deque<std::string> ParseProxyString(const std::string& input); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 63 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 64 | // Deletes internal state for the first instance of url in the state. |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 65 | // If delete_timer is set, calls CancelTask on the timer id. |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 66 | // Returns the callback in an out parameter. Returns true on success. |
| 67 | bool DeleteUrlState(const std::string& url, |
| 68 | bool delete_timer, |
| 69 | std::pair<ProxiesResolvedFn, void*>* callback); |
| 70 | |
Gilad Arnold | 1877c39 | 2012-02-10 11:34:33 -0800 | [diff] [blame] | 71 | // Shutdown the dbus proxy object. |
| 72 | void Shutdown(); |
| 73 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 74 | // DBus proxies to request a HTTP proxy resolution. The request is done in the |
| 75 | // service_interface_proxy() interface and the response is received as a |
| 76 | // signal in the ue_proxy_resolved_interface(). |
| 77 | LibCrosProxy* libcros_proxy_; |
| 78 | |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 79 | int timeout_; |
| 80 | TimeoutsMap timers_; |
| 81 | CallbacksMap callbacks_; |
| 82 | DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver); |
| 83 | }; |
| 84 | |
| 85 | } // namespace chromeos_update_engine |
| 86 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 87 | #endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ |