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

Side by Side Diff: chrome/browser/chromeos/cros_settings.cc

Issue 7867044: PART1: Initiated the SignedSettings refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments from Chris and rebased to ToT to get it running on the try servers again. Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/chromeos/cros_settings.h" 5 #include "chrome/browser/chromeos/cros_settings.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/chromeos/cros_settings_provider.h" 11 #include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
12 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 12 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
13 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
13 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
14 #include "content/common/content_notification_types.h" 15 #include "content/common/content_notification_types.h"
15 #include "content/common/notification_details.h" 16 #include "content/common/notification_details.h"
16 #include "content/common/notification_source.h" 17 #include "content/common/notification_source.h"
17 18
18 namespace chromeos { 19 namespace chromeos {
19 20
20 static base::LazyInstance<CrosSettings> g_cros_settings( 21 static base::LazyInstance<CrosSettings> g_cros_settings(
21 base::LINKER_INITIALIZED); 22 base::LINKER_INITIALIZED);
22 23
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return; 140 return;
140 } 141 }
141 142
142 NotificationObserverList* observer_list = observer_iterator->second; 143 NotificationObserverList* observer_list = observer_iterator->second;
143 observer_list->RemoveObserver(obs); 144 observer_list->RemoveObserver(obs);
144 } 145 }
145 146
146 CrosSettingsProvider* CrosSettings::GetProvider( 147 CrosSettingsProvider* CrosSettings::GetProvider(
147 const std::string& path) const { 148 const std::string& path) const {
148 for (size_t i = 0; i < providers_.size(); ++i) { 149 for (size_t i = 0; i < providers_.size(); ++i) {
149 if (providers_[i]->HandlesSetting(path)) { 150 if (providers_[i]->HandlesSetting(path))
150 return providers_[i]; 151 return providers_[i];
151 }
152 } 152 }
153 return NULL; 153 return NULL;
154 } 154 }
155 155
156 bool CrosSettings::Get(const std::string& path, Value** out_value) const { 156 const base::Value* CrosSettings::GetPref(const std::string& path) const {
157 DCHECK(CalledOnValidThread()); 157 DCHECK(CalledOnValidThread());
158 CrosSettingsProvider* provider; 158 CrosSettingsProvider* provider;
159 provider = GetProvider(path); 159 provider = GetProvider(path);
160 if (provider) { 160 if (provider)
161 return provider->Get(path, out_value); 161 return provider->Get(path);
162 } 162 NOTREACHED() << path << " preference was not found in the signed settings.";
163 return NULL;
164 }
165
166 bool CrosSettings::GetTrusted(
167 const std::string& path,
168 const base::Closure& callback) const {
169 DCHECK(CalledOnValidThread());
170 CrosSettingsProvider* provider;
171 provider = GetProvider(path);
Denis Lagno 2011/10/13 13:45:25 join lines 170+171 or even 170+171+172 together?
pastarmovj 2011/10/26 15:43:19 Done here for 170+171 as well as above for 158+159
172 if (provider)
173 return provider->GetTrusted(path, callback);
174 NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path;
163 return false; 175 return false;
164 } 176 }
165 177
166 bool CrosSettings::GetBoolean(const std::string& path, 178 bool CrosSettings::GetBoolean(const std::string& path,
167 bool* bool_value) const { 179 bool* bool_value) const {
168 DCHECK(CalledOnValidThread()); 180 DCHECK(CalledOnValidThread());
169 Value* value; 181 const base::Value* value = GetPref(path);
170 if (!Get(path, &value)) 182 if (value)
171 return false; 183 return value->GetAsBoolean(bool_value);
172 184 return false;
173 return value->GetAsBoolean(bool_value);
174 } 185 }
175 186
176 bool CrosSettings::GetInteger(const std::string& path, 187 bool CrosSettings::GetInteger(const std::string& path,
177 int* out_value) const { 188 int* out_value) const {
178 DCHECK(CalledOnValidThread()); 189 DCHECK(CalledOnValidThread());
179 Value* value; 190 const base::Value* value = GetPref(path);
180 if (!Get(path, &value)) 191 if (value)
181 return false; 192 return value->GetAsInteger(out_value);
182 193 return false;
183 return value->GetAsInteger(out_value);
184 } 194 }
185 195
186 bool CrosSettings::GetDouble(const std::string& path, 196 bool CrosSettings::GetDouble(const std::string& path,
187 double* out_value) const { 197 double* out_value) const {
188 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
189 Value* value; 199 const base::Value* value = GetPref(path);
190 if (!Get(path, &value)) 200 if (value)
191 return false; 201 return value->GetAsDouble(out_value);
192 202 return false;
193 return value->GetAsDouble(out_value);
194 } 203 }
195 204
196 bool CrosSettings::GetString(const std::string& path, 205 bool CrosSettings::GetString(const std::string& path,
197 std::string* out_value) const { 206 std::string* out_value) const {
198 DCHECK(CalledOnValidThread()); 207 DCHECK(CalledOnValidThread());
199 Value* value; 208 const base::Value* value = GetPref(path);
200 if (!Get(path, &value)) 209 if (value)
201 return false; 210 return value->GetAsString(out_value);
211 return false;
212 }
202 213
203 return value->GetAsString(out_value); 214 bool CrosSettings::GetList(const std::string& path,
215 const base::ListValue** out_value) const {
216 DCHECK(CalledOnValidThread());
217 const base::Value* value = GetPref(path);
218 if (value)
219 return value->GetAsList(out_value);
220 return false;
204 } 221 }
205 222
206 CrosSettings::CrosSettings() { 223 CrosSettings::CrosSettings() {
224 AddSettingsProvider(new ProxyCrosSettingsProvider());
225 AddSettingsProvider(new SystemSettingsProvider());
226 AddSettingsProvider(new UserCrosSettingsProvider());
207 } 227 }
208 228
209 CrosSettings::~CrosSettings() { 229 CrosSettings::~CrosSettings() {
210 DCHECK(providers_.empty()); 230 STLDeleteElements(&providers_);
211 STLDeleteValues(&settings_observers_); 231 STLDeleteValues(&settings_observers_);
212 } 232 }
213 233
214 } // namespace chromeos 234 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698