OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ | 5 #ifndef COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
6 #define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ | 6 #define COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
13 #include "chrome/browser/net/pref_proxy_config_tracker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "components/proxy_config/pref_proxy_config_tracker.h" |
14 #include "components/proxy_config/proxy_config_dictionary.h" | 15 #include "components/proxy_config/proxy_config_dictionary.h" |
15 #include "net/proxy/proxy_config.h" | 16 #include "net/proxy/proxy_config.h" |
16 #include "net/proxy/proxy_config_service.h" | 17 #include "net/proxy/proxy_config_service.h" |
17 | 18 |
18 class PrefService; | 19 class PrefService; |
19 class PrefRegistrySimple; | 20 class PrefRegistrySimple; |
20 | 21 |
| 22 namespace base { |
| 23 class SingleThreadTaskRunner; |
| 24 } |
| 25 |
21 namespace user_prefs { | 26 namespace user_prefs { |
22 class PrefRegistrySyncable; | 27 class PrefRegistrySyncable; |
23 } | 28 } |
24 | 29 |
25 // A net::ProxyConfigService implementation that applies preference proxy | 30 // A net::ProxyConfigService implementation that applies preference proxy |
26 // settings (pushed from PrefProxyConfigTrackerImpl) as overrides to the proxy | 31 // settings (pushed from PrefProxyConfigTrackerImpl) as overrides to the proxy |
27 // configuration determined by a baseline delegate ProxyConfigService on | 32 // configuration determined by a baseline delegate ProxyConfigService on |
28 // non-ChromeOS platforms. ChromeOS has its own implementation of overrides in | 33 // non-ChromeOS platforms. ChromeOS has its own implementation of overrides in |
29 // chromeos::ProxyConfigServiceImpl. | 34 // chromeos::ProxyConfigServiceImpl. |
30 class ChromeProxyConfigService | 35 class ProxyConfigServiceImpl : public net::ProxyConfigService, |
31 : public net::ProxyConfigService, | 36 public net::ProxyConfigService::Observer { |
32 public net::ProxyConfigService::Observer { | |
33 public: | 37 public: |
34 // Takes ownership of the passed |base_service|. | 38 // Takes ownership of the passed |base_service|. |
35 // GetLatestProxyConfig returns ConfigAvailability::CONFIG_PENDING until | 39 // GetLatestProxyConfig returns ConfigAvailability::CONFIG_PENDING until |
36 // UpdateProxyConfig has been called. | 40 // UpdateProxyConfig has been called. |
37 explicit ChromeProxyConfigService(net::ProxyConfigService* base_service); | 41 explicit ProxyConfigServiceImpl(net::ProxyConfigService* base_service); |
38 ~ChromeProxyConfigService() override; | 42 ~ProxyConfigServiceImpl() override; |
39 | 43 |
40 // ProxyConfigService implementation: | 44 // ProxyConfigService implementation: |
41 void AddObserver(net::ProxyConfigService::Observer* observer) override; | 45 void AddObserver(net::ProxyConfigService::Observer* observer) override; |
42 void RemoveObserver(net::ProxyConfigService::Observer* observer) override; | 46 void RemoveObserver(net::ProxyConfigService::Observer* observer) override; |
43 ConfigAvailability GetLatestProxyConfig(net::ProxyConfig* config) override; | 47 ConfigAvailability GetLatestProxyConfig(net::ProxyConfig* config) override; |
44 void OnLazyPoll() override; | 48 void OnLazyPoll() override; |
45 | 49 |
46 // Method on IO thread that receives the preference proxy settings pushed from | 50 // Method on IO thread that receives the preference proxy settings pushed from |
47 // PrefProxyConfigTrackerImpl. | 51 // PrefProxyConfigTrackerImpl. |
48 void UpdateProxyConfig(ProxyPrefs::ConfigState config_state, | 52 void UpdateProxyConfig(ProxyPrefs::ConfigState config_state, |
(...skipping 17 matching lines...) Expand all Loading... |
66 // Configuration as defined by prefs. | 70 // Configuration as defined by prefs. |
67 net::ProxyConfig pref_config_; | 71 net::ProxyConfig pref_config_; |
68 | 72 |
69 // Flag that indicates that a PrefProxyConfigTracker needs to inform us | 73 // Flag that indicates that a PrefProxyConfigTracker needs to inform us |
70 // about a proxy configuration before we may return any configuration. | 74 // about a proxy configuration before we may return any configuration. |
71 bool pref_config_read_pending_; | 75 bool pref_config_read_pending_; |
72 | 76 |
73 // Indicates whether the base service registration is done. | 77 // Indicates whether the base service registration is done. |
74 bool registered_observer_; | 78 bool registered_observer_; |
75 | 79 |
76 DISALLOW_COPY_AND_ASSIGN(ChromeProxyConfigService); | 80 base::ThreadChecker thread_checker_; |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); |
77 }; | 83 }; |
78 | 84 |
79 // A class that tracks proxy preferences. It translates the configuration | 85 // A class that tracks proxy preferences. It translates the configuration |
80 // to net::ProxyConfig and pushes the result over to the IO thread for | 86 // to net::ProxyConfig and pushes the result over to the IO thread for |
81 // ChromeProxyConfigService::UpdateProxyConfig to use. | 87 // ProxyConfigServiceImpl::UpdateProxyConfig to use. |
82 class PrefProxyConfigTrackerImpl : public PrefProxyConfigTracker { | 88 class PROXY_CONFIG_EXPORT PrefProxyConfigTrackerImpl |
| 89 : public PrefProxyConfigTracker { |
83 public: | 90 public: |
84 explicit PrefProxyConfigTrackerImpl(PrefService* pref_service); | 91 PrefProxyConfigTrackerImpl( |
| 92 PrefService* pref_service, |
| 93 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
85 ~PrefProxyConfigTrackerImpl() override; | 94 ~PrefProxyConfigTrackerImpl() override; |
86 | 95 |
87 // PrefProxyConfigTracker implementation: | 96 // PrefProxyConfigTracker implementation: |
88 scoped_ptr<net::ProxyConfigService> CreateTrackingProxyConfigService( | 97 scoped_ptr<net::ProxyConfigService> CreateTrackingProxyConfigService( |
89 scoped_ptr<net::ProxyConfigService> base_service) override; | 98 scoped_ptr<net::ProxyConfigService> base_service) override; |
90 | 99 |
91 // Notifies the tracker that the pref service passed upon construction is | 100 // Notifies the tracker that the pref service passed upon construction is |
92 // about to go away. This must be called from the UI thread. | 101 // about to go away. This must be called from the UI thread. |
93 void DetachFromPrefService() override; | 102 void DetachFromPrefService() override; |
94 | 103 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 157 |
149 private: | 158 private: |
150 // Tracks configuration state. |pref_config_| is valid only if |config_state_| | 159 // Tracks configuration state. |pref_config_| is valid only if |config_state_| |
151 // is not CONFIG_UNSET. | 160 // is not CONFIG_UNSET. |
152 ProxyPrefs::ConfigState config_state_; | 161 ProxyPrefs::ConfigState config_state_; |
153 | 162 |
154 // Configuration as defined by prefs. | 163 // Configuration as defined by prefs. |
155 net::ProxyConfig pref_config_; | 164 net::ProxyConfig pref_config_; |
156 | 165 |
157 PrefService* pref_service_; | 166 PrefService* pref_service_; |
158 ChromeProxyConfigService* chrome_proxy_config_service_; // Weak ptr. | 167 ProxyConfigServiceImpl* proxy_config_service_impl_; // Weak ptr. |
159 bool update_pending_; // True if config has not been pushed to network stack. | 168 bool update_pending_; // True if config has not been pushed to network stack. |
160 PrefChangeRegistrar proxy_prefs_; | 169 PrefChangeRegistrar proxy_prefs_; |
161 | 170 |
| 171 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 172 |
| 173 base::ThreadChecker thread_checker_; |
| 174 |
162 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTrackerImpl); | 175 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTrackerImpl); |
163 }; | 176 }; |
164 | 177 |
165 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ | 178 #endif // COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
OLD | NEW |