blob: fcf85b68a5c45a3af7c99adaceed004e37aa1808 [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 Erat941cf232017-04-20 12:09:58 -060021#include <map>
Andrew de los Reyes000d8952011-03-02 15:21:14 -080022#include <string>
Jeffrey Kardatzkecf5f1f12017-10-02 16:08:44 -070023#include <vector>
Andrew de los Reyes000d8952011-03-02 15:21:14 -080024
Daniel Erat941cf232017-04-20 12:09:58 -060025#include <base/memory/weak_ptr.h>
Andrew de los Reyes000d8952011-03-02 15:21:14 -080026
Andrew de los Reyes000d8952011-03-02 15:21:14 -080027#include "update_engine/proxy_resolver.h"
28
29namespace chromeos_update_engine {
30
Andrew de los Reyes000d8952011-03-02 15:21:14 -080031class ChromeBrowserProxyResolver : public ProxyResolver {
32 public:
Jeffrey Kardatzkecf5f1f12017-10-02 16:08:44 -070033 ChromeBrowserProxyResolver();
Alex Deymo610277e2014-11-11 21:18:11 -080034 ~ChromeBrowserProxyResolver() override;
Alex Deymo30534502015-07-20 15:06:33 -070035
Daniel Erat941cf232017-04-20 12:09:58 -060036 // ProxyResolver:
37 ProxyRequestId GetProxiesForUrl(const std::string& url,
38 const ProxiesResolvedFn& callback) override;
39 bool CancelProxyRequest(ProxyRequestId request) override;
Andrew de los Reyes000d8952011-03-02 15:21:14 -080040
Jeffrey Kardatzkecf5f1f12017-10-02 16:08:44 -070041 private:
42 // Callback for calls made by GetProxiesForUrl().
43 void OnGetChromeProxyServers(ProxyRequestId request_id,
44 bool success,
45 const std::vector<std::string>& proxies);
Alex Deymo30534502015-07-20 15:06:33 -070046
Daniel Erat941cf232017-04-20 12:09:58 -060047 // Finds the callback identified by |request_id| in |pending_callbacks_|,
48 // passes |proxies| to it, and deletes it. Does nothing if the request has
49 // been cancelled.
50 void RunCallback(ProxyRequestId request_id,
51 const std::deque<std::string>& proxies);
52
Daniel Erat941cf232017-04-20 12:09:58 -060053 // Next ID to return from GetProxiesForUrl().
54 ProxyRequestId next_request_id_;
55
56 // Callbacks that were passed to GetProxiesForUrl() but haven't yet been run.
57 std::map<ProxyRequestId, ProxiesResolvedFn> pending_callbacks_;
58
59 base::WeakPtrFactory<ChromeBrowserProxyResolver> weak_ptr_factory_;
60
Andrew de los Reyes000d8952011-03-02 15:21:14 -080061 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
62};
63
64} // namespace chromeos_update_engine
65
Gilad Arnoldcf175a02014-07-10 16:48:47 -070066#endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_