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

Side by Side Diff: chrome/browser/prefs/pref_service.cc

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years 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 4
5 #include "chrome/browser/prefs/pref_service.h" 5 #include "chrome/browser/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/command_line.h"
11 #include "base/file_path.h" 10 #include "base/file_path.h"
12 #include "base/logging.h" 11 #include "base/logging.h"
13 #include "base/message_loop.h" 12 #include "base/message_loop.h"
14 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
15 #include "base/prefs/default_pref_store.h" 14 #include "base/prefs/default_pref_store.h"
16 #include "base/prefs/overlay_user_pref_store.h"
17 #include "base/stl_util.h" 15 #include "base/stl_util.h"
18 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
19 #include "base/string_util.h" 17 #include "base/string_util.h"
20 #include "base/value_conversions.h" 18 #include "base/value_conversions.h"
21 #include "build/build_config.h" 19 #include "build/build_config.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/prefs/command_line_pref_store.h"
24 #include "chrome/browser/prefs/pref_model_associator.h"
25 #include "chrome/browser/prefs/pref_notifier_impl.h" 20 #include "chrome/browser/prefs/pref_notifier_impl.h"
26 #include "chrome/browser/prefs/pref_service_observer.h"
27 #include "chrome/browser/prefs/pref_value_store.h" 21 #include "chrome/browser/prefs/pref_value_store.h"
28 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
29 #include "ui/base/l10n/l10n_util.h"
30 22
31 using content::BrowserContext; 23 using content::BrowserContext;
32 24
33 namespace { 25 namespace {
34 26
35 // A helper function for RegisterLocalized*Pref that creates a Value* based on
36 // the string value in the locale dll. Because we control the values in a
37 // locale dll, this should always return a Value of the appropriate type.
38 Value* CreateLocaleDefaultValue(base::Value::Type type, int message_id) {
39 std::string resource_string = l10n_util::GetStringUTF8(message_id);
40 DCHECK(!resource_string.empty());
41 switch (type) {
42 case Value::TYPE_BOOLEAN: {
43 if ("true" == resource_string)
44 return Value::CreateBooleanValue(true);
45 if ("false" == resource_string)
46 return Value::CreateBooleanValue(false);
47 break;
48 }
49
50 case Value::TYPE_INTEGER: {
51 int val;
52 base::StringToInt(resource_string, &val);
53 return Value::CreateIntegerValue(val);
54 }
55
56 case Value::TYPE_DOUBLE: {
57 double val;
58 base::StringToDouble(resource_string, &val);
59 return Value::CreateDoubleValue(val);
60 }
61
62 case Value::TYPE_STRING: {
63 return Value::CreateStringValue(resource_string);
64 }
65
66 default: {
67 NOTREACHED() <<
68 "list and dictionary types cannot have default locale values";
69 }
70 }
71 NOTREACHED();
72 return Value::CreateNullValue();
73 }
74
75 // TODO(joi): Change the interface on PersistentPrefStore to just take
76 // a callback of this type. Then we can also typedef the callback in
77 // PersistentPrefStore and use that as the type of the callback used
78 // to initialize PrefService.
79 class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { 27 class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate {
80 public: 28 public:
81 ReadErrorHandler(base::Callback<void(PersistentPrefStore::PrefReadError)> cb) 29 ReadErrorHandler(base::Callback<void(PersistentPrefStore::PrefReadError)> cb)
82 : callback_(cb) {} 30 : callback_(cb) {}
83 31
84 virtual void OnError(PersistentPrefStore::PrefReadError error) { 32 virtual void OnError(PersistentPrefStore::PrefReadError error) {
85 callback_.Run(error); 33 callback_.Run(error);
86 } 34 }
87 35
88 private: 36 private:
89 base::Callback<void(PersistentPrefStore::PrefReadError)> callback_; 37 base::Callback<void(PersistentPrefStore::PrefReadError)> callback_;
90 }; 38 };
91 39
92 } // namespace 40 } // namespace
93 41
94 PrefService* PrefService::CreateIncognitoPrefService(
95 PrefStore* incognito_extension_prefs) {
96 pref_service_forked_ = true;
97 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
98 OverlayUserPrefStore* incognito_pref_store =
99 new OverlayUserPrefStore(user_pref_store_.get());
100 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store);
101 return new PrefService(
102 pref_notifier,
103 pref_value_store_->CloneAndSpecialize(
104 NULL, // managed
105 incognito_extension_prefs,
106 NULL, // command_line_prefs
107 incognito_pref_store,
108 NULL, // recommended
109 default_store_.get(),
110 NULL, // pref_sync_associator
111 pref_notifier),
112 incognito_pref_store,
113 default_store_.get(),
114 NULL,
115 read_error_callback_,
116 false);
117 }
118
119 PrefService::PrefService(
120 PrefNotifierImpl* pref_notifier,
121 PrefValueStore* pref_value_store,
122 PersistentPrefStore* user_prefs,
123 DefaultPrefStore* default_store,
124 PrefModelAssociator* pref_sync_associator,
125 base::Callback<void(PersistentPrefStore::PrefReadError)>
126 read_error_callback,
127 bool async)
128 : pref_notifier_(pref_notifier),
129 pref_value_store_(pref_value_store),
130 user_pref_store_(user_prefs),
131 default_store_(default_store),
132 pref_sync_associator_(pref_sync_associator),
133 read_error_callback_(read_error_callback),
134 pref_service_forked_(false) {
135 pref_notifier_->SetPrefService(this);
136 if (pref_sync_associator_.get())
137 pref_sync_associator_->SetPrefService(this);
138 InitFromStorage(async);
139 }
140
141 PrefService::~PrefService() { 42 PrefService::~PrefService() {
142 DCHECK(CalledOnValidThread()); 43 DCHECK(CalledOnValidThread());
143 44
144 // Reset pointers so accesses after destruction reliably crash. 45 // Reset pointers so accesses after destruction reliably crash.
145 pref_value_store_.reset(); 46 pref_value_store_.reset();
146 user_pref_store_ = NULL; 47 user_pref_store_ = NULL;
147 default_store_ = NULL; 48 default_store_ = NULL;
148 pref_sync_associator_.reset();
149 pref_notifier_.reset(); 49 pref_notifier_.reset();
150 } 50 }
151 51
152 void PrefService::InitFromStorage(bool async) { 52 void PrefService::InitFromStorage(bool async) {
153 if (!async) { 53 if (!async) {
154 read_error_callback_.Run(user_pref_store_->ReadPrefs()); 54 read_error_callback_.Run(user_pref_store_->ReadPrefs());
155 } else { 55 } else {
156 // Guarantee that initialization happens after this function returned. 56 // Guarantee that initialization happens after this function returned.
157 MessageLoop::current()->PostTask( 57 MessageLoop::current()->PostTask(
158 FROM_HERE, 58 FROM_HERE,
159 base::Bind(&PersistentPrefStore::ReadPrefsAsync, 59 base::Bind(&PersistentPrefStore::ReadPrefsAsync,
160 user_pref_store_.get(), 60 user_pref_store_.get(),
161 new ReadErrorHandler(read_error_callback_))); 61 new ReadErrorHandler(read_error_callback_)));
162 } 62 }
163 } 63 }
164 64
165 bool PrefService::ReloadPersistentPrefs() { 65 bool PrefService::ReloadPersistentPrefs() {
166 return user_pref_store_->ReadPrefs() == 66 return user_pref_store_->ReadPrefs() ==
167 PersistentPrefStore::PREF_READ_ERROR_NONE; 67 PersistentPrefStore::PREF_READ_ERROR_NONE;
168 } 68 }
169 69
170 void PrefService::CommitPendingWrite() { 70 void PrefService::CommitPendingWrite() {
171 DCHECK(CalledOnValidThread()); 71 DCHECK(CalledOnValidThread());
172 user_pref_store_->CommitPendingWrite(); 72 user_pref_store_->CommitPendingWrite();
173 } 73 }
174 74
175 void PrefService::AddObserver(PrefServiceObserver* observer) {
176 observer_list_.AddObserver(observer);
177 }
178
179 void PrefService::RemoveObserver(PrefServiceObserver* observer) {
180 observer_list_.RemoveObserver(observer);
181 }
182
183 bool PrefService::IsSyncing() {
184 return pref_sync_associator_.get() &&
185 pref_sync_associator_->models_associated();
186 }
187
188 void PrefService::OnIsSyncingChanged() {
189 FOR_EACH_OBSERVER(PrefServiceObserver, observer_list_, OnIsSyncingChanged());
190 }
191
192 namespace {
193
194 // If there's no g_browser_process or no local state, return true (for testing).
195 bool IsLocalStatePrefService(PrefService* prefs) {
196 return (!g_browser_process ||
197 !g_browser_process->local_state() ||
198 g_browser_process->local_state() == prefs);
199 }
200
201 // If there's no g_browser_process, return true (for testing).
202 bool IsProfilePrefService(PrefService* prefs) {
203 // TODO(zea): uncomment this once all preferences are only ever registered
204 // with either the local_state's pref service or the profile's pref service.
205 // return (!g_browser_process || g_browser_process->local_state() != prefs);
206 return true;
207 }
208
209 } // namespace
210
211 // Local State prefs.
212 void PrefService::RegisterBooleanPref(const char* path,
213 bool default_value) {
214 // If this fails, the pref service in use is a profile pref service, so the
215 // sync status must be provided (see profile pref registration calls below).
216 DCHECK(IsLocalStatePrefService(this));
217 RegisterPreference(path,
218 Value::CreateBooleanValue(default_value),
219 UNSYNCABLE_PREF);
220 }
221
222 void PrefService::RegisterIntegerPref(const char* path, int default_value) {
223 // If this fails, the pref service in use is a profile pref service, so the
224 // sync status must be provided (see profile pref registration calls below).
225 DCHECK(IsLocalStatePrefService(this));
226 RegisterPreference(path,
227 Value::CreateIntegerValue(default_value),
228 UNSYNCABLE_PREF);
229 }
230
231 void PrefService::RegisterDoublePref(const char* path, double default_value) {
232 // If this fails, the pref service in use is a profile pref service, so the
233 // sync status must be provided (see profile pref registration calls below).
234 DCHECK(IsLocalStatePrefService(this));
235 RegisterPreference(path,
236 Value::CreateDoubleValue(default_value),
237 UNSYNCABLE_PREF);
238 }
239
240 void PrefService::RegisterStringPref(const char* path,
241 const std::string& default_value) {
242 // If this fails, the pref service in use is a profile pref service, so the
243 // sync status must be provided (see profile pref registration calls below).
244 DCHECK(IsLocalStatePrefService(this));
245 RegisterPreference(path,
246 Value::CreateStringValue(default_value),
247 UNSYNCABLE_PREF);
248 }
249
250 void PrefService::RegisterFilePathPref(const char* path,
251 const FilePath& default_value) {
252 // If this fails, the pref service in use is a profile pref service, so the
253 // sync status must be provided (see profile pref registration calls below).
254 DCHECK(IsLocalStatePrefService(this));
255 RegisterPreference(path,
256 Value::CreateStringValue(default_value.value()),
257 UNSYNCABLE_PREF);
258 }
259
260 void PrefService::RegisterListPref(const char* path) {
261 // If this fails, the pref service in use is a profile pref service, so the
262 // sync status must be provided (see profile pref registration calls below).
263 DCHECK(IsLocalStatePrefService(this));
264 RegisterPreference(path,
265 new ListValue(),
266 UNSYNCABLE_PREF);
267 }
268
269 void PrefService::RegisterListPref(const char* path, ListValue* default_value) {
270 // If this fails, the pref service in use is a profile pref service, so the
271 // sync status must be provided (see profile pref registration calls below).
272 DCHECK(IsLocalStatePrefService(this));
273 RegisterPreference(path,
274 default_value,
275 UNSYNCABLE_PREF);
276 }
277
278 void PrefService::RegisterDictionaryPref(const char* path) {
279 // If this fails, the pref service in use is a profile pref service, so the
280 // sync status must be provided (see profile pref registration calls below).
281 DCHECK(IsLocalStatePrefService(this));
282 RegisterPreference(path,
283 new DictionaryValue(),
284 UNSYNCABLE_PREF);
285 }
286
287 void PrefService::RegisterDictionaryPref(const char* path,
288 DictionaryValue* default_value) {
289 // If this fails, the pref service in use is a profile pref service, so the
290 // sync status must be provided (see profile pref registration calls below).
291 DCHECK(IsLocalStatePrefService(this));
292 RegisterPreference(path,
293 default_value,
294 UNSYNCABLE_PREF);
295 }
296
297 void PrefService::RegisterLocalizedBooleanPref(const char* path,
298 int locale_default_message_id) {
299 // If this fails, the pref service in use is a profile pref service, so the
300 // sync status must be provided (see profile pref registration calls below).
301 DCHECK(IsLocalStatePrefService(this));
302 RegisterPreference(
303 path,
304 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id),
305 UNSYNCABLE_PREF);
306 }
307
308 void PrefService::RegisterLocalizedIntegerPref(const char* path,
309 int locale_default_message_id) {
310 // If this fails, the pref service in use is a profile pref service, so the
311 // sync status must be provided (see profile pref registration calls below).
312 DCHECK(IsLocalStatePrefService(this));
313 RegisterPreference(
314 path,
315 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id),
316 UNSYNCABLE_PREF);
317 }
318
319 void PrefService::RegisterLocalizedDoublePref(const char* path,
320 int locale_default_message_id) {
321 // If this fails, the pref service in use is a profile pref service, so the
322 // sync status must be provided (see profile pref registration calls below).
323 DCHECK(IsLocalStatePrefService(this));
324 RegisterPreference(
325 path,
326 CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id),
327 UNSYNCABLE_PREF);
328 }
329
330 void PrefService::RegisterLocalizedStringPref(const char* path,
331 int locale_default_message_id) {
332 // If this fails, the pref service in use is a profile pref service, so the
333 // sync status must be provided (see profile pref registration calls below).
334 DCHECK(IsLocalStatePrefService(this));
335 RegisterPreference(
336 path,
337 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id),
338 UNSYNCABLE_PREF);
339 }
340
341 void PrefService::RegisterInt64Pref(const char* path, int64 default_value) {
342 // If this fails, the pref service in use is a profile pref service, so the
343 // sync status must be provided (see profile pref registration calls below).
344 DCHECK(IsLocalStatePrefService(this));
345 RegisterPreference(
346 path,
347 Value::CreateStringValue(base::Int64ToString(default_value)),
348 UNSYNCABLE_PREF);
349 }
350
351 // Profile prefs (must use the sync_status variable).
352 void PrefService::RegisterBooleanPref(const char* path,
353 bool default_value,
354 PrefSyncStatus sync_status) {
355 DCHECK(IsProfilePrefService(this));
356 RegisterPreference(path,
357 Value::CreateBooleanValue(default_value),
358 sync_status);
359 }
360
361 void PrefService::RegisterIntegerPref(const char* path,
362 int default_value,
363 PrefSyncStatus sync_status) {
364 DCHECK(IsProfilePrefService(this));
365 RegisterPreference(path,
366 Value::CreateIntegerValue(default_value),
367 sync_status);
368 }
369
370 void PrefService::RegisterDoublePref(const char* path,
371 double default_value,
372 PrefSyncStatus sync_status) {
373 DCHECK(IsProfilePrefService(this));
374 RegisterPreference(path,
375 Value::CreateDoubleValue(default_value),
376 sync_status);
377 }
378
379 void PrefService::RegisterStringPref(const char* path,
380 const std::string& default_value,
381 PrefSyncStatus sync_status) {
382 DCHECK(IsProfilePrefService(this));
383 RegisterPreference(path,
384 Value::CreateStringValue(default_value),
385 sync_status);
386 }
387
388 void PrefService::RegisterFilePathPref(const char* path,
389 const FilePath& default_value,
390 PrefSyncStatus sync_status) {
391 DCHECK(IsProfilePrefService(this));
392 RegisterPreference(path,
393 Value::CreateStringValue(default_value.value()),
394 sync_status);
395 }
396
397 void PrefService::RegisterListPref(const char* path,
398 PrefSyncStatus sync_status) {
399 DCHECK(IsProfilePrefService(this));
400 RegisterPreference(path, new ListValue(), sync_status);
401 }
402
403 void PrefService::RegisterListPref(const char* path,
404 ListValue* default_value,
405 PrefSyncStatus sync_status) {
406 DCHECK(IsProfilePrefService(this));
407 RegisterPreference(path, default_value, sync_status);
408 }
409
410 void PrefService::RegisterDictionaryPref(const char* path,
411 PrefSyncStatus sync_status) {
412 DCHECK(IsProfilePrefService(this));
413 RegisterPreference(path, new DictionaryValue(), sync_status);
414 }
415
416 void PrefService::RegisterDictionaryPref(const char* path,
417 DictionaryValue* default_value,
418 PrefSyncStatus sync_status) {
419 DCHECK(IsProfilePrefService(this));
420 RegisterPreference(path, default_value, sync_status);
421 }
422
423 void PrefService::RegisterLocalizedBooleanPref(const char* path,
424 int locale_default_message_id,
425 PrefSyncStatus sync_status) {
426 DCHECK(IsProfilePrefService(this));
427 RegisterPreference(
428 path,
429 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id),
430 sync_status);
431 }
432
433 void PrefService::RegisterLocalizedIntegerPref(const char* path,
434 int locale_default_message_id,
435 PrefSyncStatus sync_status) {
436 DCHECK(IsProfilePrefService(this));
437 RegisterPreference(
438 path,
439 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id),
440 sync_status);
441 }
442
443 void PrefService::RegisterLocalizedDoublePref(const char* path,
444 int locale_default_message_id,
445 PrefSyncStatus sync_status) {
446 DCHECK(IsProfilePrefService(this));
447 RegisterPreference(
448 path,
449 CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id),
450 sync_status);
451 }
452
453 void PrefService::RegisterLocalizedStringPref(const char* path,
454 int locale_default_message_id,
455 PrefSyncStatus sync_status) {
456 DCHECK(IsProfilePrefService(this));
457 RegisterPreference(
458 path,
459 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id),
460 sync_status);
461 }
462
463 void PrefService::RegisterInt64Pref(const char* path,
464 int64 default_value,
465 PrefSyncStatus sync_status) {
466 DCHECK(IsProfilePrefService(this));
467 RegisterPreference(
468 path,
469 Value::CreateStringValue(base::Int64ToString(default_value)),
470 sync_status);
471 }
472
473 void PrefService::RegisterUint64Pref(const char* path,
474 uint64 default_value,
475 PrefSyncStatus sync_status) {
476 DCHECK(IsProfilePrefService(this));
477 RegisterPreference(
478 path,
479 Value::CreateStringValue(base::Uint64ToString(default_value)),
480 sync_status);
481 }
482
483 bool PrefService::GetBoolean(const char* path) const { 75 bool PrefService::GetBoolean(const char* path) const {
484 DCHECK(CalledOnValidThread()); 76 DCHECK(CalledOnValidThread());
485 77
486 bool result = false; 78 bool result = false;
487 79
488 const base::Value* value = GetPreferenceValue(path); 80 const base::Value* value = GetPreferenceValue(path);
489 if (!value) { 81 if (!value) {
490 NOTREACHED() << "Trying to read an unregistered pref: " << path; 82 NOTREACHED() << "Trying to read an unregistered pref: " << path;
491 return result; 83 return result;
492 } 84 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 276 }
685 277
686 void PrefService::RemovePrefObserver(const char* path, PrefObserver* obs) { 278 void PrefService::RemovePrefObserver(const char* path, PrefObserver* obs) {
687 pref_notifier_->RemovePrefObserver(path, obs); 279 pref_notifier_->RemovePrefObserver(path, obs);
688 } 280 }
689 281
690 void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) { 282 void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) {
691 pref_notifier_->AddInitObserver(obs); 283 pref_notifier_->AddInitObserver(obs);
692 } 284 }
693 285
286 PrefService::PrefService() {}
287
288 void PrefService::Initialize(
289 PrefNotifierImpl* pref_notifier,
290 PrefValueStore* pref_value_store,
291 PersistentPrefStore* user_prefs,
292 DefaultPrefStore* default_store,
293 base::Callback<void(PersistentPrefStore::PrefReadError)>
294 read_error_callback,
295 bool async) {
296 pref_notifier_.reset(pref_notifier);
297 pref_value_store_.reset(pref_value_store);
298 user_pref_store_ = user_prefs;
299 default_store_ = default_store;
300 read_error_callback_ = read_error_callback;
301 pref_notifier_->SetPrefService(this);
302 InitFromStorage(async);
303 }
304
694 void PrefService::RegisterPreference(const char* path, 305 void PrefService::RegisterPreference(const char* path,
695 Value* default_value, 306 Value* default_value) {
696 PrefSyncStatus sync_status) {
697 DCHECK(CalledOnValidThread()); 307 DCHECK(CalledOnValidThread());
698 308
699 // The main code path takes ownership, but most don't. We'll be safe. 309 // The main code path takes ownership, but most don't. We'll be safe.
700 scoped_ptr<Value> scoped_value(default_value); 310 scoped_ptr<Value> scoped_value(default_value);
701 311
702 CHECK(!FindPreference(path)) << "Tried to register duplicate pref " << path; 312 CHECK(!FindPreference(path)) << "Tried to register duplicate pref " << path;
703 313
704 base::Value::Type orig_type = default_value->GetType(); 314 base::Value::Type orig_type = default_value->GetType();
705 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << 315 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) <<
706 "invalid preference type: " << orig_type; 316 "invalid preference type: " << orig_type;
(...skipping 10 matching lines...) Expand all
717 } else if (orig_type == base::Value::TYPE_DICTIONARY) { 327 } else if (orig_type == base::Value::TYPE_DICTIONARY) {
718 const base::DictionaryValue* dict = NULL; 328 const base::DictionaryValue* dict = NULL;
719 if (default_value->GetAsDictionary(&dict) && !dict->empty()) 329 if (default_value->GetAsDictionary(&dict) && !dict->empty())
720 needs_empty_value = true; 330 needs_empty_value = true;
721 } 331 }
722 if (needs_empty_value) 332 if (needs_empty_value)
723 user_pref_store_->MarkNeedsEmptyValue(path); 333 user_pref_store_->MarkNeedsEmptyValue(path);
724 334
725 // Hand off ownership. 335 // Hand off ownership.
726 default_store_->SetDefaultValue(path, scoped_value.release()); 336 default_store_->SetDefaultValue(path, scoped_value.release());
727
728 // Register with sync if necessary.
729 if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get())
730 pref_sync_associator_->RegisterPref(path);
731 } 337 }
732 338
733 void PrefService::UnregisterPreference(const char* path) { 339 void PrefService::UnregisterPreference(const char* path) {
734 DCHECK(CalledOnValidThread()); 340 DCHECK(CalledOnValidThread());
735 341
736 PreferenceMap::iterator it = prefs_map_.find(path); 342 PreferenceMap::iterator it = prefs_map_.find(path);
737 CHECK(it != prefs_map_.end()) << "Trying to unregister an unregistered pref: " 343 CHECK(it != prefs_map_.end()) << "Trying to unregister an unregistered pref: "
738 << path; 344 << path;
739 345
740 prefs_map_.erase(it); 346 prefs_map_.erase(it);
741 default_store_->RemoveDefaultValue(path); 347 default_store_->RemoveDefaultValue(path);
742 if (pref_sync_associator_.get() &&
743 pref_sync_associator_->IsPrefRegistered(path)) {
744 pref_sync_associator_->UnregisterPref(path);
745 }
746 } 348 }
747 349
748 void PrefService::ClearPref(const char* path) { 350 void PrefService::ClearPref(const char* path) {
749 DCHECK(CalledOnValidThread()); 351 DCHECK(CalledOnValidThread());
750 352
751 const Preference* pref = FindPreference(path); 353 const Preference* pref = FindPreference(path);
752 if (!pref) { 354 if (!pref) {
753 NOTREACHED() << "Trying to clear an unregistered pref: " << path; 355 NOTREACHED() << "Trying to clear an unregistered pref: " << path;
754 return; 356 return;
755 } 357 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 if (pref->GetType() != new_value->GetType()) { 472 if (pref->GetType() != new_value->GetType()) {
871 NOTREACHED() << "Trying to set pref " << path 473 NOTREACHED() << "Trying to set pref " << path
872 << " of type " << pref->GetType() 474 << " of type " << pref->GetType()
873 << " to value of type " << new_value->GetType(); 475 << " to value of type " << new_value->GetType();
874 return; 476 return;
875 } 477 }
876 478
877 user_pref_store_->SetValue(path, owned_value.release()); 479 user_pref_store_->SetValue(path, owned_value.release());
878 } 480 }
879 481
880 syncer::SyncableService* PrefService::GetSyncableService() { 482 void PrefService::UpdateCommandLinePrefStore(PrefStore* command_line_store) {
881 return pref_sync_associator_.get(); 483 pref_value_store_->UpdateCommandLinePrefStore(command_line_store);
882 }
883
884 void PrefService::UpdateCommandLinePrefStore(CommandLine* command_line) {
885 // If |pref_service_forked_| is true, then this PrefService and the forked
886 // copies will be out of sync.
887 DCHECK(!pref_service_forked_);
888 pref_value_store_->UpdateCommandLinePrefStore(
889 new CommandLinePrefStore(command_line));
890 } 484 }
891 485
892 /////////////////////////////////////////////////////////////////////////////// 486 ///////////////////////////////////////////////////////////////////////////////
893 // PrefService::Preference 487 // PrefService::Preference
894 488
895 PrefService::Preference::Preference(const PrefService* service, 489 PrefService::Preference::Preference(const PrefService* service,
896 const char* name, 490 const char* name,
897 base::Value::Type type) 491 base::Value::Type type)
898 : name_(name), 492 : name_(name),
899 type_(type), 493 type_(type),
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 const Value* found_value = NULL; 569 const Value* found_value = NULL;
976 if (pref_value_store_->GetValue(path, type, &found_value)) { 570 if (pref_value_store_->GetValue(path, type, &found_value)) {
977 DCHECK(found_value->IsType(type)); 571 DCHECK(found_value->IsType(type));
978 return found_value; 572 return found_value;
979 } 573 }
980 574
981 // Every registered preference has at least a default value. 575 // Every registered preference has at least a default value.
982 NOTREACHED() << "no valid value found for registered pref " << path; 576 NOTREACHED() << "no valid value found for registered pref " << path;
983 return NULL; 577 return NULL;
984 } 578 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698