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

Unified Diff: chrome/browser/extensions/api/settings_private/prefs_util.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/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 6a274bf1c18c4c920babce47d08b7c01966813ff..782caefbfe47ad4d212fc104cd947b4fb2ce8c62 100644
--- a/chrome/browser/extensions/api/settings_private/prefs_util.cc
+++ b/chrome/browser/extensions/api/settings_private/prefs_util.cc
@@ -38,6 +38,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
@@ -48,13 +49,15 @@ 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
+ // All Cros settings are considered privileged and are either policy
// controlled or owner controlled.
return true;
}
+
+bool IsCrosSettingReadOnly(const std::string& pref_name) {
+ // System timezone is never directly changable by user.
+ return pref_name == chromeos::kSystemTimezone;
+}
#endif
} // namespace
@@ -284,7 +287,9 @@ 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;
@@ -446,6 +451,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;
@@ -458,16 +478,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()) {
@@ -520,7 +530,6 @@ std::unique_ptr<settings_private::PrefObject> PrefsUtil::GetPref(
}
// TODO(dbeam): surface !IsUserModifiable or IsPrefSupervisorControlled?
-
return pref_object;
}
@@ -651,12 +660,18 @@ bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) {
}
#if defined(OS_CHROMEOS)
+
bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) {
- if (IsPrivilegedCrosSetting(pref_name)) {
- policy::BrowserPolicyConnectorChromeOS* connector =
- g_browser_process->platform_part()->browser_policy_connector_chromeos();
- if (connector->IsEnterpriseManaged())
+ policy::BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos();
+ if (connector->IsEnterpriseManaged()) {
+ if (IsPrivilegedCrosSetting(pref_name))
return true;
+
+ if (pref_name == prefs::kUserTimezone ||
+ pref_name == prefs::kResolveTimezoneByGeolocation) {
+ return chromeos::system::IsTimezonePrefsManaged(pref_name);
+ }
}
return false;
}
@@ -670,7 +685,9 @@ bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) {
}
bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) {
- if (pref_name == prefs::kWakeOnWifiDarkConnect) {
+ if (pref_name == prefs::kWakeOnWifiDarkConnect ||
+ pref_name == prefs::kResolveTimezoneByGeolocation ||
+ pref_name == prefs::kUserTimezone) {
user_manager::UserManager* user_manager = user_manager::UserManager::Get();
const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
@@ -691,6 +708,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