• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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 //
16 
17 #ifndef UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
18 #define UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
19 
20 #include <deque>
21 #include <map>
22 #include <string>
23 #include <vector>
24 
25 #include <base/memory/weak_ptr.h>
26 
27 #include "update_engine/common/proxy_resolver.h"
28 
29 namespace chromeos_update_engine {
30 
31 class ChromeBrowserProxyResolver : public ProxyResolver {
32  public:
33   ChromeBrowserProxyResolver();
34   ~ChromeBrowserProxyResolver() override;
35 
36   // ProxyResolver:
37   ProxyRequestId GetProxiesForUrl(const std::string& url,
38                                   const ProxiesResolvedFn& callback) override;
39   bool CancelProxyRequest(ProxyRequestId request) override;
40 
41  private:
42   // Callback for calls made by GetProxiesForUrl().
43   void OnGetChromeProxyServers(ProxyRequestId request_id,
44                                bool success,
45                                const std::vector<std::string>& proxies);
46 
47   // 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 
53   // 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 
61   DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
62 };
63 
64 }  // namespace chromeos_update_engine
65 
66 #endif  // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
67