Home | History | Annotate | Download | only in update_engine
      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 
     24 #include <base/memory/weak_ptr.h>
     25 
     26 #include "update_engine/proxy_resolver.h"
     27 
     28 namespace brillo {
     29 class Error;
     30 }  // namespace brillo
     31 
     32 namespace org {
     33 namespace chromium {
     34 class NetworkProxyServiceInterfaceProxyInterface;
     35 }  // namespace chromium
     36 }  // namespace org
     37 
     38 namespace chromeos_update_engine {
     39 
     40 class ChromeBrowserProxyResolver : public ProxyResolver {
     41  public:
     42   explicit ChromeBrowserProxyResolver(
     43       org::chromium::NetworkProxyServiceInterfaceProxyInterface* dbus_proxy);
     44   ~ChromeBrowserProxyResolver() override;
     45 
     46   // 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);
     49 
     50   // ProxyResolver:
     51   ProxyRequestId GetProxiesForUrl(const std::string& url,
     52                                   const ProxiesResolvedFn& callback) override;
     53   bool CancelProxyRequest(ProxyRequestId request) override;
     54 
     55 private:
     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);
     60 
     61   // Callback for failed D-Bus calls made by GetProxiesForUrl().
     62   void OnResolveProxyError(ProxyRequestId request_id, brillo::Error* error);
     63 
     64   // 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 
     81   DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
     82 };
     83 
     84 }  // namespace chromeos_update_engine
     85 
     86 #endif  // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
     87