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

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

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, fix up unit tests. Created 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include <string> 8 #include <string>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/stl_util-inl.h" 17 #include "base/stl_util-inl.h"
18 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/sys_string_conversions.h" 20 #include "base/sys_string_conversions.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "chrome/browser/browser_thread.h" 23 #include "chrome/browser/browser_thread.h"
24 #include "chrome/browser/policy/configuration_policy_pref_store.h" 24 #include "chrome/browser/policy/configuration_policy_pref_store.h"
25 #include "chrome/browser/prefs/command_line_pref_store.h" 25 #include "chrome/browser/prefs/command_line_pref_store.h"
26 #include "chrome/browser/prefs/in_memory_pref_store.h" 26 #include "chrome/browser/prefs/default_pref_store.h"
27 #include "chrome/browser/prefs/pref_notifier_impl.h" 27 #include "chrome/browser/prefs/pref_notifier_impl.h"
28 #include "chrome/browser/prefs/pref_value_store.h" 28 #include "chrome/browser/prefs/pref_value_store.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/common/json_pref_store.h" 30 #include "chrome/common/json_pref_store.h"
31 #include "chrome/common/notification_service.h" 31 #include "chrome/common/notification_service.h"
32 #include "grit/chromium_strings.h" 32 #include "grit/chromium_strings.h"
33 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
34 34
35 namespace { 35 namespace {
36 36
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 void NotifyReadError(PrefService* pref, int message_id) { 79 void NotifyReadError(PrefService* pref, int message_id) {
80 Source<PrefService> source(pref); 80 Source<PrefService> source(pref);
81 NotificationService::current()->Notify(NotificationType::PROFILE_ERROR, 81 NotificationService::current()->Notify(NotificationType::PROFILE_ERROR,
82 source, Details<int>(&message_id)); 82 source, Details<int>(&message_id));
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 // static 87 // static
88 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, 88 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename,
89 PrefStore* extension_prefs,
89 Profile* profile) { 90 Profile* profile) {
90 using policy::ConfigurationPolicyPrefStore; 91 using policy::ConfigurationPolicyPrefStore;
91 92
92 #if defined(OS_LINUX) 93 #if defined(OS_LINUX)
93 // We'd like to see what fraction of our users have the preferences 94 // We'd like to see what fraction of our users have the preferences
94 // stored on a network file system, as we've had no end of troubles 95 // stored on a network file system, as we've had no end of troubles
95 // with NFS/AFS. 96 // with NFS/AFS.
96 // TODO(evanm): remove this once we've collected state. 97 // TODO(evanm): remove this once we've collected state.
97 file_util::FileSystemType fstype; 98 file_util::FileSystemType fstype;
98 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { 99 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) {
99 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", 100 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType",
100 static_cast<int>(fstype), 101 static_cast<int>(fstype),
101 file_util::FILE_SYSTEM_TYPE_COUNT); 102 file_util::FILE_SYSTEM_TYPE_COUNT);
102 } 103 }
103 #endif 104 #endif
104 105
105 ConfigurationPolicyPrefStore* managed = 106 ConfigurationPolicyPrefStore* managed =
106 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore(); 107 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore();
107 ConfigurationPolicyPrefStore* device_management = 108 ConfigurationPolicyPrefStore* device_management =
108 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( 109 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore(
109 profile); 110 profile);
110 InMemoryPrefStore* extension = new InMemoryPrefStore();
111 CommandLinePrefStore* command_line = 111 CommandLinePrefStore* command_line =
112 new CommandLinePrefStore(CommandLine::ForCurrentProcess()); 112 new CommandLinePrefStore(CommandLine::ForCurrentProcess());
113 JsonPrefStore* user = new JsonPrefStore( 113 JsonPrefStore* user = new JsonPrefStore(
114 pref_filename, 114 pref_filename,
115 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 115 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
116 ConfigurationPolicyPrefStore* recommended = 116 ConfigurationPolicyPrefStore* recommended =
117 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); 117 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore();
118 118
119 return new PrefService(managed, device_management, extension, command_line, 119 return new PrefService(managed, device_management, extension_prefs,
120 user, recommended, profile); 120 command_line, user, recommended, profile);
121 } 121 }
122 122
123 // static 123 // static
124 PrefService* PrefService::CreateUserPrefService(const FilePath& pref_filename) { 124 PrefService* PrefService::CreateUserPrefService(const FilePath& pref_filename) {
125 JsonPrefStore* user = new JsonPrefStore( 125 JsonPrefStore* user = new JsonPrefStore(
126 pref_filename, 126 pref_filename,
127 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 127 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
128 InMemoryPrefStore* extension = new InMemoryPrefStore();
129 128
130 return new PrefService(NULL, NULL, extension, NULL, user, NULL, NULL); 129 return new PrefService(NULL, NULL, NULL, NULL, user, NULL, NULL);
131 } 130 }
132 131
133 PrefService::PrefService(PrefStore* managed_platform_prefs, 132 PrefService::PrefService(PrefStore* managed_platform_prefs,
134 PrefStore* device_management_prefs, 133 PrefStore* device_management_prefs,
135 PrefStore* extension_prefs, 134 PrefStore* extension_prefs,
136 PrefStore* command_line_prefs, 135 PrefStore* command_line_prefs,
137 PrefStore* user_prefs, 136 PersistentPrefStore* user_prefs,
138 PrefStore* recommended_prefs, 137 PrefStore* recommended_prefs,
139 Profile* profile) { 138 Profile* profile)
139 : user_pref_store_(user_prefs) {
140 pref_notifier_.reset(new PrefNotifierImpl(this)); 140 pref_notifier_.reset(new PrefNotifierImpl(this));
141 extension_store_ = extension_prefs; 141 default_store_ = new DefaultPrefStore();
142 default_store_ = new InMemoryPrefStore();
143 pref_value_store_ = 142 pref_value_store_ =
144 new PrefValueStore(managed_platform_prefs, 143 new PrefValueStore(managed_platform_prefs,
145 device_management_prefs, 144 device_management_prefs,
146 extension_store_, 145 extension_prefs,
147 command_line_prefs, 146 command_line_prefs,
148 user_prefs, 147 user_pref_store_,
149 recommended_prefs, 148 recommended_prefs,
150 default_store_, 149 default_store_,
151 pref_notifier_.get(), 150 pref_notifier_.get(),
152 profile); 151 profile);
153 InitFromStorage(); 152 InitFromStorage();
154 } 153 }
155 154
156 PrefService::~PrefService() { 155 PrefService::~PrefService() {
157 DCHECK(CalledOnValidThread()); 156 DCHECK(CalledOnValidThread());
158 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); 157 STLDeleteContainerPointers(prefs_.begin(), prefs_.end());
159 prefs_.clear(); 158 prefs_.clear();
160 } 159 }
161 160
162 void PrefService::InitFromStorage() { 161 void PrefService::InitFromStorage() {
163 PrefStore::PrefReadError error = LoadPersistentPrefs(); 162 PersistentPrefStore::PrefReadError error = user_pref_store_->ReadPrefs();
danno 2010/12/08 13:08:45 const
Mattias Nissler (ping if slow) 2010/12/09 10:20:20 Done.
164 if (error == PrefStore::PREF_READ_ERROR_NONE) 163 if (error == PersistentPrefStore::PREF_READ_ERROR_NONE)
165 return; 164 return;
166 165
167 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for 166 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for
168 // an example problem that this can cause. 167 // an example problem that this can cause.
169 // Do some diagnosis and try to avoid losing data. 168 // Do some diagnosis and try to avoid losing data.
170 int message_id = 0; 169 int message_id = 0;
171 if (error <= PrefStore::PREF_READ_ERROR_JSON_TYPE) { 170 if (error <= PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE) {
172 message_id = IDS_PREFERENCES_CORRUPT_ERROR; 171 message_id = IDS_PREFERENCES_CORRUPT_ERROR;
173 } else if (error != PrefStore::PREF_READ_ERROR_NO_FILE) { 172 } else if (error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) {
174 message_id = IDS_PREFERENCES_UNREADABLE_ERROR; 173 message_id = IDS_PREFERENCES_UNREADABLE_ERROR;
175 } 174 }
176 175
177 if (message_id) { 176 if (message_id) {
178 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 177 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
179 NewRunnableFunction(&NotifyReadError, this, message_id)); 178 NewRunnableFunction(&NotifyReadError, this, message_id));
180 } 179 }
181 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, 20); 180 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, 20);
182 } 181 }
183 182
184 bool PrefService::ReloadPersistentPrefs() { 183 bool PrefService::ReloadPersistentPrefs() {
185 return (LoadPersistentPrefs() == PrefStore::PREF_READ_ERROR_NONE); 184 return user_pref_store_->ReadPrefs() ==
186 } 185 PersistentPrefStore::PREF_READ_ERROR_NONE;
187
188 PrefStore::PrefReadError PrefService::LoadPersistentPrefs() {
189 DCHECK(CalledOnValidThread());
190
191 PrefStore::PrefReadError pref_error = pref_value_store_->ReadPrefs();
192
193 for (PreferenceSet::iterator it = prefs_.begin();
194 it != prefs_.end(); ++it) {
195 (*it)->pref_service_ = this;
196 }
197
198 return pref_error;
199 } 186 }
200 187
201 bool PrefService::SavePersistentPrefs() { 188 bool PrefService::SavePersistentPrefs() {
202 DCHECK(CalledOnValidThread()); 189 DCHECK(CalledOnValidThread());
203 190
204 return pref_value_store_->WritePrefs(); 191 return user_pref_store_->WritePrefs();
205 } 192 }
206 193
207 void PrefService::ScheduleSavePersistentPrefs() { 194 void PrefService::ScheduleSavePersistentPrefs() {
208 DCHECK(CalledOnValidThread()); 195 DCHECK(CalledOnValidThread());
209 196
210 pref_value_store_->ScheduleWritePrefs(); 197 user_pref_store_->ScheduleWritePrefs();
211 } 198 }
212 199
213 void PrefService::RegisterBooleanPref(const char* path, 200 void PrefService::RegisterBooleanPref(const char* path,
214 bool default_value) { 201 bool default_value) {
215 RegisterPreference(path, Value::CreateBooleanValue(default_value)); 202 RegisterPreference(path, Value::CreateBooleanValue(default_value));
216 } 203 }
217 204
218 void PrefService::RegisterIntegerPref(const char* path, int default_value) { 205 void PrefService::RegisterIntegerPref(const char* path, int default_value) {
219 RegisterPreference(path, Value::CreateIntegerValue(default_value)); 206 RegisterPreference(path, Value::CreateIntegerValue(default_value));
220 } 207 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 341
355 const PrefService::Preference* PrefService::FindPreference( 342 const PrefService::Preference* PrefService::FindPreference(
356 const char* pref_name) const { 343 const char* pref_name) const {
357 DCHECK(CalledOnValidThread()); 344 DCHECK(CalledOnValidThread());
358 Preference p(this, pref_name); 345 Preference p(this, pref_name);
359 PreferenceSet::const_iterator it = prefs_.find(&p); 346 PreferenceSet::const_iterator it = prefs_.find(&p);
360 return it == prefs_.end() ? NULL : *it; 347 return it == prefs_.end() ? NULL : *it;
361 } 348 }
362 349
363 bool PrefService::ReadOnly() const { 350 bool PrefService::ReadOnly() const {
364 return pref_value_store_->ReadOnly(); 351 return user_pref_store_->ReadOnly();
365 } 352 }
366 353
367 PrefNotifier* PrefService::pref_notifier() const { 354 PrefNotifier* PrefService::pref_notifier() const {
368 return pref_notifier_.get(); 355 return pref_notifier_.get();
369 } 356 }
370 357
371 PrefStore* PrefService::GetExtensionPrefStore() {
372 return extension_store_;
373 }
374
375 bool PrefService::IsManagedPreference(const char* pref_name) const { 358 bool PrefService::IsManagedPreference(const char* pref_name) const {
376 const Preference* pref = FindPreference(pref_name); 359 const Preference* pref = FindPreference(pref_name);
377 if (pref && pref->IsManaged()) { 360 if (pref && pref->IsManaged()) {
378 return true; 361 return true;
379 } 362 }
380 return false; 363 return false;
381 } 364 }
382 365
383 const DictionaryValue* PrefService::GetDictionary(const char* path) const { 366 const DictionaryValue* PrefService::GetDictionary(const char* path) const {
384 DCHECK(CalledOnValidThread()); 367 DCHECK(CalledOnValidThread());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 413 }
431 414
432 Value::ValueType orig_type = default_value->GetType(); 415 Value::ValueType orig_type = default_value->GetType();
433 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << 416 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) <<
434 "invalid preference type: " << orig_type; 417 "invalid preference type: " << orig_type;
435 418
436 // We set the default value of dictionaries and lists to be null so it's 419 // We set the default value of dictionaries and lists to be null so it's
437 // easier for callers to check for empty dict/list prefs. The PrefValueStore 420 // easier for callers to check for empty dict/list prefs. The PrefValueStore
438 // accepts ownership of the value (null or default_value). 421 // accepts ownership of the value (null or default_value).
439 if (Value::TYPE_LIST == orig_type || Value::TYPE_DICTIONARY == orig_type) { 422 if (Value::TYPE_LIST == orig_type || Value::TYPE_DICTIONARY == orig_type) {
440 default_store_->prefs()->Set(path, Value::CreateNullValue()); 423 default_store_->SetDefaultValue(path, Value::CreateNullValue());
441 } else { 424 } else {
442 // Hand off ownership. 425 // Hand off ownership.
443 DCHECK(!PrefStore::IsUseDefaultSentinelValue(default_value)); 426 default_store_->SetDefaultValue(path, scoped_value.release());
444 default_store_->prefs()->Set(path, scoped_value.release());
445 } 427 }
446 428
447 pref_value_store_->RegisterPreferenceType(path, orig_type); 429 pref_value_store_->RegisterPreferenceType(path, orig_type);
448 prefs_.insert(new Preference(this, path)); 430 prefs_.insert(new Preference(this, path));
449 } 431 }
450 432
451 void PrefService::ClearPref(const char* path) { 433 void PrefService::ClearPref(const char* path) {
452 DCHECK(CalledOnValidThread()); 434 DCHECK(CalledOnValidThread());
453 435
454 const Preference* pref = FindPreference(path); 436 const Preference* pref = FindPreference(path);
455 if (!pref) { 437 if (!pref) {
456 NOTREACHED() << "Trying to clear an unregistered pref: " << path; 438 NOTREACHED() << "Trying to clear an unregistered pref: " << path;
457 return; 439 return;
458 } 440 }
459 pref_value_store_->RemoveUserPrefValue(path); 441 user_pref_store_->RemoveValue(path);
460 } 442 }
461 443
462 void PrefService::Set(const char* path, const Value& value) { 444 void PrefService::Set(const char* path, const Value& value) {
463 DCHECK(CalledOnValidThread()); 445 DCHECK(CalledOnValidThread());
464 446
465 const Preference* pref = FindPreference(path); 447 const Preference* pref = FindPreference(path);
466 if (!pref) { 448 if (!pref) {
467 NOTREACHED() << "Trying to write an unregistered pref: " << path; 449 NOTREACHED() << "Trying to write an unregistered pref: " << path;
468 return; 450 return;
469 } 451 }
470 452
471 // Allow dictionary and list types to be set to null, which removes their 453 // Allow dictionary and list types to be set to null, which removes their
472 // user values. 454 // user values.
473 if (value.GetType() == Value::TYPE_NULL && 455 if (value.GetType() == Value::TYPE_NULL &&
474 (pref->GetType() == Value::TYPE_DICTIONARY || 456 (pref->GetType() == Value::TYPE_DICTIONARY ||
475 pref->GetType() == Value::TYPE_LIST)) { 457 pref->GetType() == Value::TYPE_LIST)) {
476 pref_value_store_->RemoveUserPrefValue(path); 458 user_pref_store_->RemoveValue(path);
477 } else if (pref->GetType() != value.GetType()) { 459 } else if (pref->GetType() != value.GetType()) {
478 NOTREACHED() << "Trying to set pref " << path 460 NOTREACHED() << "Trying to set pref " << path
479 << " of type " << pref->GetType() 461 << " of type " << pref->GetType()
480 << " to value of type " << value.GetType(); 462 << " to value of type " << value.GetType();
481 } else { 463 } else {
482 pref_value_store_->SetUserPrefValue(path, value.DeepCopy()); 464 user_pref_store_->SetValue(path, value.DeepCopy());
483 } 465 }
484 } 466 }
485 467
486 void PrefService::SetBoolean(const char* path, bool value) { 468 void PrefService::SetBoolean(const char* path, bool value) {
487 SetUserPrefValue(path, Value::CreateBooleanValue(value)); 469 SetUserPrefValue(path, Value::CreateBooleanValue(value));
488 } 470 }
489 471
490 void PrefService::SetInteger(const char* path, int value) { 472 void PrefService::SetInteger(const char* path, int value) {
491 SetUserPrefValue(path, Value::CreateIntegerValue(value)); 473 SetUserPrefValue(path, Value::CreateIntegerValue(value));
492 } 474 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 530 }
549 if (pref->GetType() != Value::TYPE_DICTIONARY) { 531 if (pref->GetType() != Value::TYPE_DICTIONARY) {
550 NOTREACHED() << "Wrong type for GetMutableDictionary: " << path; 532 NOTREACHED() << "Wrong type for GetMutableDictionary: " << path;
551 return NULL; 533 return NULL;
552 } 534 }
553 535
554 DictionaryValue* dict = NULL; 536 DictionaryValue* dict = NULL;
555 Value* tmp_value = NULL; 537 Value* tmp_value = NULL;
556 // Look for an existing preference in the user store. If it doesn't 538 // Look for an existing preference in the user store. If it doesn't
557 // exist or isn't the correct type, create a new user preference. 539 // exist or isn't the correct type, create a new user preference.
558 if (!pref_value_store_->GetUserValue(path, &tmp_value) || 540 if (user_pref_store_->GetValue(path, &tmp_value)
541 != PersistentPrefStore::READ_OK ||
559 !tmp_value->IsType(Value::TYPE_DICTIONARY)) { 542 !tmp_value->IsType(Value::TYPE_DICTIONARY)) {
560 dict = new DictionaryValue; 543 dict = new DictionaryValue;
561 pref_value_store_->SetUserPrefValueSilently(path, dict); 544 user_pref_store_->SetValueSilently(path, dict);
562 } else { 545 } else {
563 dict = static_cast<DictionaryValue*>(tmp_value); 546 dict = static_cast<DictionaryValue*>(tmp_value);
564 } 547 }
565 return dict; 548 return dict;
566 } 549 }
567 550
568 ListValue* PrefService::GetMutableList(const char* path) { 551 ListValue* PrefService::GetMutableList(const char* path) {
569 DCHECK(CalledOnValidThread()); 552 DCHECK(CalledOnValidThread());
570 553
571 const Preference* pref = FindPreference(path); 554 const Preference* pref = FindPreference(path);
572 if (!pref) { 555 if (!pref) {
573 NOTREACHED() << "Trying to get an unregistered pref: " << path; 556 NOTREACHED() << "Trying to get an unregistered pref: " << path;
574 return NULL; 557 return NULL;
575 } 558 }
576 if (pref->GetType() != Value::TYPE_LIST) { 559 if (pref->GetType() != Value::TYPE_LIST) {
577 NOTREACHED() << "Wrong type for GetMutableList: " << path; 560 NOTREACHED() << "Wrong type for GetMutableList: " << path;
578 return NULL; 561 return NULL;
579 } 562 }
580 563
581 ListValue* list = NULL; 564 ListValue* list = NULL;
582 Value* tmp_value = NULL; 565 Value* tmp_value = NULL;
583 // Look for an existing preference in the user store. If it doesn't 566 // Look for an existing preference in the user store. If it doesn't
584 // exist or isn't the correct type, create a new user preference. 567 // exist or isn't the correct type, create a new user preference.
585 if (!pref_value_store_->GetUserValue(path, &tmp_value) || 568 if (user_pref_store_->GetValue(path, &tmp_value)
569 != PersistentPrefStore::READ_OK ||
586 !tmp_value->IsType(Value::TYPE_LIST)) { 570 !tmp_value->IsType(Value::TYPE_LIST)) {
587 list = new ListValue; 571 list = new ListValue;
588 pref_value_store_->SetUserPrefValueSilently(path, list); 572 user_pref_store_->SetValueSilently(path, list);
589 } else { 573 } else {
590 list = static_cast<ListValue*>(tmp_value); 574 list = static_cast<ListValue*>(tmp_value);
591 } 575 }
592 return list; 576 return list;
593 } 577 }
594 578
595 Value* PrefService::GetPrefCopy(const char* path) {
596 DCHECK(CalledOnValidThread());
597
598 const Preference* pref = FindPreference(path);
599 DCHECK(pref);
600 return pref->GetValue()->DeepCopy();
601 }
602
603 void PrefService::SetUserPrefValue(const char* path, Value* new_value) { 579 void PrefService::SetUserPrefValue(const char* path, Value* new_value) {
604 DCHECK(CalledOnValidThread()); 580 DCHECK(CalledOnValidThread());
605 581
606 const Preference* pref = FindPreference(path); 582 const Preference* pref = FindPreference(path);
607 if (!pref) { 583 if (!pref) {
608 NOTREACHED() << "Trying to write an unregistered pref: " << path; 584 NOTREACHED() << "Trying to write an unregistered pref: " << path;
609 return; 585 return;
610 } 586 }
611 if (pref->IsManaged()) {
612 NOTREACHED() << "Preference is managed: " << path;
613 return;
614 }
615 if (pref->GetType() != new_value->GetType()) { 587 if (pref->GetType() != new_value->GetType()) {
616 NOTREACHED() << "Trying to set pref " << path 588 NOTREACHED() << "Trying to set pref " << path
617 << " of type " << pref->GetType() 589 << " of type " << pref->GetType()
618 << " to value of type " << new_value->GetType(); 590 << " to value of type " << new_value->GetType();
619 return; 591 return;
620 } 592 }
621 593
622 pref_value_store_->SetUserPrefValue(path, new_value); 594 user_pref_store_->SetValue(path, new_value);
623 } 595 }
624 596
625 /////////////////////////////////////////////////////////////////////////////// 597 ///////////////////////////////////////////////////////////////////////////////
626 // PrefService::Preference 598 // PrefService::Preference
627 599
628 PrefService::Preference::Preference(const PrefService* service, 600 PrefService::Preference::Preference(const PrefService* service,
629 const char* name) 601 const char* name)
630 : name_(name), 602 : name_(name),
631 pref_service_(service) { 603 pref_service_(service) {
632 DCHECK(name); 604 DCHECK(name);
(...skipping 11 matching lines...) Expand all
644 Value* found_value = NULL; 616 Value* found_value = NULL;
645 if (pref_service_->pref_value_store_->GetValue(name_, &found_value)) 617 if (pref_service_->pref_value_store_->GetValue(name_, &found_value))
646 return found_value; 618 return found_value;
647 619
648 // Every registered preference has at least a default value. 620 // Every registered preference has at least a default value.
649 NOTREACHED() << "no valid value found for registered pref " << name_; 621 NOTREACHED() << "no valid value found for registered pref " << name_;
650 return NULL; 622 return NULL;
651 } 623 }
652 624
653 bool PrefService::Preference::IsManaged() const { 625 bool PrefService::Preference::IsManaged() const {
654 PrefValueStore* pref_value_store = 626 PrefValueStore* pref_value_store = pref_service_->pref_value_store_;
655 pref_service_->pref_value_store_;
656 return pref_value_store->PrefValueInManagedPlatformStore(name_.c_str()) || 627 return pref_value_store->PrefValueInManagedPlatformStore(name_.c_str()) ||
657 pref_value_store->PrefValueInDeviceManagementStore(name_.c_str()); 628 pref_value_store->PrefValueInDeviceManagementStore(name_.c_str());
658 } 629 }
659 630
660 bool PrefService::Preference::HasExtensionSetting() const { 631 bool PrefService::Preference::HasExtensionSetting() const {
661 return pref_service_->pref_value_store_-> 632 return pref_service_->pref_value_store_->
662 PrefValueInExtensionStore(name_.c_str()); 633 PrefValueInExtensionStore(name_.c_str());
663 } 634 }
664 635
665 bool PrefService::Preference::HasUserSetting() const { 636 bool PrefService::Preference::HasUserSetting() const {
(...skipping 13 matching lines...) Expand all
679 650
680 bool PrefService::Preference::IsDefaultValue() const { 651 bool PrefService::Preference::IsDefaultValue() const {
681 return pref_service_->pref_value_store_-> 652 return pref_service_->pref_value_store_->
682 PrefValueFromDefaultStore(name_.c_str()); 653 PrefValueFromDefaultStore(name_.c_str());
683 } 654 }
684 655
685 bool PrefService::Preference::IsUserModifiable() const { 656 bool PrefService::Preference::IsUserModifiable() const {
686 return pref_service_->pref_value_store_-> 657 return pref_service_->pref_value_store_->
687 PrefValueUserModifiable(name_.c_str()); 658 PrefValueUserModifiable(name_.c_str());
688 } 659 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698