Add diagnostics_writer.cc to the list of files allowed to printf.
[chromium-blink-merge.git] / components / data_reduction_proxy / browser / data_reduction_proxy_config_service.h
blob7c92938681d21e8d162ea1ef4ceea57d931074a8
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/callback.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/task_runner.h"
17 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h"
18 #include "net/proxy/proxy_config.h"
19 #include "net/proxy/proxy_config_service.h"
21 class PrefService;
23 namespace net {
24 class ProxyConfig;
27 namespace data_reduction_proxy {
29 // A net::ProxyConfigService implementation that applies data reduction proxy
30 // settings as overrides to the proxy configuration determined by a
31 // baseline delegate ProxyConfigService.
32 class DataReductionProxyConfigService
33 : public net::ProxyConfigService,
34 public net::ProxyConfigService::Observer {
35 public:
36 // Takes ownership of the passed |base_service|.
37 DataReductionProxyConfigService(
38 scoped_ptr<net::ProxyConfigService> base_service);
39 virtual ~DataReductionProxyConfigService();
41 // ProxyConfigService implementation:
42 virtual void AddObserver(
43 net::ProxyConfigService::Observer* observer) OVERRIDE;
44 virtual void RemoveObserver(
45 net::ProxyConfigService::Observer* observer) OVERRIDE;
46 virtual ConfigAvailability GetLatestProxyConfig(
47 net::ProxyConfig* config) OVERRIDE;
48 virtual void OnLazyPoll() OVERRIDE;
50 // Method on IO thread that receives the data reduction proxy settings pushed
51 // from DataReductionProxyConfiguratorImpl.
52 void UpdateProxyConfig(bool enabled,
53 const net::ProxyConfig& config);
55 private:
56 friend class DataReductionProxyConfigServiceTest;
58 // ProxyConfigService::Observer implementation:
59 virtual void OnProxyConfigChanged(const net::ProxyConfig& config,
60 ConfigAvailability availability) OVERRIDE;
62 // Makes sure that the observer registration with the base service is set up.
63 void RegisterObserver();
65 scoped_ptr<net::ProxyConfigService> base_service_;
66 ObserverList<net::ProxyConfigService::Observer, true> observers_;
68 // Configuration as defined by the data reduction proxy.
69 net::ProxyConfig config_;
71 // Flag that indicates that a PrefProxyConfigTracker needs to inform us
72 // about a proxy configuration before we may return any configuration.
73 bool config_read_pending_;
75 // Indicates whether the base service registration is done.
76 bool registered_observer_;
78 // The data reduction proxy is enabled.
79 bool enabled_;
81 // Use of the data reduction proxy is restricted to HTTP proxying only.
82 bool restricted_;
84 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigService);
87 // A data_reduction_proxy::DataReductionProxyConfigurator implementation that
88 // tracks changes to the data reduction proxy configuration and notifies an
89 // associated DataReductionProxyConfigService. Configuration changes include
90 // adding URL and host patterns to bypass and enabling and disabling use of the
91 // proxy.
92 class DataReductionProxyConfigTracker : public DataReductionProxyConfigurator {
93 public:
94 DataReductionProxyConfigTracker(
95 base::Callback<void(bool, const net::ProxyConfig&)> update_proxy_config,
96 base::TaskRunner* task_runner);
97 virtual ~DataReductionProxyConfigTracker();
99 virtual void Enable(bool primary_restricted,
100 bool fallback_restricted,
101 const std::string& primary_origin,
102 const std::string& fallback_origin,
103 const std::string& ssl_origin) OVERRIDE;
104 virtual void Disable() OVERRIDE;
105 virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE;
106 virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE;
108 private:
109 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
110 TrackerEnable);
111 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
112 TrackerRestricted);
113 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
114 TrackerBypassList);
116 void UpdateProxyConfigOnIOThread(bool enabled,
117 const net::ProxyConfig& config);
119 base::Callback<void(bool, const net::ProxyConfig&)> update_proxy_config_;
120 std::vector<std::string> bypass_rules_;
121 scoped_refptr<base::TaskRunner> task_runner_;
123 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigTracker);
126 } // namespace data_reduction_proxy
128 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_CONFIG_SERVICE_H_