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

Unified Diff: chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc

Issue 7867044: PART1: Initiated the SignedSettings refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments from Chris and rebased to ToT to get it running on the try servers again. Created 9 years, 2 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/ui/webui/options/chromeos/core_chromeos_options_handler.cc
diff --git a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc
index 295b834849a0fab0b711d9183b00e6b794d5f952..f172a87c3c222c83f482bd1cddf0a47fa1a5b28f 100644
--- a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc
@@ -8,7 +8,10 @@
#include "base/string_number_conversions.h"
#include "base/string_util.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/cros_settings.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/browser/user_metrics.h"
#include "content/common/notification_details.h"
@@ -16,35 +19,89 @@
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) {
+ DictionaryValue* dict = new DictionaryValue;
+ dict->Set("value", value);
+ dict->Set("managed", base::Value::CreateBooleanValue(managed));
+ dict->Set("disabled", base::Value::CreateBooleanValue(disabled));
+ return dict;
+}
+
+// This function decorates the bare list of emails with some more information
+// needed by the UI to properly display the Accounts page.
+base::Value* CreateUsersWhitelist(const base::Value *pref_value) {
+ const base::ListValue *list_value =
+ static_cast<const base::ListValue*>(pref_value);
+ base::ListValue *user_list = new base::ListValue();
+
+ const UserManager::User& self = UserManager::Get()->logged_in_user();
+ bool is_owner = UserManager::Get()->current_user_is_owner();
+
+ for (base::ListValue::const_iterator i = list_value->begin();
+ i != list_value->end(); ++i) {
+ std::string email;
+ if ((*i)->GetAsString(&email)) {
+ DictionaryValue* user = new DictionaryValue;
+ user->SetString("email", email);
+ user->SetString("name", "");
+ user->SetBoolean("owner", is_owner && email == self.email());
+ user_list->Append(user);
+ }
+ }
+ return user_list;
+}
+
+} // namespace
+
CoreChromeOSOptionsHandler::CoreChromeOSOptionsHandler()
: handling_change_(false) {
}
-Value* CoreChromeOSOptionsHandler::FetchPref(const std::string& pref_name) {
+base::Value* CoreChromeOSOptionsHandler::FetchPref(
+ const std::string& pref_name) {
if (!CrosSettings::IsCrosSettings(pref_name))
return ::CoreOptionsHandler::FetchPref(pref_name);
- Value* pref_value = NULL;
- CrosSettings::Get()->Get(pref_name, &pref_value);
- return pref_value ? pref_value : Value::CreateNullValue();
+ const base::Value* pref_value =
+ CrosSettings::Get()->GetPref(pref_name);
+ if (!pref_value)
+ return base::Value::CreateNullValue();
+
+ // Lists don't get the standard pref decoration.
+ if (pref_value->GetType() == base::Value::TYPE_LIST) {
+ if (pref_name == kAccountsPrefUsers)
+ return CreateUsersWhitelist(pref_value);
+ return pref_value->DeepCopy();
+ }
+ // All other prefs are decorated the same way.
+ return CreateSettingsValue(
+ pref_value->DeepCopy(),
+ g_browser_process->browser_policy_connector()->IsEnterpriseManaged(),
+ !UserManager::Get()->current_user_is_owner());
}
void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) {
if (!CrosSettings::IsCrosSettings(pref_name))
return ::CoreOptionsHandler::ObservePref(pref_name);
- // TODO(xiyuan): Change this when CrosSettings supports observers.
CrosSettings::Get()->AddSettingsObserver(pref_name.c_str(), this);
}
void CoreChromeOSOptionsHandler::SetPref(const std::string& pref_name,
- const Value* value,
+ const base::Value* value,
const std::string& metric) {
if (!CrosSettings::IsCrosSettings(pref_name))
return ::CoreOptionsHandler::SetPref(pref_name, value, metric);
handling_change_ = true;
// CrosSettings takes ownership of its value so we need to copy it.
- Value* pref_value = value->DeepCopy();
+ base::Value* pref_value = value->DeepCopy();
CrosSettings::Get()->Set(pref_name, pref_value);
handling_change_ = false;
@@ -76,11 +133,9 @@ void CoreChromeOSOptionsHandler::NotifySettingsChanged(
const std::string* setting_name) {
DCHECK(web_ui_);
DCHECK(CrosSettings::Get()->IsCrosSettings(*setting_name));
- Value* value = NULL;
- if (!CrosSettings::Get()->Get(*setting_name, &value)) {
+ const base::Value* value = CrosSettings::Get()->GetPref(*setting_name);
+ if (!value) {
NOTREACHED();
- if (value)
- delete value;
return;
}
for (PreferenceCallbackMap::const_iterator iter =
@@ -93,8 +148,6 @@ void CoreChromeOSOptionsHandler::NotifySettingsChanged(
web_ui_->CallJavascriptFunction(WideToASCII(callback_function),
result_value);
}
- if (value)
- delete value;
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698