OLD | NEW |
---|---|
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/browser_process.h" |
12 #include "chrome/browser/chromeos/login/user_manager.h" | |
13 #include "chrome/browser/chromeos/proxy_cros_settings_provider.h" | |
12 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 14 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
15 #include "chrome/browser/policy/browser_policy_connector.h" | |
16 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h" | |
13 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
14 #include "content/common/content_notification_types.h" | 18 #include "content/common/content_notification_types.h" |
15 #include "content/common/notification_details.h" | 19 #include "content/common/notification_details.h" |
16 #include "content/common/notification_source.h" | 20 #include "content/common/notification_source.h" |
17 | 21 |
18 namespace chromeos { | 22 namespace chromeos { |
19 | 23 |
24 namespace { | |
25 | |
26 // Create a settings value with "managed" and "disabled" property. | |
27 // "managed" property is true if the setting is managed by administrator. | |
28 // "disabled" property is true if the UI for the setting should be disabled. | |
29 base::Value* CreateSettingsValue(base::Value *value, | |
30 bool managed, | |
31 bool disabled) { | |
Mattias Nissler (ping if slow)
2011/09/26 17:26:37
As commented in reply to a previous comment, can't
pastarmovj
2011/09/29 15:15:03
Done.
| |
32 DictionaryValue* dict = new DictionaryValue; | |
33 dict->Set("value", value); | |
34 dict->Set("managed", Value::CreateBooleanValue(managed)); | |
35 dict->Set("disabled", Value::CreateBooleanValue(disabled)); | |
36 return dict; | |
37 } | |
38 | |
39 } // namespace | |
40 | |
20 static base::LazyInstance<CrosSettings> g_cros_settings( | 41 static base::LazyInstance<CrosSettings> g_cros_settings( |
21 base::LINKER_INITIALIZED); | 42 base::LINKER_INITIALIZED); |
22 | 43 |
23 CrosSettings* CrosSettings::Get() { | 44 CrosSettings* CrosSettings::Get() { |
24 // TODO(xiyaun): Use real stuff when underlying libcros is ready. | 45 // TODO(xiyaun): Use real stuff when underlying libcros is ready. |
25 return g_cros_settings.Pointer(); | 46 return g_cros_settings.Pointer(); |
26 } | 47 } |
27 | 48 |
28 bool CrosSettings::IsCrosSettings(const std::string& path) { | 49 bool CrosSettings::IsCrosSettings(const std::string& path) { |
29 return StartsWithASCII(path, kCrosSettingsPrefix, true); | 50 return StartsWithASCII(path, kCrosSettingsPrefix, true); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 return; | 160 return; |
140 } | 161 } |
141 | 162 |
142 NotificationObserverList* observer_list = observer_iterator->second; | 163 NotificationObserverList* observer_list = observer_iterator->second; |
143 observer_list->RemoveObserver(obs); | 164 observer_list->RemoveObserver(obs); |
144 } | 165 } |
145 | 166 |
146 CrosSettingsProvider* CrosSettings::GetProvider( | 167 CrosSettingsProvider* CrosSettings::GetProvider( |
147 const std::string& path) const { | 168 const std::string& path) const { |
148 for (size_t i = 0; i < providers_.size(); ++i) { | 169 for (size_t i = 0; i < providers_.size(); ++i) { |
149 if (providers_[i]->HandlesSetting(path)) { | 170 if (providers_[i]->HandlesSetting(path)) |
150 return providers_[i]; | 171 return providers_[i]; |
151 } | |
152 } | 172 } |
153 return NULL; | 173 return NULL; |
154 } | 174 } |
155 | 175 |
176 const base::Value* CrosSettings::GetPref(const std::string& path) const { | |
177 DCHECK(CalledOnValidThread()); | |
178 CrosSettingsProvider* provider; | |
179 provider = GetProvider(path); | |
180 if (provider) | |
181 return provider->Get(path); | |
182 NOTREACHED() << path << " preference was not found in the signed settings."; | |
183 return NULL; | |
184 } | |
185 | |
156 bool CrosSettings::Get(const std::string& path, Value** out_value) const { | 186 bool CrosSettings::Get(const std::string& path, Value** out_value) const { |
157 DCHECK(CalledOnValidThread()); | 187 DCHECK(CalledOnValidThread()); |
188 const Value* pref_value = GetPref(path); | |
189 if (pref_value) { | |
190 *out_value = CreateSettingsValue( | |
191 pref_value->DeepCopy(), | |
192 g_browser_process->browser_policy_connector()->IsEnterpriseManaged(), | |
193 !UserManager::Get()->current_user_is_owner()); | |
194 return true; | |
195 } | |
196 return false; | |
197 } | |
198 | |
199 bool CrosSettings::GetTrusted( | |
200 const std::string& path, | |
201 const base::Closure& callback) const { | |
202 DCHECK(CalledOnValidThread()); | |
158 CrosSettingsProvider* provider; | 203 CrosSettingsProvider* provider; |
159 provider = GetProvider(path); | 204 provider = GetProvider(path); |
160 if (provider) { | 205 if (provider) |
161 return provider->Get(path, out_value); | 206 return provider->GetTrusted(path, callback); |
162 } | 207 NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path; |
163 return false; | 208 return false; |
164 } | 209 } |
165 | 210 |
166 bool CrosSettings::GetBoolean(const std::string& path, | 211 bool CrosSettings::GetBoolean(const std::string& path, |
167 bool* bool_value) const { | 212 bool* bool_value) const { |
168 DCHECK(CalledOnValidThread()); | 213 DCHECK(CalledOnValidThread()); |
169 Value* value; | 214 const Value* value = GetPref(path); |
170 if (!Get(path, &value)) | 215 if (value) |
171 return false; | 216 return value->GetAsBoolean(bool_value); |
172 | 217 return false; |
173 return value->GetAsBoolean(bool_value); | |
174 } | 218 } |
175 | 219 |
176 bool CrosSettings::GetInteger(const std::string& path, | 220 bool CrosSettings::GetInteger(const std::string& path, |
177 int* out_value) const { | 221 int* out_value) const { |
178 DCHECK(CalledOnValidThread()); | 222 DCHECK(CalledOnValidThread()); |
179 Value* value; | 223 const Value* value = GetPref(path); |
180 if (!Get(path, &value)) | 224 if (value) |
181 return false; | 225 return value->GetAsInteger(out_value); |
182 | 226 return false; |
183 return value->GetAsInteger(out_value); | |
184 } | 227 } |
185 | 228 |
186 bool CrosSettings::GetDouble(const std::string& path, | 229 bool CrosSettings::GetDouble(const std::string& path, |
187 double* out_value) const { | 230 double* out_value) const { |
188 DCHECK(CalledOnValidThread()); | 231 DCHECK(CalledOnValidThread()); |
189 Value* value; | 232 const Value* value = GetPref(path); |
190 if (!Get(path, &value)) | 233 if (value) |
191 return false; | 234 return value->GetAsDouble(out_value); |
192 | 235 return false; |
193 return value->GetAsDouble(out_value); | |
194 } | 236 } |
195 | 237 |
196 bool CrosSettings::GetString(const std::string& path, | 238 bool CrosSettings::GetString(const std::string& path, |
197 std::string* out_value) const { | 239 std::string* out_value) const { |
198 DCHECK(CalledOnValidThread()); | 240 DCHECK(CalledOnValidThread()); |
199 Value* value; | 241 const Value* value = GetPref(path); |
200 if (!Get(path, &value)) | 242 if (value) |
201 return false; | 243 return value->GetAsString(out_value); |
244 return false; | |
245 } | |
202 | 246 |
203 return value->GetAsString(out_value); | 247 bool CrosSettings::GetList(const std::string& path, |
248 const base::ListValue** out_value) const { | |
249 DCHECK(CalledOnValidThread()); | |
250 const Value* value = GetPref(path); | |
251 if (value) | |
252 return value->GetAsList(out_value); | |
253 return false; | |
204 } | 254 } |
205 | 255 |
206 CrosSettings::CrosSettings() { | 256 CrosSettings::CrosSettings() { |
257 AddSettingsProvider(new ProxyCrosSettingsProvider()); | |
258 AddSettingsProvider(new SystemSettingsProvider()); | |
259 AddSettingsProvider(new UserCrosSettingsProvider()); | |
207 } | 260 } |
208 | 261 |
209 CrosSettings::~CrosSettings() { | 262 CrosSettings::~CrosSettings() { |
210 DCHECK(providers_.empty()); | 263 STLDeleteElements(&providers_); |
211 STLDeleteValues(&settings_observers_); | |
212 } | 264 } |
213 | 265 |
214 } // namespace chromeos | 266 } // namespace chromeos |
OLD | NEW |