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

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

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PrefNotifierImpl Created 8 years, 1 month 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) 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 #include "chrome/browser/net/ssl_config_service_manager.h" 4 #include "chrome/browser/net/ssl_config_service_manager.h"
5 5
6 #include <algorithm> 6 #include <algorithm>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/prefs/public/pref_change_registrar.h" 12 #include "base/prefs/public/pref_change_registrar.h"
13 #include "base/prefs/public/pref_observer.h"
13 #include "chrome/browser/api/prefs/pref_member.h" 14 #include "chrome/browser/api/prefs/pref_member.h"
14 #include "chrome/browser/content_settings/content_settings_utils.h" 15 #include "chrome/browser/content_settings/content_settings_utils.h"
15 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/content_settings.h" 18 #include "chrome/common/content_settings.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_source.h"
22 #include "net/base/ssl_cipher_suite_names.h" 21 #include "net/base/ssl_cipher_suite_names.h"
23 #include "net/base/ssl_config_service.h" 22 #include "net/base/ssl_config_service.h"
24 23
25 using content::BrowserThread; 24 using content::BrowserThread;
26 25
27 namespace { 26 namespace {
28 27
29 // Converts a ListValue of StringValues into a vector of strings. Any Values 28 // Converts a ListValue of StringValues into a vector of strings. Any Values
30 // which cannot be converted will be skipped. 29 // which cannot be converted will be skipped.
31 std::vector<std::string> ListValueToStringVector(const ListValue* value) { 30 std::vector<std::string> ListValueToStringVector(const ListValue* value) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 cached_config_ = new_config; 137 cached_config_ = new_config;
139 ProcessConfigUpdate(orig_config, new_config); 138 ProcessConfigUpdate(orig_config, new_config);
140 } 139 }
141 140
142 //////////////////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////////////////
143 // SSLConfigServiceManagerPref 142 // SSLConfigServiceManagerPref
144 143
145 // The manager for holding and updating an SSLConfigServicePref instance. 144 // The manager for holding and updating an SSLConfigServicePref instance.
146 class SSLConfigServiceManagerPref 145 class SSLConfigServiceManagerPref
147 : public SSLConfigServiceManager, 146 : public SSLConfigServiceManager,
148 public content::NotificationObserver { 147 public PrefObserver {
149 public: 148 public:
150 SSLConfigServiceManagerPref(PrefService* local_state, 149 SSLConfigServiceManagerPref(PrefService* local_state,
151 PrefService* user_prefs); 150 PrefService* user_prefs);
152 virtual ~SSLConfigServiceManagerPref() {} 151 virtual ~SSLConfigServiceManagerPref() {}
153 152
154 // Register local_state SSL preferences. 153 // Register local_state SSL preferences.
155 static void RegisterPrefs(PrefService* local_state); 154 static void RegisterPrefs(PrefService* local_state);
156 155
157 virtual net::SSLConfigService* Get(); 156 virtual net::SSLConfigService* Get();
158 157
159 private: 158 private:
160 // Callback for preference changes. This will post the changes to the IO 159 // Callback for preference changes. This will post the changes to the IO
161 // thread with SetNewSSLConfig. 160 // thread with SetNewSSLConfig.
162 virtual void Observe(int type, 161 virtual void OnPreferenceChanged(PrefServiceBase* service,
163 const content::NotificationSource& source, 162 const std::string& pref_name) OVERRIDE;
164 const content::NotificationDetails& details);
165 163
166 // Store SSL config settings in |config|, directly from the preferences. Must 164 // Store SSL config settings in |config|, directly from the preferences. Must
167 // only be called from UI thread. 165 // only be called from UI thread.
168 void GetSSLConfigFromPrefs(net::SSLConfig* config); 166 void GetSSLConfigFromPrefs(net::SSLConfig* config);
169 167
170 // Processes changes to the disabled cipher suites preference, updating the 168 // Processes changes to the disabled cipher suites preference, updating the
171 // cached list of parsed SSL/TLS cipher suites that are disabled. 169 // cached list of parsed SSL/TLS cipher suites that are disabled.
172 void OnDisabledCipherSuitesChange(PrefService* local_state); 170 void OnDisabledCipherSuitesChange(PrefService* local_state);
173 171
174 // Processes changes to the default cookie settings. 172 // Processes changes to the default cookie settings.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 default_config.channel_id_enabled); 246 default_config.channel_id_enabled);
249 local_state->RegisterBooleanPref(prefs::kDisableSSLRecordSplitting, 247 local_state->RegisterBooleanPref(prefs::kDisableSSLRecordSplitting,
250 !default_config.false_start_enabled); 248 !default_config.false_start_enabled);
251 local_state->RegisterListPref(prefs::kCipherSuiteBlacklist); 249 local_state->RegisterListPref(prefs::kCipherSuiteBlacklist);
252 } 250 }
253 251
254 net::SSLConfigService* SSLConfigServiceManagerPref::Get() { 252 net::SSLConfigService* SSLConfigServiceManagerPref::Get() {
255 return ssl_config_service_; 253 return ssl_config_service_;
256 } 254 }
257 255
258 void SSLConfigServiceManagerPref::Observe( 256 void SSLConfigServiceManagerPref::OnPreferenceChanged(
259 int type, 257 PrefServiceBase* service,
260 const content::NotificationSource& source, 258 const std::string& pref_name_in) {
261 const content::NotificationDetails& details) { 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
262 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 260 DCHECK(service);
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 261 PrefService* prefs = static_cast<PrefService*>(service);
Mattias Nissler (ping if slow) 2012/10/31 13:29:35 Can we do with a PrefServiceBase* instead?
Jói 2012/10/31 14:56:26 Done.
264 std::string* pref_name_in = content::Details<std::string>(details).ptr(); 262 if (pref_name_in == prefs::kCipherSuiteBlacklist)
265 PrefService* prefs = content::Source<PrefService>(source).ptr(); 263 OnDisabledCipherSuitesChange(prefs);
266 DCHECK(pref_name_in && prefs); 264 else if (pref_name_in == prefs::kDefaultContentSettings)
267 if (*pref_name_in == prefs::kCipherSuiteBlacklist) 265 OnDefaultContentSettingsChange(prefs);
268 OnDisabledCipherSuitesChange(prefs);
269 else if (*pref_name_in == prefs::kDefaultContentSettings)
270 OnDefaultContentSettingsChange(prefs);
271 266
272 net::SSLConfig new_config; 267 net::SSLConfig new_config;
273 GetSSLConfigFromPrefs(&new_config); 268 GetSSLConfigFromPrefs(&new_config);
274 269
275 // Post a task to |io_loop| with the new configuration, so it can 270 // Post a task to |io_loop| with the new configuration, so it can
276 // update |cached_config_|. 271 // update |cached_config_|.
277 BrowserThread::PostTask( 272 BrowserThread::PostTask(
278 BrowserThread::IO, 273 BrowserThread::IO,
279 FROM_HERE, 274 FROM_HERE,
280 base::Bind( 275 base::Bind(
281 &SSLConfigServicePref::SetNewSSLConfig, 276 &SSLConfigServicePref::SetNewSSLConfig,
282 ssl_config_service_.get(), 277 ssl_config_service_.get(),
283 new_config)); 278 new_config));
284 }
285 } 279 }
286 280
287 void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs( 281 void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs(
288 net::SSLConfig* config) { 282 net::SSLConfig* config) {
289 config->rev_checking_enabled = rev_checking_enabled_.GetValue(); 283 config->rev_checking_enabled = rev_checking_enabled_.GetValue();
290 std::string version_min_str = ssl_version_min_.GetValue(); 284 std::string version_min_str = ssl_version_min_.GetValue();
291 std::string version_max_str = ssl_version_max_.GetValue(); 285 std::string version_max_str = ssl_version_max_.GetValue();
292 config->version_min = net::SSLConfigService::default_version_min(); 286 config->version_min = net::SSLConfigService::default_version_min();
293 config->version_max = net::SSLConfigService::default_version_max(); 287 config->version_max = net::SSLConfigService::default_version_max();
294 uint16 version_min = SSLProtocolVersionFromString(version_min_str); 288 uint16 version_min = SSLProtocolVersionFromString(version_min_str);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // static 336 // static
343 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager( 337 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager(
344 PrefService* local_state, PrefService* user_prefs) { 338 PrefService* local_state, PrefService* user_prefs) {
345 return new SSLConfigServiceManagerPref(local_state, user_prefs); 339 return new SSLConfigServiceManagerPref(local_state, user_prefs);
346 } 340 }
347 341
348 // static 342 // static
349 void SSLConfigServiceManager::RegisterPrefs(PrefService* prefs) { 343 void SSLConfigServiceManager::RegisterPrefs(PrefService* prefs) {
350 SSLConfigServiceManagerPref::RegisterPrefs(prefs); 344 SSLConfigServiceManagerPref::RegisterPrefs(prefs);
351 } 345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698