blob: 03dbdad5a15a014cdd7e4a1ac2c227153a0dc188 [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>
Daniel Erate5f6f252017-04-20 12:09:58 -060021#include <map>
Andrew de los Reyes000d8952011-03-02 15:21:14 -080022#include <string>
23
Daniel Erate5f6f252017-04-20 12:09:58 -060024#include <base/memory/weak_ptr.h>
Andrew de los Reyes000d8952011-03-02 15:21:14 -080025
Andrew de los Reyes000d8952011-03-02 15:21:14 -080026#include "update_engine/proxy_resolver.h"
27
Daniel Erate5f6f252017-04-20 12:09:58 -060028namespace brillo {
29class Error;
30} // namespace brillo
31
32namespace org {
33namespace chromium {
34class NetworkProxyServiceInterfaceProxyInterface;
35} // namespace chromium
36} // namespace org
37
Andrew de los Reyes000d8952011-03-02 15:21:14 -080038namespace chromeos_update_engine {
39
Andrew de los Reyes000d8952011-03-02 15:21:14 -080040class ChromeBrowserProxyResolver : public ProxyResolver {
41 public:
Daniel Erate5f6f252017-04-20 12:09:58 -060042 explicit ChromeBrowserProxyResolver(
43 org::chromium::NetworkProxyServiceInterfaceProxyInterface* dbus_proxy);
Alex Deymo610277e2014-11-11 21:18:11 -080044 ~ChromeBrowserProxyResolver() override;
Alex Deymo30534502015-07-20 15:06:33 -070045
Andrew de los Reyes000d8952011-03-02 15:21:14 -080046 // Parses a string-encoded list of proxies and returns a deque
47 // of individual proxies. The last one will always be kNoProxy.
48 static std::deque<std::string> ParseProxyString(const std::string& input);
Alex Vakulenkod2779df2014-06-16 13:19:00 -070049
Daniel Erate5f6f252017-04-20 12:09:58 -060050 // ProxyResolver:
51 ProxyRequestId GetProxiesForUrl(const std::string& url,
52 const ProxiesResolvedFn& callback) override;
53 bool CancelProxyRequest(ProxyRequestId request) override;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080054
Daniel Erate5f6f252017-04-20 12:09:58 -060055private:
56 // Callback for successful D-Bus calls made by GetProxiesForUrl().
57 void OnResolveProxyResponse(ProxyRequestId request_id,
58 const std::string& proxy_info,
59 const std::string& error_message);
Gilad Arnold1877c392012-02-10 11:34:33 -080060
Daniel Erate5f6f252017-04-20 12:09:58 -060061 // Callback for failed D-Bus calls made by GetProxiesForUrl().
62 void OnResolveProxyError(ProxyRequestId request_id, brillo::Error* error);
Alex Deymo30534502015-07-20 15:06:33 -070063
Daniel Erate5f6f252017-04-20 12:09:58 -060064 // Finds the callback identified by |request_id| in |pending_callbacks_|,
65 // passes |proxies| to it, and deletes it. Does nothing if the request has
66 // been cancelled.
67 void RunCallback(ProxyRequestId request_id,
68 const std::deque<std::string>& proxies);
69
70 // D-Bus proxy for resolving network proxies.
71 org::chromium::NetworkProxyServiceInterfaceProxyInterface* dbus_proxy_;
72
73 // Next ID to return from GetProxiesForUrl().
74 ProxyRequestId next_request_id_;
75
76 // Callbacks that were passed to GetProxiesForUrl() but haven't yet been run.
77 std::map<ProxyRequestId, ProxiesResolvedFn> pending_callbacks_;
78
79 base::WeakPtrFactory<ChromeBrowserProxyResolver> weak_ptr_factory_;
80
Andrew de los Reyes000d8952011-03-02 15:21:14 -080081 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
82};
83
84} // namespace chromeos_update_engine
85
Gilad Arnoldcf175a02014-07-10 16:48:47 -070086#endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_