blob: aef87eeb771b67dcd623f25eeee7604e1e82f227 [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
6#define 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
Andrew de los Reyes000d8952011-03-02 15:21:14 -080013#include <gtest/gtest_prod.h> // for FRIEND_TEST
14
Alex Deymo60ca1a72015-06-18 18:19:15 -070015#include <chromeos/message_loops/message_loop.h>
16
Alex Deymo30534502015-07-20 15:06:33 -070017#include "update_engine/dbus_proxies.h"
18#include "update_engine/libcros_proxy.h"
Andrew de los Reyes000d8952011-03-02 15:21:14 -080019#include "update_engine/proxy_resolver.h"
20
21namespace chromeos_update_engine {
22
23extern const char kLibCrosServiceName[];
Andrew de los Reyes000d8952011-03-02 15:21:14 -080024extern const char kLibCrosProxyResolveName[];
25extern const char kLibCrosProxyResolveSignalInterface[];
Andrew de los Reyes000d8952011-03-02 15:21:14 -080026
27class ChromeBrowserProxyResolver : public ProxyResolver {
28 public:
Alex Deymo30534502015-07-20 15:06:33 -070029 explicit ChromeBrowserProxyResolver(LibCrosProxy* libcros_proxy);
Alex Deymo610277e2014-11-11 21:18:11 -080030 ~ChromeBrowserProxyResolver() override;
Alex Deymo30534502015-07-20 15:06:33 -070031
32 // Initialize the ProxyResolver using the provided DBus proxies.
Andrew de los Reyes000d8952011-03-02 15:21:14 -080033 bool Init();
34
Alex Deymo610277e2014-11-11 21:18:11 -080035 bool GetProxiesForUrl(const std::string& url,
36 ProxiesResolvedFn callback,
37 void* data) override;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080038
39 private:
40 FRIEND_TEST(ChromeBrowserProxyResolverTest, ParseTest);
41 FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest);
Ben Chanf9cb98c2014-09-21 18:31:30 -070042 typedef std::multimap<std::string, std::pair<ProxiesResolvedFn, void*>>
43 CallbacksMap;
Alex Deymo60ca1a72015-06-18 18:19:15 -070044 typedef std::multimap<std::string, chromeos::MessageLoop::TaskId> TimeoutsMap;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080045
Alex Deymo30534502015-07-20 15:06:33 -070046 // 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 Reyes000d8952011-03-02 15:21:14 -080052 // Handle a reply from Chrome:
Alex Deymo30534502015-07-20 15:06:33 -070053 void OnProxyResolvedSignal(const std::string& source_url,
54 const std::string& proxy_info,
55 const std::string& error_message);
56
Andrew de los Reyes000d8952011-03-02 15:21:14 -080057 // Handle no reply:
58 void HandleTimeout(std::string source_url);
Alex Vakulenkod2779df2014-06-16 13:19:00 -070059
Andrew de los Reyes000d8952011-03-02 15:21:14 -080060 // 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 Vakulenkod2779df2014-06-16 13:19:00 -070063
Andrew de los Reyes000d8952011-03-02 15:21:14 -080064 // Deletes internal state for the first instance of url in the state.
Alex Deymo60ca1a72015-06-18 18:19:15 -070065 // If delete_timer is set, calls CancelTask on the timer id.
Andrew de los Reyes000d8952011-03-02 15:21:14 -080066 // 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 Arnold1877c392012-02-10 11:34:33 -080071 // Shutdown the dbus proxy object.
72 void Shutdown();
73
Alex Deymo30534502015-07-20 15:06:33 -070074 // 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 Reyes000d8952011-03-02 15:21:14 -080079 int timeout_;
80 TimeoutsMap timers_;
81 CallbacksMap callbacks_;
82 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
83};
84
85} // namespace chromeos_update_engine
86
Gilad Arnoldcf175a02014-07-10 16:48:47 -070087#endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_