| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 1 | // Copyright (c) 2010 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 |  | 
|  | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__ | 
|  | 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__ | 
|  | 7 |  | 
| Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 8 | #include <deque> | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 9 | #include <string> | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 10 |  | 
|  | 11 | #include <curl/curl.h> | 
|  | 12 | #include <gtest/gtest_prod.h>  // for FRIEND_TEST | 
|  | 13 |  | 
|  | 14 | #include "update_engine/dbus_interface.h" | 
|  | 15 | #include "update_engine/proxy_resolver.h" | 
|  | 16 |  | 
|  | 17 | namespace chromeos_update_engine { | 
|  | 18 |  | 
|  | 19 | extern const char kSessionManagerService[]; | 
|  | 20 | extern const char kSessionManagerPath[]; | 
|  | 21 | extern const char kSessionManagerInterface[]; | 
|  | 22 | extern const char kSessionManagerRetrievePropertyMethod[]; | 
|  | 23 | extern const char kSessionManagerProxySettingsKey[]; | 
|  | 24 |  | 
|  | 25 | // Class to resolve proxy for a url based on Chrome's proxy settings. | 
|  | 26 |  | 
|  | 27 | // Currently only supports manual settings, not PAC files or autodetected | 
|  | 28 | // settings. | 
|  | 29 |  | 
|  | 30 | class ChromeProxyResolver : public ProxyResolver { | 
|  | 31 | public: | 
|  | 32 | explicit ChromeProxyResolver(DbusGlibInterface* dbus) : dbus_(dbus) {} | 
|  | 33 | virtual ~ChromeProxyResolver() {} | 
|  | 34 |  | 
|  | 35 | virtual bool GetProxiesForUrl(const std::string& url, | 
| Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 36 | std::deque<std::string>* out_proxies); | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 37 |  | 
|  | 38 | // Get the curl proxy type for a given proxy url. Returns true on success. | 
|  | 39 | // Note: if proxy is kNoProxy, this will return false. | 
| Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 40 | static bool GetProxyType(const std::string& proxy, curl_proxytype* out_type); | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 41 |  | 
|  | 42 | private: | 
|  | 43 | FRIEND_TEST(ChromeProxyResolverTest, GetProxiesForUrlWithSettingsTest); | 
|  | 44 |  | 
|  | 45 | // Fetches a dbus proxy to session manager. Returns NULL on failure. | 
|  | 46 | DBusGProxy* DbusProxy(); | 
|  | 47 |  | 
|  | 48 | // Fetches the json-encoded proxy settings string from the session manager. | 
|  | 49 | bool GetJsonProxySettings(DBusGProxy* proxy, std::string* out_json); | 
|  | 50 |  | 
|  | 51 | // Given a |url| and the json encoded settings |json_settings|, | 
|  | 52 | // returns the proper proxy servers in |out_proxies|. Returns true on | 
|  | 53 | // success. | 
|  | 54 | bool GetProxiesForUrlWithSettings(const std::string& url, | 
|  | 55 | const std::string& json_settings, | 
| Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 56 | std::deque<std::string>* out_proxies); | 
| Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 57 |  | 
|  | 58 | DbusGlibInterface* dbus_; | 
|  | 59 |  | 
|  | 60 | DISALLOW_COPY_AND_ASSIGN(ChromeProxyResolver); | 
|  | 61 | }; | 
|  | 62 |  | 
|  | 63 | }  // namespace chromeos_update_engine | 
|  | 64 |  | 
|  | 65 | #endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__ |