Chromium Code Reviews| 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..87a4d6b26e21a6696f70b668c5db3ed55c7346af 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 |
| @@ -45,16 +46,26 @@ |
| namespace { |
| #if defined(OS_CHROMEOS) |
| +const size_t primary_user_prefs_len = 4; |
| +const char* const primary_user_prefs[primary_user_prefs_len] = { |
| + prefs::kResolveTimezoneByGeolocation, |
| + prefs::kUserTimezone, |
| + prefs::kWakeOnWifiDarkConnect, |
| + prefs::kWakeOnWifiDarkConnect |
| +}; |
|
stevenjb
2017/05/15 17:08:02
const char* const primary_user_prefs[] = {
...
};
Alexander Alekseev
2017/05/16 01:11:56
Done.
|
| + |
| 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 +295,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 +459,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 +486,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 +538,6 @@ std::unique_ptr<settings_private::PrefObject> PrefsUtil::GetPref( |
| } |
| // TODO(dbeam): surface !IsUserModifiable or IsPrefSupervisorControlled? |
| - |
| return pref_object; |
| } |
| @@ -651,12 +668,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::IfTimezonePrefsmanaged(pref_name); |
| + } |
| } |
| return false; |
| } |
| @@ -670,14 +693,16 @@ bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { |
| } |
| bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { |
| - if (pref_name == prefs::kWakeOnWifiDarkConnect) { |
| - 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()) |
| - return true; |
| - } |
| + const char* const* end = primary_user_prefs + primary_user_prefs_len; |
| + if (std::find(primary_user_prefs, end, pref_name) == end) |
| + return false; |
|
stevenjb
2017/05/15 17:08:02
Since this appears to be the only place we use |pr
Alexander Alekseev
2017/05/16 01:11:56
Done.
|
| + |
| + user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| + const user_manager::User* user = |
| + chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| + if (user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) |
| + return true; |
| + |
| return false; |
| } |
| #endif |
| @@ -691,6 +716,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) |