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

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: Rebased on ToT (solved merging conflict). Created 9 years, 1 month 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"
12 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 11 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
12 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 static base::LazyInstance<CrosSettings> g_cros_settings = 20 static base::LazyInstance<CrosSettings> g_cros_settings =
21 LAZY_INSTANCE_INITIALIZER; 21 LAZY_INSTANCE_INITIALIZER;
22 22
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return; 139 return;
140 } 140 }
141 141
142 NotificationObserverList* observer_list = observer_iterator->second; 142 NotificationObserverList* observer_list = observer_iterator->second;
143 observer_list->RemoveObserver(obs); 143 observer_list->RemoveObserver(obs);
144 } 144 }
145 145
146 CrosSettingsProvider* CrosSettings::GetProvider( 146 CrosSettingsProvider* CrosSettings::GetProvider(
147 const std::string& path) const { 147 const std::string& path) const {
148 for (size_t i = 0; i < providers_.size(); ++i) { 148 for (size_t i = 0; i < providers_.size(); ++i) {
149 if (providers_[i]->HandlesSetting(path)) { 149 if (providers_[i]->HandlesSetting(path))
150 return providers_[i]; 150 return providers_[i];
151 }
152 } 151 }
153 return NULL; 152 return NULL;
154 } 153 }
155 154
156 bool CrosSettings::Get(const std::string& path, Value** out_value) const { 155 const base::Value* CrosSettings::GetPref(const std::string& path) const {
157 DCHECK(CalledOnValidThread()); 156 DCHECK(CalledOnValidThread());
158 CrosSettingsProvider* provider; 157 CrosSettingsProvider* provider = GetProvider(path);
159 provider = GetProvider(path); 158 if (provider)
160 if (provider) { 159 return provider->Get(path);
161 return provider->Get(path, out_value); 160 NOTREACHED() << path << " preference was not found in the signed settings.";
162 } 161 return NULL;
162 }
163
164 bool CrosSettings::GetTrusted(
Mattias Nissler (ping if slow) 2011/11/18 14:12:00 no need for line break AFAICS.
pastarmovj 2011/11/18 15:01:38 Done.
165 const std::string& path,
166 const base::Closure& callback) const {
167 DCHECK(CalledOnValidThread());
168 CrosSettingsProvider* provider = GetProvider(path);
169 if (provider)
170 return provider->GetTrusted(path, callback);
171 NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path;
163 return false; 172 return false;
164 } 173 }
165 174
166 bool CrosSettings::GetBoolean(const std::string& path, 175 bool CrosSettings::GetBoolean(const std::string& path,
167 bool* bool_value) const { 176 bool* bool_value) const {
168 DCHECK(CalledOnValidThread()); 177 DCHECK(CalledOnValidThread());
169 Value* value; 178 const base::Value* value = GetPref(path);
170 if (!Get(path, &value)) 179 if (value)
171 return false; 180 return value->GetAsBoolean(bool_value);
172 181 return false;
173 return value->GetAsBoolean(bool_value);
174 } 182 }
175 183
176 bool CrosSettings::GetInteger(const std::string& path, 184 bool CrosSettings::GetInteger(const std::string& path,
177 int* out_value) const { 185 int* out_value) const {
178 DCHECK(CalledOnValidThread()); 186 DCHECK(CalledOnValidThread());
179 Value* value; 187 const base::Value* value = GetPref(path);
180 if (!Get(path, &value)) 188 if (value)
181 return false; 189 return value->GetAsInteger(out_value);
182 190 return false;
183 return value->GetAsInteger(out_value);
184 } 191 }
185 192
186 bool CrosSettings::GetDouble(const std::string& path, 193 bool CrosSettings::GetDouble(const std::string& path,
187 double* out_value) const { 194 double* out_value) const {
188 DCHECK(CalledOnValidThread()); 195 DCHECK(CalledOnValidThread());
189 Value* value; 196 const base::Value* value = GetPref(path);
190 if (!Get(path, &value)) 197 if (value)
191 return false; 198 return value->GetAsDouble(out_value);
192 199 return false;
193 return value->GetAsDouble(out_value);
194 } 200 }
195 201
196 bool CrosSettings::GetString(const std::string& path, 202 bool CrosSettings::GetString(const std::string& path,
197 std::string* out_value) const { 203 std::string* out_value) const {
198 DCHECK(CalledOnValidThread()); 204 DCHECK(CalledOnValidThread());
199 Value* value; 205 const base::Value* value = GetPref(path);
200 if (!Get(path, &value)) 206 if (value)
201 return false; 207 return value->GetAsString(out_value);
208 return false;
209 }
202 210
203 return value->GetAsString(out_value); 211 bool CrosSettings::GetList(const std::string& path,
212 const base::ListValue** out_value) const {
213 DCHECK(CalledOnValidThread());
214 const base::Value* value = GetPref(path);
215 if (value)
216 return value->GetAsList(out_value);
217 return false;
204 } 218 }
205 219
206 CrosSettings::CrosSettings() { 220 CrosSettings::CrosSettings() {
221 AddSettingsProvider(new SystemSettingsProvider());
222 AddSettingsProvider(new UserCrosSettingsProvider());
207 } 223 }
208 224
209 CrosSettings::~CrosSettings() { 225 CrosSettings::~CrosSettings() {
210 DCHECK(providers_.empty()); 226 STLDeleteElements(&providers_);
211 STLDeleteValues(&settings_observers_); 227 STLDeleteValues(&settings_observers_);
212 } 228 }
213 229
214 } // namespace chromeos 230 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698