blob: eb92bac6c13d5503e54d1d85f4808e7350a6b8a7 [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 <string>
22
Andrew de los Reyes000d8952011-03-02 15:21:14 -080023#include <gtest/gtest_prod.h> // for FRIEND_TEST
24
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070025#include <brillo/message_loops/message_loop.h>
Alex Deymo60ca1a72015-06-18 18:19:15 -070026
Alex Deymo30534502015-07-20 15:06:33 -070027#include "update_engine/libcros_proxy.h"
Andrew de los Reyes000d8952011-03-02 15:21:14 -080028#include "update_engine/proxy_resolver.h"
29
30namespace chromeos_update_engine {
31
32extern const char kLibCrosServiceName[];
Andrew de los Reyes000d8952011-03-02 15:21:14 -080033extern const char kLibCrosProxyResolveName[];
34extern const char kLibCrosProxyResolveSignalInterface[];
Andrew de los Reyes000d8952011-03-02 15:21:14 -080035
36class ChromeBrowserProxyResolver : public ProxyResolver {
37 public:
Alex Deymo30534502015-07-20 15:06:33 -070038 explicit ChromeBrowserProxyResolver(LibCrosProxy* libcros_proxy);
Alex Deymo610277e2014-11-11 21:18:11 -080039 ~ChromeBrowserProxyResolver() override;
Alex Deymo30534502015-07-20 15:06:33 -070040
41 // Initialize the ProxyResolver using the provided DBus proxies.
Andrew de los Reyes000d8952011-03-02 15:21:14 -080042 bool Init();
43
Alex Deymoc00ec562017-02-05 04:36:02 +000044 ProxyRequestId GetProxiesForUrl(const std::string& url,
45 const ProxiesResolvedFn& callback) override;
46 bool CancelProxyRequest(ProxyRequestId request) override;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080047
48 private:
49 FRIEND_TEST(ChromeBrowserProxyResolverTest, ParseTest);
50 FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest);
Alex Deymoc00ec562017-02-05 04:36:02 +000051 struct ProxyRequestData {
52 brillo::MessageLoop::TaskId timeout_id;
53 ProxiesResolvedFn callback;
54 };
55 typedef std::multimap<std::string, std::unique_ptr<ProxyRequestData>>
Ben Chanf9cb98c2014-09-21 18:31:30 -070056 CallbacksMap;
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
Alex Deymoc00ec562017-02-05 04:36:02 +000069 // Handle no reply. The |request| pointer points to the ProxyRequestData in
70 // the |callbacks_| map that triggered this timeout.
71 void HandleTimeout(std::string source_url, ProxyRequestData* request);
Alex Vakulenkod2779df2014-06-16 13:19:00 -070072
Andrew de los Reyes000d8952011-03-02 15:21:14 -080073 // Parses a string-encoded list of proxies and returns a deque
74 // of individual proxies. The last one will always be kNoProxy.
75 static std::deque<std::string> ParseProxyString(const std::string& input);
Alex Vakulenkod2779df2014-06-16 13:19:00 -070076
Alex Deymoc00ec562017-02-05 04:36:02 +000077 // Process a proxy response by calling all the callbacks associated with the
78 // passed |source_url|. All the timeouts associated with these callbacks will
79 // be removed.
80 void ProcessUrlResponse(const std::string& source_url,
81 const std::deque<std::string>& proxies);
Andrew de los Reyes000d8952011-03-02 15:21:14 -080082
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_;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080092 CallbacksMap callbacks_;
93 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
94};
95
96} // namespace chromeos_update_engine
97
Gilad Arnoldcf175a02014-07-10 16:48:47 -070098#endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_