OLD | NEW |
(Empty) | |
| 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 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H__ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include <dbus/dbus-glib.h> |
| 12 #include <dbus/dbus-glib-lowlevel.h> |
| 13 #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 14 |
| 15 #include "update_engine/dbus_interface.h" |
| 16 #include "update_engine/proxy_resolver.h" |
| 17 |
| 18 namespace chromeos_update_engine { |
| 19 |
| 20 extern const char kLibCrosServiceName[]; |
| 21 extern const char kLibCrosServicePath[]; |
| 22 extern const char kLibCrosServiceInterface[]; |
| 23 extern const char kLibCrosServiceResolveNetworkProxyMethodName[]; |
| 24 extern const char kLibCrosProxyResolveName[]; |
| 25 extern const char kLibCrosProxyResolveSignalInterface[]; |
| 26 extern const char kLibCrosProxyResolveSignalFilter[]; |
| 27 |
| 28 class ChromeBrowserProxyResolver : public ProxyResolver { |
| 29 public: |
| 30 explicit ChromeBrowserProxyResolver(DbusGlibInterface* dbus); |
| 31 virtual ~ChromeBrowserProxyResolver(); |
| 32 bool Init(); |
| 33 |
| 34 virtual bool GetProxiesForUrl(const std::string& url, |
| 35 ProxiesResolvedFn callback, |
| 36 void* data); |
| 37 void set_timeout(int seconds) { timeout_ = seconds; } |
| 38 |
| 39 // Public for test |
| 40 static DBusHandlerResult StaticFilterMessage( |
| 41 DBusConnection* connection, |
| 42 DBusMessage* message, |
| 43 void* data) { |
| 44 return reinterpret_cast<ChromeBrowserProxyResolver*>(data)->FilterMessage( |
| 45 connection, message); |
| 46 } |
| 47 |
| 48 private: |
| 49 FRIEND_TEST(ChromeBrowserProxyResolverTest, ParseTest); |
| 50 FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest); |
| 51 typedef std::multimap<std::string, std::pair<ProxiesResolvedFn, void*> > |
| 52 CallbacksMap; |
| 53 typedef std::multimap<std::string, GSource*> TimeoutsMap; |
| 54 |
| 55 // Handle a reply from Chrome: |
| 56 void HandleReply(const std::string& source_url, |
| 57 const std::string& proxy_list); |
| 58 DBusHandlerResult FilterMessage( |
| 59 DBusConnection* connection, |
| 60 DBusMessage* message); |
| 61 // Handle no reply: |
| 62 void HandleTimeout(std::string source_url); |
| 63 |
| 64 // Parses a string-encoded list of proxies and returns a deque |
| 65 // of individual proxies. The last one will always be kNoProxy. |
| 66 static std::deque<std::string> ParseProxyString(const std::string& input); |
| 67 |
| 68 // Deletes internal state for the first instance of url in the state. |
| 69 // If delete_timer is set, calls g_source_destroy on the timer source. |
| 70 // Returns the callback in an out parameter. Returns true on success. |
| 71 bool DeleteUrlState(const std::string& url, |
| 72 bool delete_timer, |
| 73 std::pair<ProxiesResolvedFn, void*>* callback); |
| 74 |
| 75 DbusGlibInterface* dbus_; |
| 76 DBusGProxy* proxy_; |
| 77 DBusGProxy* peer_proxy_; |
| 78 int timeout_; |
| 79 TimeoutsMap timers_; |
| 80 CallbacksMap callbacks_; |
| 81 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver); |
| 82 }; |
| 83 |
| 84 } // namespace chromeos_update_engine |
| 85 |
| 86 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H__ |
OLD | NEW |