OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.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/common/notification_details.h" | 10 #include "chrome/common/notification_details.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 } | 31 } |
32 | 32 |
33 void PrefProxyConfigTracker::DetachFromPrefService() { | 33 void PrefProxyConfigTracker::DetachFromPrefService() { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
35 // Stop notifications. | 35 // Stop notifications. |
36 proxy_prefs_observer_.reset(); | 36 proxy_prefs_observer_.reset(); |
37 pref_service_ = NULL; | 37 pref_service_ = NULL; |
38 } | 38 } |
39 | 39 |
40 void PrefProxyConfigTracker::AddObserver( | 40 void PrefProxyConfigTracker::AddObserver( |
41 PrefProxyConfigTracker::ObserverInterface* observer) { | 41 PrefProxyConfigTracker::Observer* observer) { |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
43 observers_.AddObserver(observer); | 43 observers_.AddObserver(observer); |
44 } | 44 } |
45 | 45 |
46 void PrefProxyConfigTracker::RemoveObserver( | 46 void PrefProxyConfigTracker::RemoveObserver( |
47 PrefProxyConfigTracker::ObserverInterface* observer) { | 47 PrefProxyConfigTracker::Observer* observer) { |
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
49 observers_.RemoveObserver(observer); | 49 observers_.RemoveObserver(observer); |
50 } | 50 } |
51 | 51 |
52 void PrefProxyConfigTracker::Observe(NotificationType type, | 52 void PrefProxyConfigTracker::Observe(NotificationType type, |
53 const NotificationSource& source, | 53 const NotificationSource& source, |
54 const NotificationDetails& details) { | 54 const NotificationDetails& details) { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
56 if (type == NotificationType::PREF_CHANGED && | 56 if (type == NotificationType::PREF_CHANGED && |
57 Source<PrefService>(source).ptr() == pref_service_) { | 57 Source<PrefService>(source).ptr() == pref_service_) { |
58 net::ProxyConfig new_config; | 58 net::ProxyConfig new_config; |
59 bool valid = ReadPrefConfig(&new_config); | 59 bool valid = ReadPrefConfig(&new_config); |
60 BrowserThread::PostTask( | 60 BrowserThread::PostTask( |
61 BrowserThread::IO, FROM_HERE, | 61 BrowserThread::IO, FROM_HERE, |
62 NewRunnableMethod(this, | 62 NewRunnableMethod(this, |
63 &PrefProxyConfigTracker::InstallProxyConfig, | 63 &PrefProxyConfigTracker::InstallProxyConfig, |
64 new_config, valid)); | 64 new_config, valid)); |
65 } else { | 65 } else { |
66 NOTREACHED() << "Unexpected notification of type " << type.value; | 66 NOTREACHED() << "Unexpected notification of type " << type.value; |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void PrefProxyConfigTracker::InstallProxyConfig(const net::ProxyConfig& config, | 70 void PrefProxyConfigTracker::InstallProxyConfig(const net::ProxyConfig& config, |
71 bool valid) { | 71 bool valid) { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
73 if (valid_ != valid || !pref_config_.Equals(config)) { | 73 if (valid && (!valid_ || !pref_config_.Equals(config))) { |
eroman
2010/12/02 19:31:22
I don't think this is right, since it looks like w
eroman
2010/12/02 19:32:40
Oops my pseudo-code wasn't right either :-)
Let me
battre (please use the other)
2010/12/03 08:57:23
Done.
| |
74 valid_ = valid; | 74 valid_ = valid; |
75 if (valid_) | 75 if (valid_) |
76 pref_config_ = config; | 76 pref_config_ = config; |
77 FOR_EACH_OBSERVER(ObserverInterface, observers_, | 77 FOR_EACH_OBSERVER(Observer, observers_, OnPrefProxyConfigChanged()); |
78 OnPrefProxyConfigChanged()); | |
79 } | 78 } |
80 } | 79 } |
81 | 80 |
82 bool PrefProxyConfigTracker::ReadPrefConfig(net::ProxyConfig* config) { | 81 bool PrefProxyConfigTracker::ReadPrefConfig(net::ProxyConfig* config) { |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
84 | 83 |
85 // Clear the configuration. | 84 // Clear the configuration. |
86 *config = net::ProxyConfig(); | 85 *config = net::ProxyConfig(); |
87 | 86 |
88 // Scan for all "enable" type proxy switches. | 87 // Scan for all "enable" type proxy switches. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 observers_.AddObserver(observer); | 161 observers_.AddObserver(observer); |
163 } | 162 } |
164 | 163 |
165 void PrefProxyConfigService::RemoveObserver( | 164 void PrefProxyConfigService::RemoveObserver( |
166 net::ProxyConfigService::Observer* observer) { | 165 net::ProxyConfigService::Observer* observer) { |
167 observers_.RemoveObserver(observer); | 166 observers_.RemoveObserver(observer); |
168 } | 167 } |
169 | 168 |
170 bool PrefProxyConfigService::GetLatestProxyConfig(net::ProxyConfig* config) { | 169 bool PrefProxyConfigService::GetLatestProxyConfig(net::ProxyConfig* config) { |
171 RegisterObservers(); | 170 RegisterObservers(); |
172 const net::ProxyConfig pref_config; | 171 net::ProxyConfig pref_config; |
173 if (pref_config_tracker_->GetProxyConfig(config)) | 172 if (pref_config_tracker_->GetProxyConfig(&pref_config)) { |
173 *config = pref_config; | |
174 return true; | 174 return true; |
175 } | |
175 | 176 |
176 return base_service_->GetLatestProxyConfig(config); | 177 return base_service_->GetLatestProxyConfig(config); |
177 } | 178 } |
178 | 179 |
179 void PrefProxyConfigService::OnLazyPoll() { | 180 void PrefProxyConfigService::OnLazyPoll() { |
180 base_service_->OnLazyPoll(); | 181 base_service_->OnLazyPoll(); |
181 } | 182 } |
182 | 183 |
183 void PrefProxyConfigService::OnProxyConfigChanged( | 184 void PrefProxyConfigService::OnProxyConfigChanged( |
184 const net::ProxyConfig& config) { | 185 const net::ProxyConfig& config) { |
(...skipping 28 matching lines...) Expand all Loading... | |
213 } | 214 } |
214 | 215 |
215 void PrefProxyConfigService::RegisterObservers() { | 216 void PrefProxyConfigService::RegisterObservers() { |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
217 if (!registered_observers_) { | 218 if (!registered_observers_) { |
218 base_service_->AddObserver(this); | 219 base_service_->AddObserver(this); |
219 pref_config_tracker_->AddObserver(this); | 220 pref_config_tracker_->AddObserver(this); |
220 registered_observers_ = true; | 221 registered_observers_ = true; |
221 } | 222 } |
222 } | 223 } |
OLD | NEW |