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..b94aba0bc1a71c5953a58b02422f15d4de384839 100644 |
| --- a/chrome/browser/chromeos/cros_settings.cc |
| +++ b/chrome/browser/chromeos/cros_settings.cc |
| @@ -8,8 +8,12 @@ |
| #include "base/stl_util.h" |
| #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" |
| @@ -146,69 +150,110 @@ void CrosSettings::RemoveSettingsObserver(const char* path, |
| CrosSettingsProvider* CrosSettings::GetProvider( |
| const std::string& path) const { |
| for (size_t i = 0; i < providers_.size(); ++i) { |
| - if (providers_[i]->HandlesSetting(path)) { |
| + if (providers_[i]->HandlesSetting(path)) |
| return providers_[i]; |
| - } |
| } |
| 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) { |
| - return provider->Get(path, out_value); |
| + if (provider) |
| + return provider->Get(path); |
| + return NULL; |
| +} |
| + |
| +// 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( |
|
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
|
| + pref_value->DeepCopy(), |
| + 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.
|
| + !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); |
|
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
|
| + if (value) |
| + 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.
|
| + 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 |