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 |
20 static base::LazyInstance<CrosSettings> g_cros_settings( | 24 static base::LazyInstance<CrosSettings> g_cros_settings( |
21 base::LINKER_INITIALIZED); | 25 base::LINKER_INITIALIZED); |
22 | 26 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 return; | 143 return; |
140 } | 144 } |
141 | 145 |
142 NotificationObserverList* observer_list = observer_iterator->second; | 146 NotificationObserverList* observer_list = observer_iterator->second; |
143 observer_list->RemoveObserver(obs); | 147 observer_list->RemoveObserver(obs); |
144 } | 148 } |
145 | 149 |
146 CrosSettingsProvider* CrosSettings::GetProvider( | 150 CrosSettingsProvider* CrosSettings::GetProvider( |
147 const std::string& path) const { | 151 const std::string& path) const { |
148 for (size_t i = 0; i < providers_.size(); ++i) { | 152 for (size_t i = 0; i < providers_.size(); ++i) { |
149 if (providers_[i]->HandlesSetting(path)) { | 153 if (providers_[i]->HandlesSetting(path)) |
150 return providers_[i]; | 154 return providers_[i]; |
151 } | |
152 } | 155 } |
153 return NULL; | 156 return NULL; |
154 } | 157 } |
155 | 158 |
156 bool CrosSettings::Get(const std::string& path, Value** out_value) const { | 159 const base::Value* CrosSettings::GetPref(const std::string& path) const { |
157 DCHECK(CalledOnValidThread()); | 160 DCHECK(CalledOnValidThread()); |
158 CrosSettingsProvider* provider; | 161 CrosSettingsProvider* provider; |
159 provider = GetProvider(path); | 162 provider = GetProvider(path); |
160 if (provider) { | 163 if (provider) |
161 return provider->Get(path, out_value); | 164 return provider->Get(path); |
165 return NULL; | |
166 } | |
167 | |
168 // Create a settings value with "managed" and "disabled" property. | |
169 // "managed" property is true if the setting is managed by administrator. | |
170 // "disabled" property is true if the UI for the setting should be disabled. | |
171 Value* CreateSettingsValue(Value *value, bool managed, bool disabled) { | |
172 DictionaryValue* dict = new DictionaryValue; | |
173 dict->Set("value", value); | |
174 dict->Set("managed", Value::CreateBooleanValue(managed)); | |
175 dict->Set("disabled", Value::CreateBooleanValue(disabled)); | |
176 return dict; | |
177 } | |
178 | |
179 bool CrosSettings::Get(const std::string& path, Value** out_value) const { | |
180 DCHECK(CalledOnValidThread()); | |
181 const Value* pref_value = GetPref(path); | |
182 if (pref_value) { | |
183 *out_value = CreateSettingsValue( | |
Mattias Nissler (ping if slow)
2011/09/21 11:12:59
It seems like wrapping stuff in a DictionaryValue
pastarmovj
2011/09/23 15:19:32
True but this function is being used by the UI and
Mattias Nissler (ping if slow)
2011/09/26 17:26:37
If the UI needs this then why can't the UI impleme
| |
184 pref_value->DeepCopy(), | |
185 g_browser_process->browser_policy_connector()->IsEnterpriseManaged(), | |
Mattias Nissler (ping if slow)
2011/09/21 11:12:59
I dislike the global here, it complicates testing.
| |
186 !UserManager::Get()->current_user_is_owner()); | |
187 return true; | |
162 } | 188 } |
163 return false; | 189 return false; |
164 } | 190 } |
165 | 191 |
192 bool CrosSettings::GetTrusted( | |
193 const std::string& path, | |
194 const CrosSettingsProvider::Callback& callback) const { | |
195 DCHECK(CalledOnValidThread()); | |
196 CrosSettingsProvider* provider; | |
197 provider = GetProvider(path); | |
198 if (provider) | |
199 return provider->GetTrusted(path, callback); | |
200 NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path; | |
201 return false; | |
202 } | |
203 | |
166 bool CrosSettings::GetBoolean(const std::string& path, | 204 bool CrosSettings::GetBoolean(const std::string& path, |
167 bool* bool_value) const { | 205 bool* bool_value) const { |
168 DCHECK(CalledOnValidThread()); | 206 DCHECK(CalledOnValidThread()); |
169 Value* value; | 207 const Value* value = GetPref(path); |
Mattias Nissler (ping if slow)
2011/09/21 11:12:59
value is leaked (also below)
pastarmovj
2011/09/23 15:19:32
It would has been leaking if we used the Get funct
| |
170 if (!Get(path, &value)) | 208 if (value) |
171 return false; | 209 return value->GetAsBoolean(bool_value); |
Mattias Nissler (ping if slow)
2011/09/21 11:12:59
indentation (also below)
pastarmovj
2011/09/23 15:19:32
Done.
| |
172 | 210 return false; |
173 return value->GetAsBoolean(bool_value); | |
174 } | 211 } |
175 | 212 |
176 bool CrosSettings::GetInteger(const std::string& path, | 213 bool CrosSettings::GetInteger(const std::string& path, |
177 int* out_value) const { | 214 int* out_value) const { |
178 DCHECK(CalledOnValidThread()); | 215 DCHECK(CalledOnValidThread()); |
179 Value* value; | 216 const Value* value = GetPref(path); |
180 if (!Get(path, &value)) | 217 if (value) |
181 return false; | 218 return value->GetAsInteger(out_value); |
182 | 219 return false; |
183 return value->GetAsInteger(out_value); | |
184 } | 220 } |
185 | 221 |
186 bool CrosSettings::GetDouble(const std::string& path, | 222 bool CrosSettings::GetDouble(const std::string& path, |
187 double* out_value) const { | 223 double* out_value) const { |
188 DCHECK(CalledOnValidThread()); | 224 DCHECK(CalledOnValidThread()); |
189 Value* value; | 225 const Value* value = GetPref(path); |
190 if (!Get(path, &value)) | 226 if (value) |
191 return false; | 227 return value->GetAsDouble(out_value); |
192 | 228 return false; |
193 return value->GetAsDouble(out_value); | |
194 } | 229 } |
195 | 230 |
196 bool CrosSettings::GetString(const std::string& path, | 231 bool CrosSettings::GetString(const std::string& path, |
197 std::string* out_value) const { | 232 std::string* out_value) const { |
198 DCHECK(CalledOnValidThread()); | 233 DCHECK(CalledOnValidThread()); |
199 Value* value; | 234 const Value* value = GetPref(path); |
200 if (!Get(path, &value)) | 235 if (value) |
201 return false; | 236 return value->GetAsString(out_value); |
237 return false; | |
238 } | |
202 | 239 |
203 return value->GetAsString(out_value); | 240 bool CrosSettings::GetList(const std::string& path, |
241 const base::ListValue** out_value) const { | |
242 DCHECK(CalledOnValidThread()); | |
243 const Value* value = GetPref(path); | |
244 if (value) | |
245 return value->GetAsList(out_value); | |
246 return false; | |
204 } | 247 } |
205 | 248 |
206 CrosSettings::CrosSettings() { | 249 CrosSettings::CrosSettings() { |
250 AddSettingsProvider(new ProxyCrosSettingsProvider()); | |
251 AddSettingsProvider(new SystemSettingsProvider()); | |
252 AddSettingsProvider(new UserCrosSettingsProvider()); | |
207 } | 253 } |
208 | 254 |
209 CrosSettings::~CrosSettings() { | 255 CrosSettings::~CrosSettings() { |
210 DCHECK(providers_.empty()); | 256 STLDeleteElements(&providers_); |
211 STLDeleteValues(&settings_observers_); | |
212 } | 257 } |
213 | 258 |
214 } // namespace chromeos | 259 } // namespace chromeos |
OLD | NEW |