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

Unified Diff: chrome/browser/extensions/api/settings_private/prefs_util.cc

Issue 2849823003: ChromeOS: implement per-user time zone preferences. (Closed)
Patch Set: Moved more code to previous CL. 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/extensions/api/settings_private/prefs_util.cc
diff --git a/chrome/browser/extensions/api/settings_private/prefs_util.cc b/chrome/browser/extensions/api/settings_private/prefs_util.cc
index 2c9b357f4048f77fc9ed8b31f0c5b27f04735d2a..538bd3bd941d4b48d4f3738a6d83f7ccd1221cb4 100644
--- a/chrome/browser/extensions/api/settings_private/prefs_util.cc
+++ b/chrome/browser/extensions/api/settings_private/prefs_util.cc
@@ -39,6 +39,7 @@
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "chrome/browser/chromeos/system/timezone_util.h"
#include "chromeos/settings/cros_settings_names.h"
#include "ui/chromeos/events/pref_names.h"
#endif
@@ -49,13 +50,25 @@ namespace {
bool IsPrivilegedCrosSetting(const std::string& pref_name) {
if (!chromeos::CrosSettings::IsCrosSettings(pref_name))
return false;
- // kSystemTimezone should be changeable by all users.
- if (pref_name == chromeos::kSystemTimezone)
- return false;
- // All other Cros settings are considered privileged and are either policy
+ if (!chromeos::system::PerUserTimezoneEnabled()) {
+ // kSystemTimezone should be changeable by all users.
+ if (pref_name == chromeos::kSystemTimezone)
+ return false;
+ // All other Cros settings are considered privileged and are either policy
+ // controlled or owner controlled.
+ }
+ // All Cros settings are considered privileged and are either policy
// controlled or owner controlled.
return true;
}
+
+bool IsCrosSettingReadOnly(const std::string& pref_name) {
+ if (chromeos::system::PerUserTimezoneEnabled()) {
+ // System timezone is never directly changable by user.
+ return pref_name == chromeos::kSystemTimezone;
+ }
+ return false;
+}
#endif
} // namespace
@@ -289,9 +302,13 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
// Timezone settings.
(*s_whitelist)[chromeos::kSystemTimezone] =
- settings_private::PrefType::PREF_TYPE_BOOLEAN;
+ settings_private::PrefType::PREF_TYPE_STRING;
+ (*s_whitelist)[prefs::kUserTimezone] =
+ settings_private::PrefType::PREF_TYPE_STRING;
(*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] =
settings_private::PrefType::PREF_TYPE_BOOLEAN;
+ (*s_whitelist)[chromeos::kPerUserTimezoneEnabled] =
+ settings_private::PrefType::PREF_TYPE_BOOLEAN;
// Ash settings.
(*s_whitelist)[::prefs::kEnableStylusTools] =
@@ -457,6 +474,21 @@ std::unique_ptr<settings_private::PrefObject> PrefsUtil::GetPref(
}
#if defined(OS_CHROMEOS)
+ // We first check for enterprise-managed, then for primary-user managed.
+ // Otherwise in multiprofile mode enterprise preference for the secondary
+ // user will appear primary-user-controlled, which looks strange, because
+ // primary user preference will be disabled with "enterprise controlled"
+ // status.
+ if (IsPrefEnterpriseManaged(name)) {
+ // Enterprise managed prefs are treated the same as device policy restricted
+ // prefs in the UI.
+ pref_object->controlled_by =
+ settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY;
+ pref_object->enforcement =
+ settings_private::Enforcement::ENFORCEMENT_ENFORCED;
+ return pref_object;
+ }
+
if (IsPrefPrimaryUserControlled(name)) {
pref_object->controlled_by =
settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER;
@@ -469,16 +501,6 @@ std::unique_ptr<settings_private::PrefObject> PrefsUtil::GetPref(
.GetUserEmail()));
return pref_object;
}
-
- if (IsPrefEnterpriseManaged(name)) {
- // Enterprise managed prefs are treated the same as device policy restricted
- // prefs in the UI.
- pref_object->controlled_by =
- settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY;
- pref_object->enforcement =
- settings_private::Enforcement::ENFORCEMENT_ENFORCED;
- return pref_object;
- }
#endif
if (pref && pref->IsManaged()) {
@@ -664,16 +686,36 @@ bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) {
#if defined(OS_CHROMEOS)
bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) {
- if (IsPrivilegedCrosSetting(pref_name)) {
+ if (chromeos::system::PerUserTimezoneEnabled()) {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
- if (connector->IsEnterpriseManaged())
- return true;
+ if (connector->IsEnterpriseManaged()) {
+ if (IsPrivilegedCrosSetting(pref_name))
+ return true;
stevenjb 2017/05/25 22:13:06 In the interest of readability, can we do this che
Alexander Alekseev 2017/05/29 21:10:23 Done.
+
+ if (pref_name == prefs::kUserTimezone ||
+ pref_name == prefs::kResolveTimezoneByGeolocation) {
+ return chromeos::system::IsTimezonePrefsManaged(pref_name);
+ }
+ }
+ } else {
+ if (IsPrivilegedCrosSetting(pref_name)) {
+ policy::BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()
+ ->browser_policy_connector_chromeos();
+ if (connector->IsEnterpriseManaged())
+ return true;
+ }
}
return false;
}
bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) {
+ // chromeos::kSystemTimezone is global display-only preference and
+ // it should appear as disabled, but not owned.
+ if (pref_name == chromeos::kSystemTimezone)
+ return false;
+
if (IsPrivilegedCrosSetting(pref_name)) {
if (!chromeos::ProfileHelper::IsOwnerProfile(profile_))
return true;
@@ -682,13 +724,19 @@ bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) {
}
bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) {
- if (pref_name == prefs::kWakeOnWifiDarkConnect) {
+ // chromeos::kSystemTimezone is read-only, but for the non-primary users
+ // it should have "primary user controlled" attribute.
+ if (pref_name == prefs::kWakeOnWifiDarkConnect ||
+ pref_name == prefs::kResolveTimezoneByGeolocation ||
+ pref_name == prefs::kUserTimezone ||
+ pref_name == chromeos::kSystemTimezone) {
user_manager::UserManager* user_manager = user_manager::UserManager::Get();
const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
- if (user &&
- user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId())
+ if (user && user->GetAccountId() !=
+ user_manager->GetPrimaryUser()->GetAccountId()) {
return true;
+ }
}
return false;
}
@@ -703,6 +751,11 @@ bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) {
}
bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) {
+#if defined(OS_CHROMEOS)
+ if (IsCrosSettingReadOnly(pref_name))
+ return false;
+#endif
+
const PrefService::Preference* profile_pref =
profile_->GetPrefs()->FindPreference(pref_name);
if (profile_pref)

Powered by Google App Engine
This is Rietveld 408576698