Chromium Code Reviews| Index: chrome/browser/chromeos/cros_settings.cc |
| diff --git a/chrome/browser/chromeos/cros_settings.cc b/chrome/browser/chromeos/cros_settings.cc |
| index 31e42865818a0b89e60898413561136465eb46a7..13e60c7c5e17fb530293a2dcce4c4101c3ef12d7 100644 |
| --- a/chrome/browser/chromeos/cros_settings.cc |
| +++ b/chrome/browser/chromeos/cros_settings.cc |
| @@ -5,11 +5,14 @@ |
| #include "chrome/browser/chromeos/cros_settings.h" |
| #include "base/lazy_instance.h" |
| -#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
|
| #include "base/string_util.h" |
| #include "base/values.h" |
| -#include "chrome/browser/chromeos/cros_settings_provider.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chromeos/login/user_manager.h" |
| +#include "chrome/browser/chromeos/proxy_cros_settings_provider.h" |
| #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
| +#include "chrome/browser/policy/browser_policy_connector.h" |
| +#include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "content/common/content_notification_types.h" |
| #include "content/common/notification_details.h" |
| @@ -153,62 +156,105 @@ CrosSettingsProvider* CrosSettings::GetProvider( |
| return NULL; |
| } |
| -bool CrosSettings::Get(const std::string& path, Value** out_value) const { |
| +const base::Value* CrosSettings::GetPref(const std::string& path) const { |
| DCHECK(CalledOnValidThread()); |
| CrosSettingsProvider* provider; |
| provider = GetProvider(path); |
| 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.
|
| - return provider->Get(path, out_value); |
| + return provider->Get(path); |
| } |
| return false; |
|
pastarmovj
2011/09/20 17:11:52
And this should be NULL. Baaad copy/paste.
|
| } |
| +// Create a settings value with "managed" and "disabled" property. |
| +// "managed" property is true if the setting is managed by administrator. |
| +// "disabled" property is true if the UI for the setting should be disabled. |
| +Value* CreateSettingsValue(Value *value, bool managed, bool disabled) { |
| + DictionaryValue* dict = new DictionaryValue; |
| + dict->Set("value", value); |
| + dict->Set("managed", Value::CreateBooleanValue(managed)); |
| + dict->Set("disabled", Value::CreateBooleanValue(disabled)); |
| + return dict; |
| +} |
| + |
| +bool CrosSettings::Get(const std::string& path, Value** out_value) const { |
| + DCHECK(CalledOnValidThread()); |
| + const Value* pref_value = GetPref(path); |
| + if (pref_value) { |
| + *out_value = CreateSettingsValue( |
| + pref_value->DeepCopy(), |
| + g_browser_process->browser_policy_connector()->IsEnterpriseManaged(), |
| + !UserManager::Get()->current_user_is_owner()); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +bool CrosSettings::GetTrusted( |
| + const std::string& path, |
| + const CrosSettingsProvider::Callback& callback) const { |
| + DCHECK(CalledOnValidThread()); |
| + CrosSettingsProvider* provider; |
| + provider = GetProvider(path); |
| + if (provider) |
| + return provider->GetTrusted(path, callback); |
| + NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path; |
| + return false; |
| +} |
| + |
| bool CrosSettings::GetBoolean(const std::string& path, |
| bool* bool_value) const { |
| DCHECK(CalledOnValidThread()); |
| - Value* value; |
| - if (!Get(path, &value)) |
| - return false; |
| - |
| - return value->GetAsBoolean(bool_value); |
| + const Value* value = GetPref(path); |
| + if (value) |
| + return value->GetAsBoolean(bool_value); |
| + return false; |
| } |
| bool CrosSettings::GetInteger(const std::string& path, |
| int* out_value) const { |
| DCHECK(CalledOnValidThread()); |
| - Value* value; |
| - if (!Get(path, &value)) |
| - return false; |
| - |
| - return value->GetAsInteger(out_value); |
| + const Value* value = GetPref(path); |
| + if (value) |
| + return value->GetAsInteger(out_value); |
| + return false; |
| } |
| bool CrosSettings::GetDouble(const std::string& path, |
| double* out_value) const { |
| DCHECK(CalledOnValidThread()); |
| - Value* value; |
| - if (!Get(path, &value)) |
| - return false; |
| - |
| - return value->GetAsDouble(out_value); |
| + const Value* value = GetPref(path); |
| + if (value) |
| + return value->GetAsDouble(out_value); |
| + return false; |
| } |
| bool CrosSettings::GetString(const std::string& path, |
| std::string* out_value) const { |
| DCHECK(CalledOnValidThread()); |
| - Value* value; |
| - if (!Get(path, &value)) |
| - return false; |
| + const Value* value = GetPref(path); |
| + if (value) |
| + return value->GetAsString(out_value); |
| + return false; |
| +} |
| - return value->GetAsString(out_value); |
| +bool CrosSettings::GetList(const std::string& path, |
| + const base::ListValue** out_value) const { |
| + DCHECK(CalledOnValidThread()); |
| + const Value* value = GetPref(path); |
| + if (value) |
| + return value->GetAsList(out_value); |
| + return false; |
| } |
| CrosSettings::CrosSettings() { |
| + AddSettingsProvider(new ProxyCrosSettingsProvider()); |
| + AddSettingsProvider(new SystemSettingsProvider()); |
| + AddSettingsProvider(new UserCrosSettingsProvider()); |
| } |
| CrosSettings::~CrosSettings() { |
| - DCHECK(providers_.empty()); |
| - STLDeleteValues(&settings_observers_); |
| + STLDeleteElements(&providers_); |
| } |
| } // namespace chromeos |