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

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

Issue 3051001: Adjust preference sync code to only sync user modifiable preferences. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: separate out the download_manager_unittest.cc fixes Created 10 years, 5 months 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
« no previous file with comments | « chrome/browser/pref_service.h ('k') | chrome/browser/pref_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/pref_service.h" 5 #include "chrome/browser/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"
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 414 }
415 return false; 415 return false;
416 } 416 }
417 417
418 void PrefService::FireObserversIfChanged(const wchar_t* path, 418 void PrefService::FireObserversIfChanged(const wchar_t* path,
419 const Value* old_value) { 419 const Value* old_value) {
420 if (PrefIsChanged(path, old_value)) 420 if (PrefIsChanged(path, old_value))
421 FireObservers(path); 421 FireObservers(path);
422 } 422 }
423 423
424 void PrefService::FireObservers(const wchar_t* path) {
425 DCHECK(CalledOnValidThread());
426
427 // Convert path to a std::wstring because the Details constructor requires a
428 // class.
429 std::wstring path_str(path);
430 PrefObserverMap::iterator observer_iterator = pref_observers_.find(path_str);
431 if (observer_iterator == pref_observers_.end())
432 return;
433
434 NotificationObserverList::Iterator it(*(observer_iterator->second));
435 NotificationObserver* observer;
436 while ((observer = it.GetNext()) != NULL) {
437 observer->Observe(NotificationType::PREF_CHANGED,
438 Source<PrefService>(this),
439 Details<std::wstring>(&path_str));
440 }
441 }
442
424 bool PrefService::PrefIsChanged(const wchar_t* path, 443 bool PrefService::PrefIsChanged(const wchar_t* path,
425 const Value* old_value) { 444 const Value* old_value) {
426 Value* new_value = NULL; 445 Value* new_value = NULL;
427 pref_value_store_->GetValue(path, &new_value); 446 pref_value_store_->GetValue(path, &new_value);
428 // Some unit tests have no values for certain prefs. 447 // Some unit tests have no values for certain prefs.
429 return (!new_value || !old_value->Equals(new_value)); 448 return (!new_value || !old_value->Equals(new_value));
430 } 449 }
431 450
432 const DictionaryValue* PrefService::GetDictionary(const wchar_t* path) const { 451 const DictionaryValue* PrefService::GetDictionary(const wchar_t* path) const {
433 DCHECK(CalledOnValidThread()); 452 DCHECK(CalledOnValidThread());
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 } 803 }
785 804
786 Value* PrefService::GetPrefCopy(const wchar_t* path) { 805 Value* PrefService::GetPrefCopy(const wchar_t* path) {
787 DCHECK(CalledOnValidThread()); 806 DCHECK(CalledOnValidThread());
788 807
789 const Preference* pref = FindPreference(path); 808 const Preference* pref = FindPreference(path);
790 DCHECK(pref); 809 DCHECK(pref);
791 return pref->GetValue()->DeepCopy(); 810 return pref->GetValue()->DeepCopy();
792 } 811 }
793 812
794 void PrefService::FireObservers(const wchar_t* path) {
795 DCHECK(CalledOnValidThread());
796
797 // Convert path to a std::wstring because the Details constructor requires a
798 // class.
799 std::wstring path_str(path);
800 PrefObserverMap::iterator observer_iterator = pref_observers_.find(path_str);
801 if (observer_iterator == pref_observers_.end())
802 return;
803
804 NotificationObserverList::Iterator it(*(observer_iterator->second));
805 NotificationObserver* observer;
806 while ((observer = it.GetNext()) != NULL) {
807 observer->Observe(NotificationType::PREF_CHANGED,
808 Source<PrefService>(this),
809 Details<std::wstring>(&path_str));
810 }
811 }
812
813 /////////////////////////////////////////////////////////////////////////////// 813 ///////////////////////////////////////////////////////////////////////////////
814 // PrefService::Preference 814 // PrefService::Preference
815 815
816 PrefService::Preference::Preference(PrefValueStore* pref_value_store, 816 PrefService::Preference::Preference(PrefValueStore* pref_value_store,
817 const wchar_t* name, 817 const wchar_t* name,
818 Value* default_value) 818 Value* default_value)
819 : type_(Value::TYPE_NULL), 819 : type_(Value::TYPE_NULL),
820 name_(name), 820 name_(name),
821 default_value_(default_value), 821 default_value_(default_value),
822 pref_value_store_(pref_value_store) { 822 pref_value_store_(pref_value_store) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 return pref_value_store_->PrefValueInUserStore(name_.c_str()); 865 return pref_value_store_->PrefValueInUserStore(name_.c_str());
866 } 866 }
867 867
868 bool PrefService::Preference::IsExtensionControlled() const { 868 bool PrefService::Preference::IsExtensionControlled() const {
869 return pref_value_store_->PrefValueFromExtensionStore(name_.c_str()); 869 return pref_value_store_->PrefValueFromExtensionStore(name_.c_str());
870 } 870 }
871 871
872 bool PrefService::Preference::IsUserControlled() const { 872 bool PrefService::Preference::IsUserControlled() const {
873 return pref_value_store_->PrefValueFromUserStore(name_.c_str()); 873 return pref_value_store_->PrefValueFromUserStore(name_.c_str());
874 } 874 }
875
876 bool PrefService::Preference::IsUserModifiable() const {
877 return pref_value_store_->PrefValueUserModifiable(name_.c_str());
878 }
OLDNEW
« no previous file with comments | « chrome/browser/pref_service.h ('k') | chrome/browser/pref_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698