Support for unpacked ARM packed relocations.
[chromium-blink-merge.git] / components / data_reduction_proxy / browser / data_reduction_proxy_config_service.h
blob75addad6e273cd404423ee5aff478e443eb31803
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_CONFIG_SERVICE_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_CONFIG_SERVICE_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/task_runner.h"
16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h"
17 #include "net/proxy/proxy_config.h"
18 #include "net/proxy/proxy_config_service.h"
20 class PrefService;
22 namespace net {
23 class ProxyConfig;
26 namespace data_reduction_proxy {
28 // A net::ProxyConfigService implementation that applies data reduction proxy
29 // settings as overrides to the proxy configuration determined by a
30 // baseline delegate ProxyConfigService.
31 class DataReductionProxyConfigService
32 : public net::ProxyConfigService,
33 public net::ProxyConfigService::Observer {
34 public:
35 // Takes ownership of the passed |base_service|.
36 DataReductionProxyConfigService(
37 scoped_ptr<net::ProxyConfigService> base_service);
38 virtual ~DataReductionProxyConfigService();
40 // ProxyConfigService implementation:
41 virtual void AddObserver(
42 net::ProxyConfigService::Observer* observer) OVERRIDE;
43 virtual void RemoveObserver(
44 net::ProxyConfigService::Observer* observer) OVERRIDE;
45 virtual ConfigAvailability GetLatestProxyConfig(
46 net::ProxyConfig* config) OVERRIDE;
47 virtual void OnLazyPoll() OVERRIDE;
49 // Method on IO thread that receives the data reduction proxy settings pushed
50 // from DataReductionProxyConfiguratorImpl.
51 void UpdateProxyConfig(bool enabled,
52 const net::ProxyConfig& config);
54 private:
55 friend class DataReductionProxyConfigServiceTest;
57 // ProxyConfigService::Observer implementation:
58 virtual void OnProxyConfigChanged(const net::ProxyConfig& config,
59 ConfigAvailability availability) OVERRIDE;
61 // Makes sure that the observer registration with the base service is set up.
62 void RegisterObserver();
64 scoped_ptr<net::ProxyConfigService> base_service_;
65 ObserverList<net::ProxyConfigService::Observer, true> observers_;
67 // Configuration as defined by the data reduction proxy.
68 net::ProxyConfig config_;
70 // Flag that indicates that a PrefProxyConfigTracker needs to inform us
71 // about a proxy configuration before we may return any configuration.
72 bool config_read_pending_;
74 // Indicates whether the base service registration is done.
75 bool registered_observer_;
77 // The data reduction proxy is enabled.
78 bool enabled_;
80 // Use of the data reduction proxy is restricted to HTTP proxying only.
81 bool restricted_;
83 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigService);
86 // A data_reduction_proxy::DataReductionProxyConfigurator implementation that
87 // tracks changes to the data reduction proxy configuration and notifies an
88 // associated DataReductionProxyConfigService. Configuration changes include
89 // adding URL and host patterns to bypass and enabling and disabling use of the
90 // proxy.
91 class DataReductionProxyConfigTracker : public DataReductionProxyConfigurator {
92 public:
93 DataReductionProxyConfigTracker(
94 DataReductionProxyConfigService* config_service,
95 base::TaskRunner* task_runner);
96 virtual ~DataReductionProxyConfigTracker();
98 virtual void Enable(bool primary_restricted,
99 bool fallback_restricted,
100 const std::string& primary_origin,
101 const std::string& fallback_origin,
102 const std::string& ssl_origin) OVERRIDE;
103 virtual void Disable() OVERRIDE;
104 virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE;
105 virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE;
107 private:
108 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
109 TrackerEnable);
110 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
111 TrackerRestricted);
112 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
113 TrackerBypassList);
115 void UpdateProxyConfigOnIOThread(bool enabled,
116 const net::ProxyConfig& config);
118 DataReductionProxyConfigService* config_service_;
119 std::vector<std::string> bypass_rules_;
120 scoped_refptr<base::TaskRunner> task_runner_;
122 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigTracker);
125 } // namespace data_reduction_proxy
127 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_CONFIG_SERVICE_H_