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

Side by Side Diff: base/prefs/pref_service.cc

Issue 12330008: Get rid of the ability to unregister preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head for commit. Created 7 years, 10 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
« no previous file with comments | « base/prefs/pref_service.h ('k') | chrome/browser/chromeos/login/oauth2_login_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4
5 #include "base/prefs/pref_service.h" 5 #include "base/prefs/pref_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 : pref_notifier_(pref_notifier), 51 : pref_notifier_(pref_notifier),
52 pref_value_store_(pref_value_store), 52 pref_value_store_(pref_value_store),
53 pref_registry_(pref_registry), 53 pref_registry_(pref_registry),
54 user_pref_store_(user_prefs), 54 user_pref_store_(user_prefs),
55 read_error_callback_(read_error_callback) { 55 read_error_callback_(read_error_callback) {
56 pref_notifier_->SetPrefService(this); 56 pref_notifier_->SetPrefService(this);
57 57
58 pref_registry_->SetRegistrationCallback( 58 pref_registry_->SetRegistrationCallback(
59 base::Bind(&PrefService::AddRegisteredPreference, 59 base::Bind(&PrefService::AddRegisteredPreference,
60 base::Unretained(this))); 60 base::Unretained(this)));
61 pref_registry_->SetUnregistrationCallback(
62 base::Bind(&PrefService::RemoveRegisteredPreference,
63 base::Unretained(this)));
64 AddInitialPreferences(); 61 AddInitialPreferences();
65 62
66 InitFromStorage(async); 63 InitFromStorage(async);
67 } 64 }
68 65
69 PrefService::~PrefService() { 66 PrefService::~PrefService() {
70 DCHECK(CalledOnValidThread()); 67 DCHECK(CalledOnValidThread());
71 68
72 // Remove our callbacks, setting NULL ones. 69 // Remove our callback, setting a NULL one.
73 pref_registry_->SetRegistrationCallback(PrefRegistry::RegistrationCallback()); 70 pref_registry_->SetRegistrationCallback(PrefRegistry::RegistrationCallback());
74 pref_registry_->SetUnregistrationCallback(
75 PrefRegistry::UnregistrationCallback());
76 71
77 // Reset pointers so accesses after destruction reliably crash. 72 // Reset pointers so accesses after destruction reliably crash.
78 pref_value_store_.reset(); 73 pref_value_store_.reset();
79 pref_registry_ = NULL; 74 pref_registry_ = NULL;
80 user_pref_store_ = NULL; 75 user_pref_store_ = NULL;
81 pref_notifier_.reset(); 76 pref_notifier_.reset();
82 } 77 }
83 78
84 void PrefService::InitFromStorage(bool async) { 79 void PrefService::InitFromStorage(bool async) {
85 if (!async) { 80 if (!async) {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 needs_empty_value = true; 344 needs_empty_value = true;
350 } else if (orig_type == base::Value::TYPE_DICTIONARY) { 345 } else if (orig_type == base::Value::TYPE_DICTIONARY) {
351 const base::DictionaryValue* dict = NULL; 346 const base::DictionaryValue* dict = NULL;
352 if (default_value->GetAsDictionary(&dict) && !dict->empty()) 347 if (default_value->GetAsDictionary(&dict) && !dict->empty())
353 needs_empty_value = true; 348 needs_empty_value = true;
354 } 349 }
355 if (needs_empty_value) 350 if (needs_empty_value)
356 user_pref_store_->MarkNeedsEmptyValue(path); 351 user_pref_store_->MarkNeedsEmptyValue(path);
357 } 352 }
358 353
359 // TODO(joi): We can get rid of this once the ability to unregister
360 // prefs has been removed.
361 void PrefService::RemoveRegisteredPreference(const char* path) {
362 DCHECK(CalledOnValidThread());
363
364 prefs_map_.erase(path);
365 }
366
367 void PrefService::ClearPref(const char* path) { 354 void PrefService::ClearPref(const char* path) {
368 DCHECK(CalledOnValidThread()); 355 DCHECK(CalledOnValidThread());
369 356
370 const Preference* pref = FindPreference(path); 357 const Preference* pref = FindPreference(path);
371 if (!pref) { 358 if (!pref) {
372 NOTREACHED() << "Trying to clear an unregistered pref: " << path; 359 NOTREACHED() << "Trying to clear an unregistered pref: " << path;
373 return; 360 return;
374 } 361 }
375 user_pref_store_->RemoveValue(path); 362 user_pref_store_->RemoveValue(path);
376 } 363 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 DCHECK(found_value->IsType(default_type)); 575 DCHECK(found_value->IsType(default_type));
589 return found_value; 576 return found_value;
590 } else { 577 } else {
591 // Every registered preference has at least a default value. 578 // Every registered preference has at least a default value.
592 NOTREACHED() << "no valid value found for registered pref " << path; 579 NOTREACHED() << "no valid value found for registered pref " << path;
593 } 580 }
594 } 581 }
595 582
596 return NULL; 583 return NULL;
597 } 584 }
OLDNEW
« no previous file with comments | « base/prefs/pref_service.h ('k') | chrome/browser/chromeos/login/oauth2_login_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698