Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/browser/net/pref_proxy_config_service.cc

Issue 8102019: redesign and reimplement proxy config service and tracker, revise proxy ui on cros (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/net/pref_proxy_config_service.h" 5 #include "chrome/browser/net/pref_proxy_config_service.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/prefs/pref_set_observer.h" 9 #include "chrome/browser/prefs/pref_set_observer.h"
10 #include "chrome/browser/prefs/proxy_config_dictionary.h" 10 #include "chrome/browser/prefs/proxy_config_dictionary.h"
11 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
14 #include "content/common/notification_details.h" 14 #include "content/common/notification_details.h"
15 #include "content/common/notification_source.h" 15 #include "content/common/notification_source.h"
16 16
17 PrefProxyConfigTracker::PrefProxyConfigTracker(PrefService* pref_service) 17 PrefProxyConfigTracker::PrefProxyConfigTracker(PrefService* pref_service)
18 : pref_service_(pref_service) { 18 : pref_service_(pref_service) {
19 config_state_ = ReadPrefConfig(&pref_config_); 19 ui_config_state_ = ReadPrefConfig(&ui_pref_config_);
20 io_config_state_ = ui_config_state_;
21 io_pref_config_ = ui_pref_config_;
20 proxy_prefs_observer_.reset( 22 proxy_prefs_observer_.reset(
21 PrefSetObserver::CreateProxyPrefSetObserver(pref_service_, this)); 23 PrefSetObserver::CreateProxyPrefSetObserver(pref_service_, this));
22 } 24 }
23 25
24 PrefProxyConfigTracker::~PrefProxyConfigTracker() { 26 PrefProxyConfigTracker::~PrefProxyConfigTracker() {
25 DCHECK(pref_service_ == NULL); 27 DCHECK(pref_service_ == NULL);
26 } 28 }
27 29
28 PrefProxyConfigTracker::ConfigState 30 PrefProxyConfigTracker::ConfigState
29 PrefProxyConfigTracker::GetProxyConfig(net::ProxyConfig* config) { 31 PrefProxyConfigTracker::IOGetProxyConfig(net::ProxyConfig* config) {
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
31 if (config_state_ != CONFIG_UNSET) 33 if (io_config_state_ != CONFIG_UNSET)
32 *config = pref_config_; 34 *config = io_pref_config_;
33 return config_state_; 35 return io_config_state_;
36 }
37
38 PrefProxyConfigTracker::ConfigState
39 PrefProxyConfigTracker::UIGetProxyConfig(net::ProxyConfig* config) {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
41 if (ui_config_state_ != CONFIG_UNSET)
42 *config = ui_pref_config_;
43 return ui_config_state_;
34 } 44 }
35 45
36 void PrefProxyConfigTracker::DetachFromPrefService() { 46 void PrefProxyConfigTracker::DetachFromPrefService() {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
38 // Stop notifications. 48 // Stop notifications.
39 proxy_prefs_observer_.reset(); 49 proxy_prefs_observer_.reset();
40 pref_service_ = NULL; 50 pref_service_ = NULL;
41 } 51 }
42 52
43 void PrefProxyConfigTracker::AddObserver( 53 void PrefProxyConfigTracker::AddObserver(
44 PrefProxyConfigTracker::Observer* observer) { 54 PrefProxyConfigTracker::Observer* observer) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
46 observers_.AddObserver(observer); 56 observers_.AddObserver(observer);
47 } 57 }
48 58
49 void PrefProxyConfigTracker::RemoveObserver( 59 void PrefProxyConfigTracker::RemoveObserver(
50 PrefProxyConfigTracker::Observer* observer) { 60 PrefProxyConfigTracker::Observer* observer) {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
52 observers_.RemoveObserver(observer); 62 observers_.RemoveObserver(observer);
53 } 63 }
54 64
55 void PrefProxyConfigTracker::Observe(int type, 65 void PrefProxyConfigTracker::Observe(int type,
56 const NotificationSource& source, 66 const NotificationSource& source,
57 const NotificationDetails& details) { 67 const NotificationDetails& details) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 if (type == chrome::NOTIFICATION_PREF_CHANGED && 69 if (type == chrome::NOTIFICATION_PREF_CHANGED &&
60 Source<PrefService>(source).ptr() == pref_service_) { 70 Source<PrefService>(source).ptr() == pref_service_) {
61 net::ProxyConfig new_config; 71 net::ProxyConfig new_config;
62 ConfigState config_state = ReadPrefConfig(&new_config); 72 ConfigState config_state = ReadPrefConfig(&new_config);
63 BrowserThread::PostTask( 73 if (ui_config_state_ != config_state ||
64 BrowserThread::IO, FROM_HERE, 74 (ui_config_state_ != CONFIG_UNSET &&
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 nit: not breaking this line would make the thing m
kuan 2011/10/07 00:30:41 i didn't want to, but it won't fit, so i don't hv
65 NewRunnableMethod(this, 75 !ui_pref_config_.Equals(new_config))) {
66 &PrefProxyConfigTracker::InstallProxyConfig, 76 ui_config_state_ = config_state;
67 new_config, config_state)); 77 if (ui_config_state_ != CONFIG_UNSET)
78 ui_pref_config_ = new_config;
79 BrowserThread::PostTask(
80 BrowserThread::IO, FROM_HERE,
81 NewRunnableMethod(this,
82 &PrefProxyConfigTracker::InstallProxyConfig,
83 new_config, config_state));
84 }
68 } else { 85 } else {
69 NOTREACHED() << "Unexpected notification of type " << type; 86 NOTREACHED() << "Unexpected notification of type " << type;
70 } 87 }
71 } 88 }
72 89
73 void PrefProxyConfigTracker::InstallProxyConfig( 90 void PrefProxyConfigTracker::InstallProxyConfig(
74 const net::ProxyConfig& config, 91 const net::ProxyConfig& config,
75 PrefProxyConfigTracker::ConfigState config_state) { 92 PrefProxyConfigTracker::ConfigState config_state) {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
77 if (config_state_ != config_state || 94 io_config_state_ = config_state;
78 (config_state_ != CONFIG_UNSET && !pref_config_.Equals(config))) { 95 if (io_config_state_ != CONFIG_UNSET)
79 config_state_ = config_state; 96 io_pref_config_ = config;
80 if (config_state_ != CONFIG_UNSET) 97 FOR_EACH_OBSERVER(Observer, observers_, OnPrefProxyConfigChanged());
81 pref_config_ = config;
82 FOR_EACH_OBSERVER(Observer, observers_, OnPrefProxyConfigChanged());
83 }
84 } 98 }
85 99
86 PrefProxyConfigTracker::ConfigState 100 PrefProxyConfigTracker::ConfigState
87 PrefProxyConfigTracker::ReadPrefConfig(net::ProxyConfig* config) { 101 PrefProxyConfigTracker::ReadPrefConfig(net::ProxyConfig* config) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
89 103
90 // Clear the configuration. 104 // Clear the configuration.
91 *config = net::ProxyConfig(); 105 *config = net::ProxyConfig();
92 106
93 const PrefService::Preference* pref = 107 const PrefService::Preference* pref =
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 void PrefProxyConfigService::RemoveObserver( 205 void PrefProxyConfigService::RemoveObserver(
192 net::ProxyConfigService::Observer* observer) { 206 net::ProxyConfigService::Observer* observer) {
193 observers_.RemoveObserver(observer); 207 observers_.RemoveObserver(observer);
194 } 208 }
195 209
196 net::ProxyConfigService::ConfigAvailability 210 net::ProxyConfigService::ConfigAvailability
197 PrefProxyConfigService::GetLatestProxyConfig(net::ProxyConfig* config) { 211 PrefProxyConfigService::GetLatestProxyConfig(net::ProxyConfig* config) {
198 RegisterObservers(); 212 RegisterObservers();
199 net::ProxyConfig pref_config; 213 net::ProxyConfig pref_config;
200 PrefProxyConfigTracker::ConfigState state = 214 PrefProxyConfigTracker::ConfigState state =
201 pref_config_tracker_->GetProxyConfig(&pref_config); 215 pref_config_tracker_->IOGetProxyConfig(&pref_config);
202 if (state == PrefProxyConfigTracker::CONFIG_PRESENT) { 216 if (state == PrefProxyConfigTracker::CONFIG_PRESENT) {
203 *config = pref_config; 217 *config = pref_config;
204 return CONFIG_VALID; 218 return CONFIG_VALID;
205 } 219 }
206 220
207 // Ask the base service. 221 // Ask the base service.
208 ConfigAvailability available = base_service_->GetLatestProxyConfig(config); 222 ConfigAvailability available = base_service_->GetLatestProxyConfig(config);
209 223
210 // Base service doesn't have a configuration, fall back to prefs or default. 224 // Base service doesn't have a configuration, fall back to prefs or default.
211 if (available == CONFIG_UNSET) { 225 if (available == CONFIG_UNSET) {
(...skipping 13 matching lines...) Expand all
225 239
226 void PrefProxyConfigService::OnProxyConfigChanged( 240 void PrefProxyConfigService::OnProxyConfigChanged(
227 const net::ProxyConfig& config, 241 const net::ProxyConfig& config,
228 ConfigAvailability availability) { 242 ConfigAvailability availability) {
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
230 244
231 // Check whether there is a proxy configuration defined by preferences. In 245 // Check whether there is a proxy configuration defined by preferences. In
232 // this case that proxy configuration takes precedence and the change event 246 // this case that proxy configuration takes precedence and the change event
233 // from the delegate proxy service can be disregarded. 247 // from the delegate proxy service can be disregarded.
234 net::ProxyConfig actual_config; 248 net::ProxyConfig actual_config;
235 if (pref_config_tracker_->GetProxyConfig(&actual_config) != 249 if (pref_config_tracker_->IOGetProxyConfig(&actual_config) !=
236 PrefProxyConfigTracker::CONFIG_PRESENT) { 250 PrefProxyConfigTracker::CONFIG_PRESENT) {
237 availability = GetLatestProxyConfig(&actual_config); 251 availability = GetLatestProxyConfig(&actual_config);
238 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, 252 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_,
239 OnProxyConfigChanged(actual_config, availability)); 253 OnProxyConfigChanged(actual_config, availability));
240 } 254 }
241 } 255 }
242 256
243 void PrefProxyConfigService::OnPrefProxyConfigChanged() { 257 void PrefProxyConfigService::OnPrefProxyConfigChanged() {
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
245 259
(...skipping 22 matching lines...) Expand all
268 } 282 }
269 } 283 }
270 284
271 // static 285 // static
272 void PrefProxyConfigService::RegisterPrefs(PrefService* pref_service) { 286 void PrefProxyConfigService::RegisterPrefs(PrefService* pref_service) {
273 DictionaryValue* default_settings = ProxyConfigDictionary::CreateSystem(); 287 DictionaryValue* default_settings = ProxyConfigDictionary::CreateSystem();
274 pref_service->RegisterDictionaryPref(prefs::kProxy, 288 pref_service->RegisterDictionaryPref(prefs::kProxy,
275 default_settings, 289 default_settings,
276 PrefService::UNSYNCABLE_PREF); 290 PrefService::UNSYNCABLE_PREF);
277 } 291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698