OLD | NEW |
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/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
12 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
13 #include "content/common/notification_details.h" | 14 #include "content/common/notification_details.h" |
14 #include "content/common/notification_source.h" | 15 #include "content/common/notification_source.h" |
15 #include "content/common/notification_type.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 config_state_ = ReadPrefConfig(&pref_config_); |
20 proxy_prefs_observer_.reset( | 20 proxy_prefs_observer_.reset( |
21 PrefSetObserver::CreateProxyPrefSetObserver(pref_service_, this)); | 21 PrefSetObserver::CreateProxyPrefSetObserver(pref_service_, this)); |
22 } | 22 } |
23 | 23 |
24 PrefProxyConfigTracker::~PrefProxyConfigTracker() { | 24 PrefProxyConfigTracker::~PrefProxyConfigTracker() { |
25 DCHECK(pref_service_ == NULL); | 25 DCHECK(pref_service_ == NULL); |
(...skipping 19 matching lines...) Expand all Loading... |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
46 observers_.AddObserver(observer); | 46 observers_.AddObserver(observer); |
47 } | 47 } |
48 | 48 |
49 void PrefProxyConfigTracker::RemoveObserver( | 49 void PrefProxyConfigTracker::RemoveObserver( |
50 PrefProxyConfigTracker::Observer* observer) { | 50 PrefProxyConfigTracker::Observer* observer) { |
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
52 observers_.RemoveObserver(observer); | 52 observers_.RemoveObserver(observer); |
53 } | 53 } |
54 | 54 |
55 void PrefProxyConfigTracker::Observe(NotificationType type, | 55 void PrefProxyConfigTracker::Observe(int type, |
56 const NotificationSource& source, | 56 const NotificationSource& source, |
57 const NotificationDetails& details) { | 57 const NotificationDetails& details) { |
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
59 if (type == NotificationType::PREF_CHANGED && | 59 if (type == chrome::NOTIFICATION_PREF_CHANGED && |
60 Source<PrefService>(source).ptr() == pref_service_) { | 60 Source<PrefService>(source).ptr() == pref_service_) { |
61 net::ProxyConfig new_config; | 61 net::ProxyConfig new_config; |
62 ConfigState config_state = ReadPrefConfig(&new_config); | 62 ConfigState config_state = ReadPrefConfig(&new_config); |
63 BrowserThread::PostTask( | 63 BrowserThread::PostTask( |
64 BrowserThread::IO, FROM_HERE, | 64 BrowserThread::IO, FROM_HERE, |
65 NewRunnableMethod(this, | 65 NewRunnableMethod(this, |
66 &PrefProxyConfigTracker::InstallProxyConfig, | 66 &PrefProxyConfigTracker::InstallProxyConfig, |
67 new_config, config_state)); | 67 new_config, config_state)); |
68 } else { | 68 } else { |
69 NOTREACHED() << "Unexpected notification of type " << type.value; | 69 NOTREACHED() << "Unexpected notification of type " << type; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 void PrefProxyConfigTracker::InstallProxyConfig( | 73 void PrefProxyConfigTracker::InstallProxyConfig( |
74 const net::ProxyConfig& config, | 74 const net::ProxyConfig& config, |
75 PrefProxyConfigTracker::ConfigState config_state) { | 75 PrefProxyConfigTracker::ConfigState config_state) { |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
77 if (config_state_ != config_state || | 77 if (config_state_ != config_state || |
78 (config_state_ != CONFIG_UNSET && !pref_config_.Equals(config))) { | 78 (config_state_ != CONFIG_UNSET && !pref_config_.Equals(config))) { |
79 config_state_ = config_state; | 79 config_state_ = config_state; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 } | 269 } |
270 | 270 |
271 // static | 271 // static |
272 void PrefProxyConfigService::RegisterPrefs(PrefService* pref_service) { | 272 void PrefProxyConfigService::RegisterPrefs(PrefService* pref_service) { |
273 DictionaryValue* default_settings = ProxyConfigDictionary::CreateSystem(); | 273 DictionaryValue* default_settings = ProxyConfigDictionary::CreateSystem(); |
274 pref_service->RegisterDictionaryPref(prefs::kProxy, | 274 pref_service->RegisterDictionaryPref(prefs::kProxy, |
275 default_settings, | 275 default_settings, |
276 PrefService::UNSYNCABLE_PREF); | 276 PrefService::UNSYNCABLE_PREF); |
277 } | 277 } |
OLD | NEW |