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

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

Issue 2989002: Add methods for determining which PrefStore contains a given preference, and ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/pref_value_store.h ('k') | chrome/browser/pref_value_store_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_value_store.h" 5 #include "chrome/browser/pref_value_store.h"
6 6
7 PrefValueStore::PrefValueStore(PrefStore* managed_prefs, 7 PrefValueStore::PrefValueStore(PrefStore* managed_prefs,
8 PrefStore* extension_prefs, 8 PrefStore* extension_prefs,
9 PrefStore* user_prefs, 9 PrefStore* user_prefs,
10 PrefStore* recommended_prefs) { 10 PrefStore* recommended_prefs) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return result; 61 return result;
62 } 62 }
63 63
64 bool PrefValueStore::HasPrefPath(const wchar_t* path) const { 64 bool PrefValueStore::HasPrefPath(const wchar_t* path) const {
65 Value* tmp_value = NULL; 65 Value* tmp_value = NULL;
66 const std::wstring name(path); 66 const std::wstring name(path);
67 bool rv = GetValue(name, &tmp_value); 67 bool rv = GetValue(name, &tmp_value);
68 return rv; 68 return rv;
69 } 69 }
70 70
71 // The value of a Preference is managed if the PrefStore for managed
72 // preferences contains a value for the given preference |name|.
73 bool PrefValueStore::PrefValueIsManaged(const wchar_t* name) {
74 if (pref_stores_[MANAGED].get() == NULL) {
75 // No managed PreferenceStore set, hence there are no managed
76 // preferences.
77 return false;
78 }
79 Value* tmp_value;
80 return pref_stores_[MANAGED]->prefs()->Get(name, &tmp_value);
81 }
82
83 // Note the |DictionaryValue| referenced by the |PrefStore| user_prefs_ 71 // Note the |DictionaryValue| referenced by the |PrefStore| user_prefs_
84 // (returned by the method prefs()) takes the ownership of the Value referenced 72 // (returned by the method prefs()) takes the ownership of the Value referenced
85 // by in_value. 73 // by in_value.
86 void PrefValueStore::SetUserPrefValue(const wchar_t* name, Value* in_value) { 74 void PrefValueStore::SetUserPrefValue(const wchar_t* name, Value* in_value) {
87 pref_stores_[USER]->prefs()->Set(name, in_value); 75 pref_stores_[USER]->prefs()->Set(name, in_value);
88 } 76 }
89 77
90 bool PrefValueStore::ReadOnly() { 78 bool PrefValueStore::ReadOnly() {
91 return pref_stores_[USER]->ReadOnly(); 79 return pref_stores_[USER]->ReadOnly();
92 } 80 }
93 81
94 void PrefValueStore::RemoveUserPrefValue(const wchar_t* name) { 82 void PrefValueStore::RemoveUserPrefValue(const wchar_t* name) {
95 if (pref_stores_[USER].get()) { 83 if (pref_stores_[USER].get()) {
96 pref_stores_[USER]->prefs()->Remove(name, NULL); 84 pref_stores_[USER]->prefs()->Remove(name, NULL);
97 } 85 }
98 } 86 }
87
88 bool PrefValueStore::PrefValueInManagedStore(const wchar_t* name) {
89 return PrefValueInStore(name, MANAGED);
90 }
91
92 bool PrefValueStore::PrefValueInExtensionStore(const wchar_t* name) {
93 return PrefValueInStore(name, EXTENSION);
94 }
95
96 bool PrefValueStore::PrefValueInUserStore(const wchar_t* name) {
97 return PrefValueInStore(name, USER);
98 }
99
100 bool PrefValueStore::PrefValueFromExtensionStore(const wchar_t* name) {
101 return PrefValueFromStore(name, EXTENSION);
102 }
103
104 bool PrefValueStore::PrefValueFromUserStore(const wchar_t* name) {
105 return PrefValueFromStore(name, USER);
106 }
107
108 bool PrefValueStore::PrefValueInStore(const wchar_t* name, PrefStoreType type) {
109 if (pref_stores_[type].get() == NULL) {
110 // No store of that type set, so this pref can't be in it.
111 return false;
112 }
113 Value* tmp_value;
114 return pref_stores_[type]->prefs()->Get(name, &tmp_value);
115 }
116
117 bool PrefValueStore::PrefValueFromStore(const wchar_t* name,
118 PrefStoreType type) {
119 // No need to look in PrefStores with lower priority than the one we want.
120 for (int i = 0; i <= type; ++i) {
121 if (PrefValueInStore(name, static_cast<PrefStoreType>(i)))
122 return (i == type);
123 }
124 return false;
125 }
OLDNEW
« no previous file with comments | « chrome/browser/pref_value_store.h ('k') | chrome/browser/pref_value_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698