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

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

Issue 2849823003: ChromeOS: implement per-user time zone preferences. (Closed)
Patch Set: Try remove g_browser_process check Created 3 years, 7 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 b21df5fcf9db1b6d07d9a6f31eee268b06bc5be3..63203cbc2b5e676c59619a0411ade3e8d2081c27 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
@@ -48,19 +48,21 @@ namespace options {
namespace {
// List of settings that should be changeable by all users.
-const char* kNonPrivilegedSettings[] = {
+const char* kReadOnlySettings[] = {
kSystemTimezone
};
// List of settings that should only be changeable by the primary user.
const char* kPrimaryUserSettings[] = {
prefs::kWakeOnWifiDarkConnect,
+ prefs::kUserTimezone,
+ prefs::kResolveTimezoneByGeolocation
};
// Returns true if |pref| can be controlled (e.g. by policy or owner).
-bool IsSettingPrivileged(const std::string& pref) {
- const char** end = kNonPrivilegedSettings + arraysize(kNonPrivilegedSettings);
- return std::find(kNonPrivilegedSettings, end, pref) == end;
+bool IsSettingWritable(const std::string& pref) {
+ const char** end = kReadOnlySettings + arraysize(kReadOnlySettings);
+ return std::find(kReadOnlySettings, end, pref) == end;
}
// Returns true if |pref| is shared (controlled by the primary user).
@@ -200,8 +202,9 @@ std::unique_ptr<base::Value> CoreChromeOSOptionsHandler::FetchPref(
return value;
dict->SetString("controlledBy", "shared");
dict->SetBoolean("disabled", true);
- dict->SetBoolean("value", primary_profile->GetPrefs()->GetBoolean(
- pref_name));
+ const PrefService::Preference* pref =
+ primary_profile->GetPrefs()->FindPreference(pref_name);
+ dict->Set("value", base::MakeUnique<base::Value>(*pref->GetValue()));
return value;
}
@@ -218,17 +221,18 @@ std::unique_ptr<base::Value> CoreChromeOSOptionsHandler::FetchPref(
dict->Set("value", base::MakeUnique<base::Value>(*pref_value));
std::string controlled_by;
- if (IsSettingPrivileged(pref_name)) {
- policy::BrowserPolicyConnectorChromeOS* connector =
- g_browser_process->platform_part()->browser_policy_connector_chromeos();
- if (connector->IsEnterpriseManaged())
- controlled_by = "policy";
- else if (!ProfileHelper::IsOwnerProfile(profile))
- controlled_by = "owner";
- }
- dict->SetBoolean("disabled", !controlled_by.empty());
+ policy::BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos();
+ if (connector->IsEnterpriseManaged())
+ controlled_by = "policy";
+ else if (!ProfileHelper::IsOwnerProfile(profile))
+ controlled_by = "owner";
if (!controlled_by.empty())
dict->SetString("controlledBy", controlled_by);
+
+ // Read-only setting is always disabled.
+ dict->SetBoolean("disabled",
+ !controlled_by.empty() || !IsSettingWritable(pref_name));
return std::move(dict);
}
@@ -263,6 +267,10 @@ void CoreChromeOSOptionsHandler::SetPref(const std::string& pref_name,
}
if (!CrosSettings::IsCrosSettings(pref_name))
return ::options::CoreOptionsHandler::SetPref(pref_name, value, metric);
+ if (!IsSettingWritable(pref_name)) {
+ NOTREACHED() << pref_name;
+ return;
+ }
OwnerSettingsServiceChromeOS* service =
OwnerSettingsServiceChromeOS::FromWebUI(web_ui());
if (service && service->HandlesSetting(pref_name))

Powered by Google App Engine
This is Rietveld 408576698