blob: f9b1e29fe256bda1d794ad05fc359dd7077a36c4 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2011 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Andrew de los Reyes000d8952011-03-02 15:21:14 -080016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
18#define UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
Andrew de los Reyes000d8952011-03-02 15:21:14 -080019
Alex Vakulenkod2779df2014-06-16 13:19:00 -070020#include <deque>
Andrew de los Reyes000d8952011-03-02 15:21:14 -080021#include <map>
22#include <string>
Alex Vakulenkod2779df2014-06-16 13:19:00 -070023#include <utility>
Andrew de los Reyes000d8952011-03-02 15:21:14 -080024
Andrew de los Reyes000d8952011-03-02 15:21:14 -080025#include <gtest/gtest_prod.h> // for FRIEND_TEST
26
Alex Deymo60ca1a72015-06-18 18:19:15 -070027#include <chromeos/message_loops/message_loop.h>
28
Alex Deymo30534502015-07-20 15:06:33 -070029#include "update_engine/dbus_proxies.h"
30#include "update_engine/libcros_proxy.h"
Andrew de los Reyes000d8952011-03-02 15:21:14 -080031#include "update_engine/proxy_resolver.h"
32
33namespace chromeos_update_engine {
34
35extern const char kLibCrosServiceName[];
Andrew de los Reyes000d8952011-03-02 15:21:14 -080036extern const char kLibCrosProxyResolveName[];
37extern const char kLibCrosProxyResolveSignalInterface[];
Andrew de los Reyes000d8952011-03-02 15:21:14 -080038
39class ChromeBrowserProxyResolver : public ProxyResolver {
40 public:
Alex Deymo30534502015-07-20 15:06:33 -070041 explicit ChromeBrowserProxyResolver(LibCrosProxy* libcros_proxy);
Alex Deymo610277e2014-11-11 21:18:11 -080042 ~ChromeBrowserProxyResolver() override;
Alex Deymo30534502015-07-20 15:06:33 -070043
44 // Initialize the ProxyResolver using the provided DBus proxies.
Andrew de los Reyes000d8952011-03-02 15:21:14 -080045 bool Init();
46
Alex Deymo610277e2014-11-11 21:18:11 -080047 bool GetProxiesForUrl(const std::string& url,
48 ProxiesResolvedFn callback,
49 void* data) override;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080050
51 private:
52 FRIEND_TEST(ChromeBrowserProxyResolverTest, ParseTest);
53 FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest);
Ben Chanf9cb98c2014-09-21 18:31:30 -070054 typedef std::multimap<std::string, std::pair<ProxiesResolvedFn, void*>>
55 CallbacksMap;
Alex Deymo60ca1a72015-06-18 18:19:15 -070056 typedef std::multimap<std::string, chromeos::MessageLoop::TaskId> TimeoutsMap;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080057
Alex Deymo30534502015-07-20 15:06:33 -070058 // Called when the signal in UpdateEngineLibcrosProxyResolvedInterface is
59 // connected.
60 void OnSignalConnected(const std::string& interface_name,
61 const std::string& signal_name,
62 bool successful);
63
Andrew de los Reyes000d8952011-03-02 15:21:14 -080064 // Handle a reply from Chrome:
Alex Deymo30534502015-07-20 15:06:33 -070065 void OnProxyResolvedSignal(const std::string& source_url,
66 const std::string& proxy_info,
67 const std::string& error_message);
68
Andrew de los Reyes000d8952011-03-02 15:21:14 -080069 // Handle no reply:
70 void HandleTimeout(std::string source_url);
Alex Vakulenkod2779df2014-06-16 13:19:00 -070071
Andrew de los Reyes000d8952011-03-02 15:21:14 -080072 // Parses a string-encoded list of proxies and returns a deque
73 // of individual proxies. The last one will always be kNoProxy.
74 static std::deque<std::string> ParseProxyString(const std::string& input);
Alex Vakulenkod2779df2014-06-16 13:19:00 -070075
Andrew de los Reyes000d8952011-03-02 15:21:14 -080076 // Deletes internal state for the first instance of url in the state.
Alex Deymo60ca1a72015-06-18 18:19:15 -070077 // If delete_timer is set, calls CancelTask on the timer id.
Andrew de los Reyes000d8952011-03-02 15:21:14 -080078 // Returns the callback in an out parameter. Returns true on success.
79 bool DeleteUrlState(const std::string& url,
80 bool delete_timer,
81 std::pair<ProxiesResolvedFn, void*>* callback);
82
Gilad Arnold1877c392012-02-10 11:34:33 -080083 // Shutdown the dbus proxy object.
84 void Shutdown();
85
Alex Deymo30534502015-07-20 15:06:33 -070086 // DBus proxies to request a HTTP proxy resolution. The request is done in the
87 // service_interface_proxy() interface and the response is received as a
88 // signal in the ue_proxy_resolved_interface().
89 LibCrosProxy* libcros_proxy_;
90
Andrew de los Reyes000d8952011-03-02 15:21:14 -080091 int timeout_;
92 TimeoutsMap timers_;
93 CallbacksMap callbacks_;
94 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
95};
96
97} // namespace chromeos_update_engine
98
Gilad Arnoldcf175a02014-07-10 16:48:47 -070099#endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_