[email protected] | 32c3c75 | 2012-01-05 17:33:47 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 5 | #include "chrome/browser/prefs/pref_service.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 1cb92b8 | 2010-03-08 23:12:15 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 1cb92b8 | 2010-03-08 23:12:15 | [diff] [blame] | 8 | |
[email protected] | bebe6943 | 2011-09-28 18:36:45 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | c02c853d7 | 2010-08-07 06:23:24 | [diff] [blame] | 10 | #include "base/file_path.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | #include "base/logging.h" |
| 12 | #include "base/message_loop.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 13 | #include "base/metrics/histogram.h" |
[email protected] | 03b9b4e | 2012-10-22 20:01:52 | [diff] [blame] | 14 | #include "base/prefs/default_pref_store.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 15 | #include "base/stl_util.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 16 | #include "base/string_number_conversions.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | #include "base/string_util.h" |
[email protected] | 8703b2b | 2011-03-15 09:51:50 | [diff] [blame] | 18 | #include "base/value_conversions.h" |
[email protected] | 66de4f09 | 2009-09-04 23:59:40 | [diff] [blame] | 19 | #include "build/build_config.h" |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 20 | #include "chrome/browser/prefs/pref_notifier_impl.h" |
[email protected] | 39d9f62c | 2010-12-03 10:48:50 | [diff] [blame] | 21 | #include "chrome/browser/prefs/pref_value_store.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | |
[email protected] | 6bb2d37 | 2012-09-13 20:27:03 | [diff] [blame] | 23 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 24 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | namespace { |
| 26 | |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 27 | class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { |
| 28 | public: |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 29 | ReadErrorHandler(base::Callback<void(PersistentPrefStore::PrefReadError)> cb) |
| 30 | : callback_(cb) {} |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 31 | |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 32 | virtual void OnError(PersistentPrefStore::PrefReadError error) { |
| 33 | callback_.Run(error); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 34 | } |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 35 | |
| 36 | private: |
| 37 | base::Callback<void(PersistentPrefStore::PrefReadError)> callback_; |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 38 | }; |
| 39 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 40 | } // namespace |
| 41 | |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 42 | PrefService::PrefService( |
| 43 | PrefNotifierImpl* pref_notifier, |
| 44 | PrefValueStore* pref_value_store, |
| 45 | PersistentPrefStore* user_prefs, |
| 46 | DefaultPrefStore* default_store, |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 47 | base::Callback<void(PersistentPrefStore::PrefReadError)> |
| 48 | read_error_callback, |
| 49 | bool async) |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 50 | : pref_notifier_(pref_notifier), |
| 51 | pref_value_store_(pref_value_store), |
| 52 | user_pref_store_(user_prefs), |
| 53 | default_store_(default_store), |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 54 | read_error_callback_(read_error_callback) { |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 55 | pref_notifier_->SetPrefService(this); |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 56 | InitFromStorage(async); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 57 | } |
| 58 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 59 | PrefService::~PrefService() { |
| 60 | DCHECK(CalledOnValidThread()); |
[email protected] | a98ce126 | 2011-01-28 13:20:23 | [diff] [blame] | 61 | |
| 62 | // Reset pointers so accesses after destruction reliably crash. |
| 63 | pref_value_store_.reset(); |
| 64 | user_pref_store_ = NULL; |
| 65 | default_store_ = NULL; |
[email protected] | 42f2378 | 2012-06-08 19:11:53 | [diff] [blame] | 66 | pref_notifier_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 67 | } |
| 68 | |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 69 | void PrefService::InitFromStorage(bool async) { |
| 70 | if (!async) { |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 71 | read_error_callback_.Run(user_pref_store_->ReadPrefs()); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 72 | } else { |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 73 | // Guarantee that initialization happens after this function returned. |
| 74 | MessageLoop::current()->PostTask( |
| 75 | FROM_HERE, |
[email protected] | bebe6943 | 2011-09-28 18:36:45 | [diff] [blame] | 76 | base::Bind(&PersistentPrefStore::ReadPrefsAsync, |
| 77 | user_pref_store_.get(), |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 78 | new ReadErrorHandler(read_error_callback_))); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 79 | } |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | bool PrefService::ReloadPersistentPrefs() { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 83 | return user_pref_store_->ReadPrefs() == |
| 84 | PersistentPrefStore::PREF_READ_ERROR_NONE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | 3826fed | 2011-03-25 10:59:56 | [diff] [blame] | 87 | void PrefService::CommitPendingWrite() { |
| 88 | DCHECK(CalledOnValidThread()); |
| 89 | user_pref_store_->CommitPendingWrite(); |
| 90 | } |
| 91 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 92 | bool PrefService::GetBoolean(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | DCHECK(CalledOnValidThread()); |
| 94 | |
| 95 | bool result = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 97 | const base::Value* value = GetPreferenceValue(path); |
| 98 | if (!value) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 99 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | return result; |
| 101 | } |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 102 | bool rv = value->GetAsBoolean(&result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 103 | DCHECK(rv); |
| 104 | return result; |
| 105 | } |
| 106 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 107 | int PrefService::GetInteger(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 108 | DCHECK(CalledOnValidThread()); |
| 109 | |
| 110 | int result = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 111 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 112 | const base::Value* value = GetPreferenceValue(path); |
| 113 | if (!value) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 114 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 115 | return result; |
| 116 | } |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 117 | bool rv = value->GetAsInteger(&result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 118 | DCHECK(rv); |
| 119 | return result; |
| 120 | } |
| 121 | |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 122 | double PrefService::GetDouble(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | DCHECK(CalledOnValidThread()); |
| 124 | |
| 125 | double result = 0.0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 127 | const base::Value* value = GetPreferenceValue(path); |
| 128 | if (!value) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 129 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 130 | return result; |
| 131 | } |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 132 | bool rv = value->GetAsDouble(&result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 133 | DCHECK(rv); |
| 134 | return result; |
| 135 | } |
| 136 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 137 | std::string PrefService::GetString(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 138 | DCHECK(CalledOnValidThread()); |
| 139 | |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 140 | std::string result; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 141 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 142 | const base::Value* value = GetPreferenceValue(path); |
| 143 | if (!value) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 144 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 145 | return result; |
| 146 | } |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 147 | bool rv = value->GetAsString(&result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 148 | DCHECK(rv); |
| 149 | return result; |
| 150 | } |
| 151 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 152 | FilePath PrefService::GetFilePath(const char* path) const { |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 153 | DCHECK(CalledOnValidThread()); |
| 154 | |
[email protected] | 68d9d35 | 2011-02-21 16:35:04 | [diff] [blame] | 155 | FilePath result; |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 156 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 157 | const base::Value* value = GetPreferenceValue(path); |
| 158 | if (!value) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 159 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 160 | return FilePath(result); |
| 161 | } |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 162 | bool rv = base::GetValueAsFilePath(*value, &result); |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 163 | DCHECK(rv); |
[email protected] | 68d9d35 | 2011-02-21 16:35:04 | [diff] [blame] | 164 | return result; |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 167 | bool PrefService::HasPrefPath(const char* path) const { |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 168 | const Preference* pref = FindPreference(path); |
| 169 | return pref && !pref->IsDefaultValue(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | ebd0b02 | 2011-01-27 13:24:14 | [diff] [blame] | 172 | DictionaryValue* PrefService::GetPreferenceValues() const { |
| 173 | DCHECK(CalledOnValidThread()); |
| 174 | DictionaryValue* out = new DictionaryValue; |
| 175 | DefaultPrefStore::const_iterator i = default_store_->begin(); |
| 176 | for (; i != default_store_->end(); ++i) { |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 177 | const Value* value = GetPreferenceValue(i->first); |
[email protected] | 8874e0217 | 2011-03-11 19:44:08 | [diff] [blame] | 178 | DCHECK(value); |
[email protected] | ebd0b02 | 2011-01-27 13:24:14 | [diff] [blame] | 179 | out->Set(i->first, value->DeepCopy()); |
| 180 | } |
| 181 | return out; |
| 182 | } |
| 183 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 184 | const PrefService::Preference* PrefService::FindPreference( |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 185 | const char* pref_name) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 186 | DCHECK(CalledOnValidThread()); |
[email protected] | d15d568 | 2012-10-23 17:50:42 | [diff] [blame] | 187 | PreferenceMap::iterator it = prefs_map_.find(pref_name); |
| 188 | if (it != prefs_map_.end()) |
| 189 | return &(it->second); |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 190 | const base::Value::Type type = default_store_->GetType(pref_name); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 191 | if (type == Value::TYPE_NULL) |
| 192 | return NULL; |
[email protected] | d15d568 | 2012-10-23 17:50:42 | [diff] [blame] | 193 | it = prefs_map_.insert( |
| 194 | std::make_pair(pref_name, Preference(this, pref_name, type))).first; |
| 195 | return &(it->second); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 198 | bool PrefService::ReadOnly() const { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 199 | return user_pref_store_->ReadOnly(); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 200 | } |
| 201 | |
[email protected] | 59c1071 | 2012-03-13 02:10:34 | [diff] [blame] | 202 | PrefService::PrefInitializationStatus PrefService::GetInitializationStatus() |
| 203 | const { |
| 204 | if (!user_pref_store_->IsInitializationComplete()) |
| 205 | return INITIALIZATION_STATUS_WAITING; |
| 206 | |
| 207 | switch (user_pref_store_->GetReadError()) { |
| 208 | case PersistentPrefStore::PREF_READ_ERROR_NONE: |
| 209 | return INITIALIZATION_STATUS_SUCCESS; |
| 210 | case PersistentPrefStore::PREF_READ_ERROR_NO_FILE: |
| 211 | return INITIALIZATION_STATUS_CREATED_NEW_PROFILE; |
| 212 | default: |
| 213 | return INITIALIZATION_STATUS_ERROR; |
| 214 | } |
| 215 | } |
| 216 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 217 | bool PrefService::IsManagedPreference(const char* pref_name) const { |
[email protected] | d90de1c0 | 2010-07-19 19:50:48 | [diff] [blame] | 218 | const Preference* pref = FindPreference(pref_name); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 219 | return pref && pref->IsManaged(); |
[email protected] | d90de1c0 | 2010-07-19 19:50:48 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | d6bbd293 | 2012-03-19 17:10:07 | [diff] [blame] | 222 | bool PrefService::IsUserModifiablePreference(const char* pref_name) const { |
| 223 | const Preference* pref = FindPreference(pref_name); |
| 224 | return pref && pref->IsUserModifiable(); |
| 225 | } |
| 226 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 227 | const DictionaryValue* PrefService::GetDictionary(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 228 | DCHECK(CalledOnValidThread()); |
| 229 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 230 | const Value* value = GetPreferenceValue(path); |
| 231 | if (!value) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 232 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 233 | return NULL; |
| 234 | } |
[email protected] | 11b040b | 2011-02-02 12:42:25 | [diff] [blame] | 235 | if (value->GetType() != Value::TYPE_DICTIONARY) { |
| 236 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | return NULL; |
[email protected] | 11b040b | 2011-02-02 12:42:25 | [diff] [blame] | 238 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 239 | return static_cast<const DictionaryValue*>(value); |
| 240 | } |
| 241 | |
[email protected] | 1a5a31f | 2012-04-26 20:21:34 | [diff] [blame] | 242 | const base::Value* PrefService::GetUserPrefValue(const char* path) const { |
| 243 | DCHECK(CalledOnValidThread()); |
| 244 | |
| 245 | const Preference* pref = FindPreference(path); |
| 246 | if (!pref) { |
| 247 | NOTREACHED() << "Trying to get an unregistered pref: " << path; |
| 248 | return NULL; |
| 249 | } |
| 250 | |
| 251 | // Look for an existing preference in the user store. If it doesn't |
| 252 | // exist, return NULL. |
| 253 | base::Value* value = NULL; |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 254 | if (!user_pref_store_->GetMutableValue(path, &value)) |
[email protected] | 1a5a31f | 2012-04-26 20:21:34 | [diff] [blame] | 255 | return NULL; |
[email protected] | 1a5a31f | 2012-04-26 20:21:34 | [diff] [blame] | 256 | |
| 257 | if (!value->IsType(pref->GetType())) { |
| 258 | NOTREACHED() << "Pref value type doesn't match registered type."; |
| 259 | return NULL; |
| 260 | } |
| 261 | |
| 262 | return value; |
| 263 | } |
| 264 | |
[email protected] | 35a6fd1 | 2012-05-28 18:08:08 | [diff] [blame] | 265 | const base::Value* PrefService::GetDefaultPrefValue(const char* path) const { |
| 266 | DCHECK(CalledOnValidThread()); |
| 267 | // Lookup the preference in the default store. |
| 268 | const base::Value* value = NULL; |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 269 | if (!default_store_->GetValue(path, &value)) { |
[email protected] | 35a6fd1 | 2012-05-28 18:08:08 | [diff] [blame] | 270 | NOTREACHED() << "Default value missing for pref: " << path; |
| 271 | return NULL; |
| 272 | } |
| 273 | return value; |
| 274 | } |
| 275 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 276 | const ListValue* PrefService::GetList(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 277 | DCHECK(CalledOnValidThread()); |
| 278 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 279 | const Value* value = GetPreferenceValue(path); |
| 280 | if (!value) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 281 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 282 | return NULL; |
| 283 | } |
[email protected] | 11b040b | 2011-02-02 12:42:25 | [diff] [blame] | 284 | if (value->GetType() != Value::TYPE_LIST) { |
| 285 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | return NULL; |
[email protected] | 11b040b | 2011-02-02 12:42:25 | [diff] [blame] | 287 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 288 | return static_cast<const ListValue*>(value); |
| 289 | } |
| 290 | |
[email protected] | a6a7ced | 2012-11-01 17:24:18 | [diff] [blame] | 291 | void PrefService::AddPrefObserver(const char* path, PrefObserver* obs) { |
[email protected] | d81288a0 | 2010-08-18 07:25:50 | [diff] [blame] | 292 | pref_notifier_->AddPrefObserver(path, obs); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | a6a7ced | 2012-11-01 17:24:18 | [diff] [blame] | 295 | void PrefService::RemovePrefObserver(const char* path, PrefObserver* obs) { |
[email protected] | d81288a0 | 2010-08-18 07:25:50 | [diff] [blame] | 296 | pref_notifier_->RemovePrefObserver(path, obs); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 297 | } |
| 298 | |
[email protected] | a6a7ced | 2012-11-01 17:24:18 | [diff] [blame] | 299 | void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) { |
| 300 | pref_notifier_->AddInitObserver(obs); |
| 301 | } |
| 302 | |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 303 | void PrefService::RegisterPreference(const char* path, |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 304 | Value* default_value) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 305 | DCHECK(CalledOnValidThread()); |
| 306 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 307 | // The main code path takes ownership, but most don't. We'll be safe. |
| 308 | scoped_ptr<Value> scoped_value(default_value); |
| 309 | |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 310 | CHECK(!FindPreference(path)) << "Tried to register duplicate pref " << path; |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 311 | |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 312 | base::Value::Type orig_type = default_value->GetType(); |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 313 | DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << |
| 314 | "invalid preference type: " << orig_type; |
| 315 | |
[email protected] | ea3e497 | 2012-04-12 03:41:37 | [diff] [blame] | 316 | // For ListValue and DictionaryValue with non empty default, empty value |
| 317 | // for |path| needs to be persisted in |user_pref_store_|. So that |
| 318 | // non empty default is not used when user sets an empty ListValue or |
| 319 | // DictionaryValue. |
| 320 | bool needs_empty_value = false; |
| 321 | if (orig_type == base::Value::TYPE_LIST) { |
| 322 | const base::ListValue* list = NULL; |
| 323 | if (default_value->GetAsList(&list) && !list->empty()) |
| 324 | needs_empty_value = true; |
| 325 | } else if (orig_type == base::Value::TYPE_DICTIONARY) { |
| 326 | const base::DictionaryValue* dict = NULL; |
| 327 | if (default_value->GetAsDictionary(&dict) && !dict->empty()) |
| 328 | needs_empty_value = true; |
| 329 | } |
| 330 | if (needs_empty_value) |
| 331 | user_pref_store_->MarkNeedsEmptyValue(path); |
| 332 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 333 | // Hand off ownership. |
| 334 | default_store_->SetDefaultValue(path, scoped_value.release()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 335 | } |
| 336 | |
[email protected] | 7a5f593 | 2011-12-29 10:35:49 | [diff] [blame] | 337 | void PrefService::UnregisterPreference(const char* path) { |
| 338 | DCHECK(CalledOnValidThread()); |
| 339 | |
[email protected] | d15d568 | 2012-10-23 17:50:42 | [diff] [blame] | 340 | PreferenceMap::iterator it = prefs_map_.find(path); |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 341 | CHECK(it != prefs_map_.end()) << "Trying to unregister an unregistered pref: " |
| 342 | << path; |
[email protected] | 7a5f593 | 2011-12-29 10:35:49 | [diff] [blame] | 343 | |
[email protected] | d15d568 | 2012-10-23 17:50:42 | [diff] [blame] | 344 | prefs_map_.erase(it); |
[email protected] | 7a5f593 | 2011-12-29 10:35:49 | [diff] [blame] | 345 | default_store_->RemoveDefaultValue(path); |
[email protected] | 7a5f593 | 2011-12-29 10:35:49 | [diff] [blame] | 346 | } |
| 347 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 348 | void PrefService::ClearPref(const char* path) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 349 | DCHECK(CalledOnValidThread()); |
| 350 | |
| 351 | const Preference* pref = FindPreference(path); |
| 352 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 353 | NOTREACHED() << "Trying to clear an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 354 | return; |
| 355 | } |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 356 | user_pref_store_->RemoveValue(path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 357 | } |
| 358 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 359 | void PrefService::Set(const char* path, const Value& value) { |
[email protected] | b99c41c | 2011-04-27 15:18:48 | [diff] [blame] | 360 | SetUserPrefValue(path, value.DeepCopy()); |
[email protected] | a048d7e4 | 2009-12-01 01:02:39 | [diff] [blame] | 361 | } |
| 362 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 363 | void PrefService::SetBoolean(const char* path, bool value) { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 364 | SetUserPrefValue(path, Value::CreateBooleanValue(value)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | } |
| 366 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 367 | void PrefService::SetInteger(const char* path, int value) { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 368 | SetUserPrefValue(path, Value::CreateIntegerValue(value)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 369 | } |
| 370 | |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 371 | void PrefService::SetDouble(const char* path, double value) { |
| 372 | SetUserPrefValue(path, Value::CreateDoubleValue(value)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 373 | } |
| 374 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 375 | void PrefService::SetString(const char* path, const std::string& value) { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 376 | SetUserPrefValue(path, Value::CreateStringValue(value)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 377 | } |
| 378 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 379 | void PrefService::SetFilePath(const char* path, const FilePath& value) { |
[email protected] | 8703b2b | 2011-03-15 09:51:50 | [diff] [blame] | 380 | SetUserPrefValue(path, base::CreateFilePathValue(value)); |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 381 | } |
| 382 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 383 | void PrefService::SetInt64(const char* path, int64 value) { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 384 | SetUserPrefValue(path, Value::CreateStringValue(base::Int64ToString(value))); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 385 | } |
| 386 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 387 | int64 PrefService::GetInt64(const char* path) const { |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 388 | DCHECK(CalledOnValidThread()); |
| 389 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 390 | const Value* value = GetPreferenceValue(path); |
| 391 | if (!value) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 392 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
[email protected] | c345330 | 2009-12-01 01:33:08 | [diff] [blame] | 393 | return 0; |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 394 | } |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 395 | std::string result("0"); |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 396 | bool rv = value->GetAsString(&result); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 397 | DCHECK(rv); |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 398 | |
| 399 | int64 val; |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 400 | base::StringToInt64(result, &val); |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 401 | return val; |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 402 | } |
| 403 | |
[email protected] | 3cbe081 | 2012-07-03 02:51:43 | [diff] [blame] | 404 | void PrefService::SetUint64(const char* path, uint64 value) { |
| 405 | SetUserPrefValue(path, Value::CreateStringValue(base::Uint64ToString(value))); |
| 406 | } |
| 407 | |
| 408 | uint64 PrefService::GetUint64(const char* path) const { |
| 409 | DCHECK(CalledOnValidThread()); |
| 410 | |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 411 | const Value* value = GetPreferenceValue(path); |
| 412 | if (!value) { |
[email protected] | 3cbe081 | 2012-07-03 02:51:43 | [diff] [blame] | 413 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
| 414 | return 0; |
| 415 | } |
| 416 | std::string result("0"); |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 417 | bool rv = value->GetAsString(&result); |
[email protected] | 3cbe081 | 2012-07-03 02:51:43 | [diff] [blame] | 418 | DCHECK(rv); |
| 419 | |
| 420 | uint64 val; |
| 421 | base::StringToUint64(result, &val); |
| 422 | return val; |
| 423 | } |
| 424 | |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 425 | Value* PrefService::GetMutableUserPref(const char* path, |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 426 | base::Value::Type type) { |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 427 | CHECK(type == Value::TYPE_DICTIONARY || type == Value::TYPE_LIST); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 428 | DCHECK(CalledOnValidThread()); |
| 429 | |
| 430 | const Preference* pref = FindPreference(path); |
| 431 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 432 | NOTREACHED() << "Trying to get an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 433 | return NULL; |
| 434 | } |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 435 | if (pref->GetType() != type) { |
| 436 | NOTREACHED() << "Wrong type for GetMutableValue: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 437 | return NULL; |
| 438 | } |
| 439 | |
[email protected] | e025089 | 2010-10-01 18:57:53 | [diff] [blame] | 440 | // Look for an existing preference in the user store. If it doesn't |
| 441 | // exist or isn't the correct type, create a new user preference. |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 442 | Value* value = NULL; |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 443 | if (!user_pref_store_->GetMutableValue(path, &value) || |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 444 | !value->IsType(type)) { |
| 445 | if (type == Value::TYPE_DICTIONARY) { |
| 446 | value = new DictionaryValue; |
| 447 | } else if (type == Value::TYPE_LIST) { |
| 448 | value = new ListValue; |
| 449 | } else { |
| 450 | NOTREACHED(); |
| 451 | } |
| 452 | user_pref_store_->SetValueSilently(path, value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 453 | } |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 454 | return value; |
| 455 | } |
| 456 | |
[email protected] | 68bf41a | 2011-03-25 16:38:31 | [diff] [blame] | 457 | void PrefService::ReportUserPrefChanged(const std::string& key) { |
[email protected] | f89ee34 | 2011-03-07 09:28:27 | [diff] [blame] | 458 | user_pref_store_->ReportValueChanged(key); |
| 459 | } |
| 460 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 461 | void PrefService::SetUserPrefValue(const char* path, Value* new_value) { |
[email protected] | b99c41c | 2011-04-27 15:18:48 | [diff] [blame] | 462 | scoped_ptr<Value> owned_value(new_value); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 463 | DCHECK(CalledOnValidThread()); |
| 464 | |
| 465 | const Preference* pref = FindPreference(path); |
| 466 | if (!pref) { |
| 467 | NOTREACHED() << "Trying to write an unregistered pref: " << path; |
| 468 | return; |
| 469 | } |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 470 | if (pref->GetType() != new_value->GetType()) { |
| 471 | NOTREACHED() << "Trying to set pref " << path |
| 472 | << " of type " << pref->GetType() |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 473 | << " to value of type " << new_value->GetType(); |
| 474 | return; |
| 475 | } |
| 476 | |
[email protected] | b99c41c | 2011-04-27 15:18:48 | [diff] [blame] | 477 | user_pref_store_->SetValue(path, owned_value.release()); |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 478 | } |
| 479 | |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 480 | void PrefService::UpdateCommandLinePrefStore(PrefStore* command_line_store) { |
| 481 | pref_value_store_->UpdateCommandLinePrefStore(command_line_store); |
[email protected] | d3b05ea | 2012-01-24 22:57:05 | [diff] [blame] | 482 | } |
| 483 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 484 | /////////////////////////////////////////////////////////////////////////////// |
| 485 | // PrefService::Preference |
| 486 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 487 | PrefService::Preference::Preference(const PrefService* service, |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 488 | const char* name, |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 489 | base::Value::Type type) |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 490 | : name_(name), |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 491 | type_(type), |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 492 | pref_service_(service) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 493 | DCHECK(name); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 494 | DCHECK(service); |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 495 | } |
| 496 | |
[email protected] | fb8fdf1 | 2012-08-21 16:28:20 | [diff] [blame] | 497 | const std::string PrefService::Preference::name() const { |
| 498 | return name_; |
| 499 | } |
| 500 | |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 501 | base::Value::Type PrefService::Preference::GetType() const { |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 502 | return type_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | const Value* PrefService::Preference::GetValue() const { |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 506 | const Value* result= pref_service_->GetPreferenceValue(name_); |
| 507 | DCHECK(result) << "Must register pref before getting its value"; |
| 508 | return result; |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 509 | } |
| 510 | |
[email protected] | 7ca0f36 | 2012-07-30 10:14:03 | [diff] [blame] | 511 | const Value* PrefService::Preference::GetRecommendedValue() const { |
| 512 | DCHECK(pref_service_->FindPreference(name_.c_str())) << |
| 513 | "Must register pref before getting its value"; |
| 514 | |
| 515 | const Value* found_value = NULL; |
| 516 | if (pref_value_store()->GetRecommendedValue(name_, type_, &found_value)) { |
| 517 | DCHECK(found_value->IsType(type_)); |
| 518 | return found_value; |
| 519 | } |
| 520 | |
| 521 | // The pref has no recommended value. |
| 522 | return NULL; |
| 523 | } |
| 524 | |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 525 | bool PrefService::Preference::IsManaged() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 526 | return pref_value_store()->PrefValueInManagedStore(name_.c_str()); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 527 | } |
| 528 | |
[email protected] | a543728 | 2011-12-12 12:33:21 | [diff] [blame] | 529 | bool PrefService::Preference::IsRecommended() const { |
| 530 | return pref_value_store()->PrefValueFromRecommendedStore(name_.c_str()); |
| 531 | } |
| 532 | |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 533 | bool PrefService::Preference::HasExtensionSetting() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 534 | return pref_value_store()->PrefValueInExtensionStore(name_.c_str()); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | bool PrefService::Preference::HasUserSetting() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 538 | return pref_value_store()->PrefValueInUserStore(name_.c_str()); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | bool PrefService::Preference::IsExtensionControlled() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 542 | return pref_value_store()->PrefValueFromExtensionStore(name_.c_str()); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | bool PrefService::Preference::IsUserControlled() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 546 | return pref_value_store()->PrefValueFromUserStore(name_.c_str()); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | bool PrefService::Preference::IsDefaultValue() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 550 | return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
[email protected] | d7449e8 | 2010-07-14 11:42:35 | [diff] [blame] | 551 | } |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 552 | |
| 553 | bool PrefService::Preference::IsUserModifiable() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 554 | return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 555 | } |
[email protected] | 9a28f13 | 2011-02-24 21:15:16 | [diff] [blame] | 556 | |
| 557 | bool PrefService::Preference::IsExtensionModifiable() const { |
| 558 | return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 559 | } |
[email protected] | 18038f8 | 2012-11-20 13:46:58 | [diff] [blame] | 560 | |
| 561 | const base::Value* PrefService::GetPreferenceValue( |
| 562 | const std::string& path) const { |
| 563 | DCHECK(CalledOnValidThread()); |
| 564 | const base::Value::Type type = default_store_->GetType(path); |
| 565 | if (type == Value::TYPE_NULL) |
| 566 | return NULL; |
| 567 | const Value* found_value = NULL; |
| 568 | if (pref_value_store_->GetValue(path, type, &found_value)) { |
| 569 | DCHECK(found_value->IsType(type)); |
| 570 | return found_value; |
| 571 | } |
| 572 | |
| 573 | // Every registered preference has at least a default value. |
| 574 | NOTREACHED() << "no valid value found for registered pref " << path; |
| 575 | return NULL; |
| 576 | } |