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

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: Rebased. Created 3 years, 4 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
« no previous file with comments | « chrome/browser/ui/webui/chromeos/set_time_ui.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 71db18ff44b5aae8ae12b656c4fc548e1ba43ea2..201f458d34f3d66c0d1a4a74287b67c6300b28b8 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
@@ -26,6 +26,7 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/proxy_cros_settings_parser.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "chrome/browser/chromeos/system/timezone_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/session_controller_client.h"
#include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h"
@@ -47,20 +48,34 @@ namespace options {
namespace {
-// List of settings that should be changeable by all users.
-const char* kNonPrivilegedSettings[] = {
+// List of settings that are not changeable by users.
+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;
+ if (!chromeos::system::PerUserTimezoneEnabled()) {
+ return pref != kSystemTimezone;
+ }
+ // All the other Cros Settings are controlled.
+ return true;
+}
+
+// Returns true if |pref| is modifiable from UI.
+bool IsSettingWritable(const std::string& pref) {
+ if (!system::PerUserTimezoneEnabled())
+ return true;
+
+ 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 +215,14 @@ 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));
+ if (system::PerUserTimezoneEnabled()) {
+ const PrefService::Preference* pref =
+ primary_profile->GetPrefs()->FindPreference(pref_name);
+ dict->Set("value", base::MakeUnique<base::Value>(*pref->GetValue()));
+ } else {
+ dict->SetBoolean("value",
+ primary_profile->GetPrefs()->GetBoolean(pref_name));
+ }
return value;
}
@@ -218,7 +239,7 @@ std::unique_ptr<base::Value> CoreChromeOSOptionsHandler::FetchPref(
dict->Set("value", base::MakeUnique<base::Value>(*pref_value));
std::string controlled_by;
- if (IsSettingPrivileged(pref_name)) {
+ if (system::PerUserTimezoneEnabled() || IsSettingPrivileged(pref_name)) {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (connector->IsEnterpriseManaged())
@@ -226,9 +247,12 @@ std::unique_ptr<base::Value> CoreChromeOSOptionsHandler::FetchPref(
else if (!ProfileHelper::IsOwnerProfile(profile))
controlled_by = "owner";
}
- dict->SetBoolean("disabled", !controlled_by.empty());
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);
}
@@ -262,6 +286,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))
« no previous file with comments | « chrome/browser/ui/webui/chromeos/set_time_ui.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698