Commit 788a2c00 authored by A Olsen's avatar A Olsen Committed by Commit Bot

Remove call to CrosSettings->Set(kSystemTimezone)

crbug.com/433840 says we should split the read and write path for
cros settings (or device settings), which will simplify the read path
and get rid of its dependency on the write path.

Calls to CrosSettings->Set(kSystemTimezone) don't actually affect
signed device settings (unlike other cros settings), but end up
calling TimezoneSettings->SetTimezone. We can simplify the cros
settings interface by calling this directly.

This CL replaces the last call to CrosSettings->Set(kSystemTimezone)
with an equivalent call to timezone_util, which also delegates
to TimezoneSettings.

Bug: 433840
Change-Id: Ibaac986323cb286eab83ec7c0b29780dc2ef7d87
Reviewed-on: https://chromium-review.googlesource.com/c/1326144Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: A Olsen <olsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607186}
parent 0d7f510f
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/chromeos/arc/arc_util.h" #include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #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/settings/cros_settings.h"
#include "chrome/browser/chromeos/system/timezone_util.h" #include "chrome/browser/chromeos/system/timezone_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -429,9 +430,13 @@ ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() { ...@@ -429,9 +430,13 @@ ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() {
Profile::FromBrowserContext(context_)->GetPrefs()->SetString( Profile::FromBrowserContext(context_)->GetPrefs()->SetString(
prefs::kUserTimezone, param_value); prefs::kUserTimezone, param_value);
} else { } else {
chromeos::CrosSettings::Get()->Set(chromeos::kSystemTimezone, const user_manager::User* user =
base::Value(param_value)); chromeos::ProfileHelper::Get()->GetUserByProfile(
Profile::FromBrowserContext(context_));
if (user)
chromeos::system::SetSystemTimezone(user, param_value);
} }
} else { } else {
const char* pref_name = GetBoolPrefNameForApiProperty(param_name.c_str()); const char* pref_name = GetBoolPrefNameForApiProperty(param_name.c_str());
if (pref_name) { if (pref_name) {
......
...@@ -325,11 +325,18 @@ void UpdateSystemTimezone(Profile* profile) { ...@@ -325,11 +325,18 @@ void UpdateSystemTimezone(Profile* profile) {
value); value);
} }
if (user_manager->GetPrimaryUser() == user && PerUserTimezoneEnabled() && if (user_manager->GetPrimaryUser() == user && PerUserTimezoneEnabled())
CanSetSystemTimezone(user)) { SetSystemTimezone(user, value);
TimezoneSettings::GetInstance()->SetTimezoneFromID( }
base::UTF8ToUTF16(value));
} bool SetSystemTimezone(const user_manager::User* user,
const std::string& timezone) {
DCHECK(user);
if (!CanSetSystemTimezone(user))
return false;
TimezoneSettings::GetInstance()->SetTimezoneFromID(
base::UTF8ToUTF16(timezone));
return true;
} }
void SetSystemAndSigninScreenTimezone(const std::string& timezone) { void SetSystemAndSigninScreenTimezone(const std::string& timezone) {
...@@ -357,10 +364,7 @@ void SetTimezoneFromUI(Profile* profile, const std::string& timezone_id) { ...@@ -357,10 +364,7 @@ void SetTimezoneFromUI(Profile* profile, const std::string& timezone_id) {
ProfileHelper::Get()->GetUserByProfile(profile); ProfileHelper::Get()->GetUserByProfile(profile);
if (!PerUserTimezoneEnabled()) { if (!PerUserTimezoneEnabled()) {
if (CanSetSystemTimezone(user)) { SetSystemTimezone(user, timezone_id);
TimezoneSettings::GetInstance()->SetTimezoneFromID(
base::UTF8ToUTF16(timezone_id));
}
return; return;
} }
...@@ -370,10 +374,7 @@ void SetTimezoneFromUI(Profile* profile, const std::string& timezone_id) { ...@@ -370,10 +374,7 @@ void SetTimezoneFromUI(Profile* profile, const std::string& timezone_id) {
} }
if (ProfileHelper::IsEphemeralUserProfile(profile)) { if (ProfileHelper::IsEphemeralUserProfile(profile)) {
if (CanSetSystemTimezone(user)) { SetSystemTimezone(user, timezone_id);
TimezoneSettings::GetInstance()->SetTimezoneFromID(
base::UTF8ToUTF16(timezone_id));
}
return; return;
} }
......
...@@ -15,6 +15,10 @@ namespace base { ...@@ -15,6 +15,10 @@ namespace base {
class ListValue; class ListValue;
} }
namespace user_manager {
class User;
}
namespace chromeos { namespace chromeos {
struct TimeZoneResponseData; struct TimeZoneResponseData;
...@@ -44,6 +48,14 @@ bool IsTimezonePrefsManaged(const std::string& pref_name); ...@@ -44,6 +48,14 @@ bool IsTimezonePrefsManaged(const std::string& pref_name);
// preferences to apply new value to system time zone. // preferences to apply new value to system time zone.
void UpdateSystemTimezone(Profile* profile); void UpdateSystemTimezone(Profile* profile);
// Set system timezone to the given |timezone_id|, as long as the given |user|
// is allowed to set it (so not a guest, public account or child).
// Updates only the global system timezone - not specific to the user - and
// doesn't care if perUserTimezone is enabled.
// Returns |true| if the system timezone is set, false if the given user cannot.
bool SetSystemTimezone(const user_manager::User* user,
const std::string& timezone);
// Updates Local State preference prefs::kSigninScreenTimezone AND // Updates Local State preference prefs::kSigninScreenTimezone AND
// also immediately sets system timezone (chromeos::system::TimezoneSettings). // also immediately sets system timezone (chromeos::system::TimezoneSettings).
// This is called when there is no user session (i.e. OOBE and signin screen), // This is called when there is no user session (i.e. OOBE and signin screen),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment