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

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: Clean up some debug output. Created 9 years, 3 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"
Denis Lagno 2011/09/20 14:05:22 you seem to use STLDeleteElements yet you remove s
pastarmovj 2011/09/20 17:11:52 True. I must have removed this before I added the
9 #include "base/string_util.h" 8 #include "base/string_util.h"
10 #include "base/values.h" 9 #include "base/values.h"
11 #include "chrome/browser/chromeos/cros_settings_provider.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/login/user_manager.h"
12 #include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
12 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 13 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
14 #include "chrome/browser/policy/browser_policy_connector.h"
15 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
13 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
14 #include "content/common/content_notification_types.h" 17 #include "content/common/content_notification_types.h"
15 #include "content/common/notification_details.h" 18 #include "content/common/notification_details.h"
16 #include "content/common/notification_source.h" 19 #include "content/common/notification_source.h"
17 20
18 namespace chromeos { 21 namespace chromeos {
19 22
20 static base::LazyInstance<CrosSettings> g_cros_settings( 23 static base::LazyInstance<CrosSettings> g_cros_settings(
21 base::LINKER_INITIALIZED); 24 base::LINKER_INITIALIZED);
22 25
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return; 142 return;
140 } 143 }
141 144
142 NotificationObserverList* observer_list = observer_iterator->second; 145 NotificationObserverList* observer_list = observer_iterator->second;
143 observer_list->RemoveObserver(obs); 146 observer_list->RemoveObserver(obs);
144 } 147 }
145 148
146 CrosSettingsProvider* CrosSettings::GetProvider( 149 CrosSettingsProvider* CrosSettings::GetProvider(
147 const std::string& path) const { 150 const std::string& path) const {
148 for (size_t i = 0; i < providers_.size(); ++i) { 151 for (size_t i = 0; i < providers_.size(); ++i) {
149 if (providers_[i]->HandlesSetting(path)) { 152 if (providers_[i]->HandlesSetting(path)) {
pastarmovj 2011/09/20 17:11:52 Removed the curlies here as well.
150 return providers_[i]; 153 return providers_[i];
151 } 154 }
152 } 155 }
153 return NULL; 156 return NULL;
154 } 157 }
155 158
159 const base::Value* CrosSettings::GetPref(const std::string& path) const {
160 DCHECK(CalledOnValidThread());
161 CrosSettingsProvider* provider;
162 provider = GetProvider(path);
163 if (provider) {
Denis Lagno 2011/09/20 14:05:22 nit: we usually do not put curly braces for one-li
pastarmovj 2011/09/20 17:11:52 Done.
164 return provider->Get(path);
165 }
166 return false;
pastarmovj 2011/09/20 17:11:52 And this should be NULL. Baaad copy/paste.
167 }
168
169 // Create a settings value with "managed" and "disabled" property.
170 // "managed" property is true if the setting is managed by administrator.
171 // "disabled" property is true if the UI for the setting should be disabled.
172 Value* CreateSettingsValue(Value *value, bool managed, bool disabled) {
173 DictionaryValue* dict = new DictionaryValue;
174 dict->Set("value", value);
175 dict->Set("managed", Value::CreateBooleanValue(managed));
176 dict->Set("disabled", Value::CreateBooleanValue(disabled));
177 return dict;
178 }
179
156 bool CrosSettings::Get(const std::string& path, Value** out_value) const { 180 bool CrosSettings::Get(const std::string& path, Value** out_value) const {
157 DCHECK(CalledOnValidThread()); 181 DCHECK(CalledOnValidThread());
182 const Value* pref_value = GetPref(path);
183 if (pref_value) {
184 *out_value = CreateSettingsValue(
185 pref_value->DeepCopy(),
186 g_browser_process->browser_policy_connector()->IsEnterpriseManaged(),
187 !UserManager::Get()->current_user_is_owner());
188 return true;
189 }
190 return false;
191 }
192
193 bool CrosSettings::GetTrusted(
194 const std::string& path,
195 const CrosSettingsProvider::Callback& callback) const {
196 DCHECK(CalledOnValidThread());
158 CrosSettingsProvider* provider; 197 CrosSettingsProvider* provider;
159 provider = GetProvider(path); 198 provider = GetProvider(path);
160 if (provider) { 199 if (provider)
161 return provider->Get(path, out_value); 200 return provider->GetTrusted(path, callback);
162 } 201 NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path;
163 return false; 202 return false;
164 } 203 }
165 204
166 bool CrosSettings::GetBoolean(const std::string& path, 205 bool CrosSettings::GetBoolean(const std::string& path,
167 bool* bool_value) const { 206 bool* bool_value) const {
168 DCHECK(CalledOnValidThread()); 207 DCHECK(CalledOnValidThread());
169 Value* value; 208 const Value* value = GetPref(path);
170 if (!Get(path, &value)) 209 if (value)
171 return false; 210 return value->GetAsBoolean(bool_value);
172 211 return false;
173 return value->GetAsBoolean(bool_value);
174 } 212 }
175 213
176 bool CrosSettings::GetInteger(const std::string& path, 214 bool CrosSettings::GetInteger(const std::string& path,
177 int* out_value) const { 215 int* out_value) const {
178 DCHECK(CalledOnValidThread()); 216 DCHECK(CalledOnValidThread());
179 Value* value; 217 const Value* value = GetPref(path);
180 if (!Get(path, &value)) 218 if (value)
181 return false; 219 return value->GetAsInteger(out_value);
182 220 return false;
183 return value->GetAsInteger(out_value);
184 } 221 }
185 222
186 bool CrosSettings::GetDouble(const std::string& path, 223 bool CrosSettings::GetDouble(const std::string& path,
187 double* out_value) const { 224 double* out_value) const {
188 DCHECK(CalledOnValidThread()); 225 DCHECK(CalledOnValidThread());
189 Value* value; 226 const Value* value = GetPref(path);
190 if (!Get(path, &value)) 227 if (value)
191 return false; 228 return value->GetAsDouble(out_value);
192 229 return false;
193 return value->GetAsDouble(out_value);
194 } 230 }
195 231
196 bool CrosSettings::GetString(const std::string& path, 232 bool CrosSettings::GetString(const std::string& path,
197 std::string* out_value) const { 233 std::string* out_value) const {
198 DCHECK(CalledOnValidThread()); 234 DCHECK(CalledOnValidThread());
199 Value* value; 235 const Value* value = GetPref(path);
200 if (!Get(path, &value)) 236 if (value)
201 return false; 237 return value->GetAsString(out_value);
238 return false;
239 }
202 240
203 return value->GetAsString(out_value); 241 bool CrosSettings::GetList(const std::string& path,
242 const base::ListValue** out_value) const {
243 DCHECK(CalledOnValidThread());
244 const Value* value = GetPref(path);
245 if (value)
246 return value->GetAsList(out_value);
247 return false;
204 } 248 }
205 249
206 CrosSettings::CrosSettings() { 250 CrosSettings::CrosSettings() {
251 AddSettingsProvider(new ProxyCrosSettingsProvider());
252 AddSettingsProvider(new SystemSettingsProvider());
253 AddSettingsProvider(new UserCrosSettingsProvider());
207 } 254 }
208 255
209 CrosSettings::~CrosSettings() { 256 CrosSettings::~CrosSettings() {
210 DCHECK(providers_.empty()); 257 STLDeleteElements(&providers_);
211 STLDeleteValues(&settings_observers_);
212 } 258 }
213 259
214 } // namespace chromeos 260 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698