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

Unified 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: Addressed comments and issues. 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 side-by-side diff with in-line comments
Download patch
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..9d51d54f69bc67d4f7108e459d6390fc06fd1ef8 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"
@@ -17,6 +21,23 @@
namespace chromeos {
+namespace {
+
+// 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.
+base::Value* CreateSettingsValue(base::Value *value,
+ bool managed,
+ 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.
+ DictionaryValue* dict = new DictionaryValue;
+ dict->Set("value", value);
+ dict->Set("managed", Value::CreateBooleanValue(managed));
+ dict->Set("disabled", Value::CreateBooleanValue(disabled));
+ return dict;
+}
+
+} // namespace
+
static base::LazyInstance<CrosSettings> g_cros_settings(
base::LINKER_INITIALIZED);
@@ -146,69 +167,100 @@ 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);
+ NOTREACHED() << path << " preference was not found in the signed settings.";
+ return NULL;
+}
+
+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 base::Closure& 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

Powered by Google App Engine
This is Rietveld 408576698