Chromium Code Reviews| Index: chrome/browser/chromeos/system/timezone_util.cc |
| diff --git a/chrome/browser/chromeos/system/timezone_util.cc b/chrome/browser/chromeos/system/timezone_util.cc |
| index d01f60e03b9fa460b7d67a6f535f2d3393327db2..4dc16cc0b8b5790b289350a89c3f7b6e93521e36 100644 |
| --- a/chrome/browser/chromeos/system/timezone_util.cc |
| +++ b/chrome/browser/chromeos/system/timezone_util.cc |
| @@ -21,13 +21,16 @@ |
| #include "base/values.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| +#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| #include "chrome/browser/chromeos/system/timezone_resolver_manager.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "chromeos/settings/timezone_settings.h" |
| #include "chromeos/timezone/timezone_request.h" |
| #include "components/prefs/pref_service.h" |
| +#include "components/user_manager/user.h" |
| #include "components/user_manager/user_manager.h" |
| #include "third_party/icu/source/common/unicode/ures.h" |
| #include "third_party/icu/source/common/unicode/utypes.h" |
| @@ -184,6 +187,43 @@ bool HasSystemTimezonePolicy() { |
| return false; |
| } |
| +bool IfTimezonePrefsmanaged(const std::string& pref_name) { |
| + DCHECK(pref_name == prefs::kUserTimezone || |
| + pref_name == prefs::kResolveTimezoneByGeolocation); |
| + |
| + std::string policy_timezone; |
| + if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy, |
| + &policy_timezone) && |
| + !policy_timezone.empty()) { |
| + return true; |
| + } |
|
stevenjb
2017/05/15 17:08:02
nit: blank line
Alexander Alekseev
2017/05/16 01:11:56
Done.
|
| + const PrefService* local_state = g_browser_process->local_state(); |
| + const bool is_resolve_managed = local_state->IsManagedPreference( |
|
stevenjb
2017/05/15 17:08:02
I'm confused about what 'resolve' refers to here a
Alexander Alekseev
2017/05/16 01:11:56
This was lame abbreviation of "resolve timezone au
|
| + prefs::kSystemTimezoneAutomaticDetectionPolicy); |
| + if (!is_resolve_managed) |
| + return false; |
| + |
| + int resolve_policy_value = |
| + local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy); |
| + |
| + switch (resolve_policy_value) { |
| + case enterprise_management::SystemTimezoneProto::USERS_DECIDE: |
| + return false; |
| + case enterprise_management::SystemTimezoneProto::DISABLED: |
| + // This only disables resolving. |
| + return pref_name == prefs::kResolveTimezoneByGeolocation; |
| + case enterprise_management::SystemTimezoneProto::IP_ONLY: |
| + return true; |
|
michaelpg
2017/05/15 23:01:50
nit: use fall-through for trivial cases
Alexander Alekseev
2017/05/16 01:11:56
Done.
|
| + case enterprise_management::SystemTimezoneProto::SEND_WIFI_ACCESS_POINTS: |
| + return true; |
| + case enterprise_management::SystemTimezoneProto::SEND_ALL_LOCATION_INFO: |
| + return true; |
| + } |
| + // Default for unknown policy value. |
| + NOTREACHED() << "Unrecognized policy value: " << resolve_policy_value; |
| + return true; |
| +} |
| + |
| void ApplyTimeZone(const TimeZoneResponseData* timezone) { |
| if (!g_browser_process->platform_part() |
| ->GetTimezoneResolverManager() |
| @@ -195,9 +235,50 @@ void ApplyTimeZone(const TimeZoneResponseData* timezone) { |
| VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId |
| << "'"; |
| - chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
| - base::UTF8ToUTF16(timezone->timeZoneId)); |
| + const user_manager::UserManager* user_manager = |
| + user_manager::UserManager::Get(); |
| + const user_manager::User* primary_user = user_manager->GetPrimaryUser(); |
| + |
| + if (primary_user) { |
| + Profile* profile = ProfileHelper::Get()->GetProfileByUser(primary_user); |
| + profile->GetPrefs()->SetString(prefs::kUserTimezone, |
| + timezone->timeZoneId); |
| + // Actual system timezone change will happen automatically. |
|
stevenjb
2017/05/15 17:08:02
Could you elaborate on 'automatically'? Where does
Alexander Alekseev
2017/05/16 01:11:56
Done.
|
| + } else { |
| + g_browser_process->local_state()->SetString(prefs::kSigninScreenTimezone, |
| + timezone->timeZoneId); |
| + chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
| + base::UTF8ToUTF16(timezone->timeZoneId)); |
| + } |
| + } |
| +} |
| + |
| +void UpdateSystemTimezone(Profile* profile) { |
| + if (IfTimezonePrefsmanaged(prefs::kUserTimezone)) { |
| + VLOG(1) << "Ignoring user timezone change, because timezone is enterprise " |
| + "managed."; |
| + return; |
| + } |
| + |
| + const user_manager::UserManager* user_manager = |
| + user_manager::UserManager::Get(); |
| + const user_manager::User* user = |
| + ProfileHelper::Get()->GetUserByProfile(profile); |
| + |
| + const AccountId owner(user_manager->GetOwnerAccountId()); |
| + const bool user_is_owner = |
| + owner.is_valid() && (owner == user->GetAccountId()); |
| + |
| + const bool user_is_primary = user_manager->GetPrimaryUser() == user; |
|
stevenjb
2017/05/15 17:08:02
Move this to where it is used (better yet, just re
Alexander Alekseev
2017/05/16 01:11:56
Done.
|
| + |
| + const std::string value = |
| + profile->GetPrefs()->GetString(prefs::kUserTimezone); |
| + if (user_is_owner) { |
| + g_browser_process->local_state()->SetString(prefs::kSigninScreenTimezone, |
| + value); |
| } |
| + if (user_is_primary) |
| + CrosSettings::Get()->SetString(kSystemTimezone, value); |
| } |
| } // namespace system |