OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/prefs/pref_registry.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/prefs/default_pref_store.h" |
| 9 #include "base/prefs/pref_store.h" |
| 10 #include "base/stl_util.h" |
| 11 #include "base/values.h" |
| 12 |
| 13 PrefRegistry::PrefRegistry() |
| 14 : defaults_(new DefaultPrefStore()) { |
| 15 } |
| 16 |
| 17 PrefRegistry::~PrefRegistry() { |
| 18 } |
| 19 |
| 20 uint32_t PrefRegistry::GetRegistrationFlags( |
| 21 const std::string& pref_name) const { |
| 22 const auto& it = registration_flags_.find(pref_name); |
| 23 if (it == registration_flags_.end()) |
| 24 return NO_REGISTRATION_FLAGS; |
| 25 return it->second; |
| 26 } |
| 27 |
| 28 scoped_refptr<PrefStore> PrefRegistry::defaults() { |
| 29 return defaults_.get(); |
| 30 } |
| 31 |
| 32 PrefRegistry::const_iterator PrefRegistry::begin() const { |
| 33 return defaults_->begin(); |
| 34 } |
| 35 |
| 36 PrefRegistry::const_iterator PrefRegistry::end() const { |
| 37 return defaults_->end(); |
| 38 } |
| 39 |
| 40 void PrefRegistry::SetDefaultPrefValue(const std::string& pref_name, |
| 41 base::Value* value) { |
| 42 DCHECK(value); |
| 43 const base::Value* current_value = NULL; |
| 44 DCHECK(defaults_->GetValue(pref_name, ¤t_value)) |
| 45 << "Setting default for unregistered pref: " << pref_name; |
| 46 DCHECK(value->IsType(current_value->GetType())) |
| 47 << "Wrong type for new default: " << pref_name; |
| 48 |
| 49 defaults_->ReplaceDefaultValue(pref_name, make_scoped_ptr(value)); |
| 50 } |
| 51 |
| 52 void PrefRegistry::RegisterPreference(const std::string& path, |
| 53 base::Value* default_value, |
| 54 uint32_t flags) { |
| 55 base::Value::Type orig_type = default_value->GetType(); |
| 56 DCHECK(orig_type != base::Value::TYPE_NULL && |
| 57 orig_type != base::Value::TYPE_BINARY) << |
| 58 "invalid preference type: " << orig_type; |
| 59 DCHECK(!defaults_->GetValue(path, NULL)) << |
| 60 "Trying to register a previously registered pref: " << path; |
| 61 DCHECK(!ContainsKey(registration_flags_, path)) << |
| 62 "Trying to register a previously registered pref: " << path; |
| 63 |
| 64 defaults_->SetDefaultValue(path, make_scoped_ptr(default_value)); |
| 65 if (flags != NO_REGISTRATION_FLAGS) |
| 66 registration_flags_[path] = flags; |
| 67 } |
OLD | NEW |