blob: 61f59826c5fd624186750f2ada055ce566296736 [file] [log] [blame]
Andrew de los Reyes000d8952011-03-02 15:21:14 -08001// 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
18namespace chromeos_update_engine {
19
20extern const char kLibCrosServiceName[];
21extern const char kLibCrosServicePath[];
22extern const char kLibCrosServiceInterface[];
23extern const char kLibCrosServiceResolveNetworkProxyMethodName[];
24extern const char kLibCrosProxyResolveName[];
25extern const char kLibCrosProxyResolveSignalInterface[];
26extern const char kLibCrosProxyResolveSignalFilter[];
27
28class 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
Gilad Arnold1877c392012-02-10 11:34:33 -080075 // Shutdown the dbus proxy object.
76 void Shutdown();
77
Andrew de los Reyes000d8952011-03-02 15:21:14 -080078 DbusGlibInterface* dbus_;
79 DBusGProxy* proxy_;
80 DBusGProxy* peer_proxy_;
81 int timeout_;
82 TimeoutsMap timers_;
83 CallbacksMap callbacks_;
84 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
85};
86
87} // namespace chromeos_update_engine
88
89#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H__