| OLD | NEW |
| 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_registry.h" | 5 #include "base/prefs/pref_registry.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/prefs/default_pref_store.h" | 8 #include "base/prefs/default_pref_store.h" |
| 9 #include "base/prefs/pref_store.h" | 9 #include "base/prefs/pref_store.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 | 11 |
| 12 PrefRegistry::PrefRegistry() | 12 PrefRegistry::PrefRegistry() |
| 13 : defaults_(new DefaultPrefStore()) { | 13 : defaults_(new DefaultPrefStore()) { |
| 14 } | 14 } |
| 15 | 15 |
| 16 PrefRegistry::~PrefRegistry() { | 16 PrefRegistry::~PrefRegistry() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 scoped_refptr<PrefStore> PrefRegistry::defaults() { | 19 scoped_refptr<DefaultPrefStore> PrefRegistry::defaults() { |
| 20 return defaults_.get(); | 20 return defaults_.get(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 PrefRegistry::const_iterator PrefRegistry::begin() const { | |
| 24 return defaults_->begin(); | |
| 25 } | |
| 26 | |
| 27 PrefRegistry::const_iterator PrefRegistry::end() const { | |
| 28 return defaults_->end(); | |
| 29 } | |
| 30 | |
| 31 void PrefRegistry::SetRegistrationCallback( | 23 void PrefRegistry::SetRegistrationCallback( |
| 32 const RegistrationCallback& callback) { | 24 const RegistrationCallback& callback) { |
| 33 registration_callback_ = callback; | 25 registration_callback_ = callback; |
| 34 } | 26 } |
| 35 | 27 |
| 36 void PrefRegistry::RegisterPreference(const char* path, | 28 void PrefRegistry::RegisterPreference(const char* path, |
| 37 base::Value* default_value) { | 29 base::Value* default_value) { |
| 38 base::Value::Type orig_type = default_value->GetType(); | 30 base::Value::Type orig_type = default_value->GetType(); |
| 39 DCHECK(orig_type != base::Value::TYPE_NULL && | 31 DCHECK(orig_type != base::Value::TYPE_NULL && |
| 40 orig_type != base::Value::TYPE_BINARY) << | 32 orig_type != base::Value::TYPE_BINARY) << |
| 41 "invalid preference type: " << orig_type; | 33 "invalid preference type: " << orig_type; |
| 42 DCHECK(!defaults_->GetValue(path, NULL)) << | 34 DCHECK(!defaults_->GetValue(path, NULL)) << |
| 43 "Trying to register a previously registered pref: " << path; | 35 "Trying to register a previously registered pref: " << path; |
| 44 | 36 |
| 45 defaults_->SetDefaultValue(path, default_value); | 37 defaults_->SetDefaultValue(path, default_value); |
| 46 | 38 |
| 47 if (!registration_callback_.is_null()) | 39 if (!registration_callback_.is_null()) |
| 48 registration_callback_.Run(path, default_value); | 40 registration_callback_.Run(path, default_value); |
| 49 } | 41 } |
| OLD | NEW |