chrome_browser_proxy_resolver.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
  17. #define UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_
  18. #include <deque>
  19. #include <map>
  20. #include <string>
  21. #include <vector>
  22. #include <base/memory/weak_ptr.h>
  23. #include "update_engine/common/proxy_resolver.h"
  24. namespace chromeos_update_engine {
  25. class ChromeBrowserProxyResolver : public ProxyResolver {
  26. public:
  27. ChromeBrowserProxyResolver();
  28. ~ChromeBrowserProxyResolver() override;
  29. // ProxyResolver:
  30. ProxyRequestId GetProxiesForUrl(const std::string& url,
  31. const ProxiesResolvedFn& callback) override;
  32. bool CancelProxyRequest(ProxyRequestId request) override;
  33. private:
  34. // Callback for calls made by GetProxiesForUrl().
  35. void OnGetChromeProxyServers(ProxyRequestId request_id,
  36. bool success,
  37. const std::vector<std::string>& proxies);
  38. // Finds the callback identified by |request_id| in |pending_callbacks_|,
  39. // passes |proxies| to it, and deletes it. Does nothing if the request has
  40. // been cancelled.
  41. void RunCallback(ProxyRequestId request_id,
  42. const std::deque<std::string>& proxies);
  43. // Next ID to return from GetProxiesForUrl().
  44. ProxyRequestId next_request_id_;
  45. // Callbacks that were passed to GetProxiesForUrl() but haven't yet been run.
  46. std::map<ProxyRequestId, ProxiesResolvedFn> pending_callbacks_;
  47. base::WeakPtrFactory<ChromeBrowserProxyResolver> weak_ptr_factory_;
  48. DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver);
  49. };
  50. } // namespace chromeos_update_engine
  51. #endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_