blob: 48a1049816569d3b5e03298f9e8e962e3fed1182 [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
Alex Deymo759c2752014-03-17 21:09:36 -07005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
Andrew de los Reyes000d8952011-03-02 15:21:14 -08007
Alex Vakulenkod2779df2014-06-16 13:19:00 -07008#include <deque>
Andrew de los Reyes000d8952011-03-02 15:21:14 -08009#include <map>
10#include <string>
Alex Vakulenkod2779df2014-06-16 13:19:00 -070011#include <utility>
Andrew de los Reyes000d8952011-03-02 15:21:14 -080012
13#include <dbus/dbus-glib.h>
14#include <dbus/dbus-glib-lowlevel.h>
15#include <gtest/gtest_prod.h> // for FRIEND_TEST
16
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080017#include "update_engine/dbus_wrapper_interface.h"
Andrew de los Reyes000d8952011-03-02 15:21:14 -080018#include "update_engine/proxy_resolver.h"
19
20namespace chromeos_update_engine {
21
22extern const char kLibCrosServiceName[];
23extern const char kLibCrosServicePath[];
24extern const char kLibCrosServiceInterface[];
25extern const char kLibCrosServiceResolveNetworkProxyMethodName[];
26extern const char kLibCrosProxyResolveName[];
27extern const char kLibCrosProxyResolveSignalInterface[];
28extern const char kLibCrosProxyResolveSignalFilter[];
29
30class ChromeBrowserProxyResolver : public ProxyResolver {
31 public:
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080032 explicit ChromeBrowserProxyResolver(DBusWrapperInterface* dbus);
Andrew de los Reyes000d8952011-03-02 15:21:14 -080033 virtual ~ChromeBrowserProxyResolver();
34 bool Init();
35
36 virtual bool GetProxiesForUrl(const std::string& url,
37 ProxiesResolvedFn callback,
38 void* data);
39 void set_timeout(int seconds) { timeout_ = seconds; }
40
41 // Public for test
42 static DBusHandlerResult StaticFilterMessage(
43 DBusConnection* connection,
44 DBusMessage* message,
45 void* data) {
46 return reinterpret_cast<ChromeBrowserProxyResolver*>(data)->FilterMessage(
47 connection, message);
48 }
49
50 private:
51 FRIEND_TEST(ChromeBrowserProxyResolverTest, ParseTest);
52 FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest);
53 typedef std::multimap<std::string, std::pair<ProxiesResolvedFn, void*> >
54 CallbacksMap;
55 typedef std::multimap<std::string, GSource*> TimeoutsMap;
56
57 // Handle a reply from Chrome:
58 void HandleReply(const std::string& source_url,
59 const std::string& proxy_list);
60 DBusHandlerResult FilterMessage(
61 DBusConnection* connection,
62 DBusMessage* message);
63 // Handle no reply:
64 void HandleTimeout(std::string source_url);
Alex Vakulenkod2779df2014-06-16 13:19:00 -070065
Andrew de los Reyes000d8952011-03-02 15:21:14 -080066 // Parses a string-encoded list of proxies and returns a deque
67 // of individual proxies. The last one will always be kNoProxy.
68 static std::deque<std::string> ParseProxyString(const std::string& input);
Alex Vakulenkod2779df2014-06-16 13:19:00 -070069
Andrew de los Reyes000d8952011-03-02 15:21:14 -080070 // Deletes internal state for the first instance of url in the state.
71 // If delete_timer is set, calls g_source_destroy on the timer source.
72 // Returns the callback in an out parameter. Returns true on success.
73 bool DeleteUrlState(const std::string& url,
74 bool delete_timer,
75 std::pair<ProxiesResolvedFn, void*>* callback);
76
Gilad Arnold1877c392012-02-10 11:34:33 -080077 // Shutdown the dbus proxy object.
78 void Shutdown();
79
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080080 DBusWrapperInterface* dbus_;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080081 DBusGProxy* proxy_;
82 DBusGProxy* peer_proxy_;
83 int timeout_;
84 TimeoutsMap timers_;
85 CallbacksMap callbacks_;
86 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
87};
88
89} // namespace chromeos_update_engine
90
Alex Deymo759c2752014-03-17 21:09:36 -070091#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_