Commit c194e4f1 authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros login: Use default hour type in case use does not have the pref.

Fixes the issue when the user does not have the stored hour clock type
preference - it uses the previous user preference.

Bug: b/168759134
Change-Id: I415b85456dd578ac0565b42c819ef9d0b3590d94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2443009Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Auto-Submit: Roman Sorokin [CET] <rsorokin@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816633}
parent 062273fc
...@@ -828,18 +828,27 @@ void UserSelectionScreen::HandleFocusPod(const AccountId& account_id) { ...@@ -828,18 +828,27 @@ void UserSelectionScreen::HandleFocusPod(const AccountId& account_id) {
lock_screen_utils::SetKeyboardSettings(account_id); lock_screen_utils::SetKeyboardSettings(account_id);
bool use_24hour_clock = false; bool use_24hour_clock = false;
if (user_manager::known_user::GetBooleanPref( if (!user_manager::known_user::GetBooleanPref(
account_id, ::prefs::kUse24HourClock, &use_24hour_clock)) { account_id, ::prefs::kUse24HourClock, &use_24hour_clock)) {
g_browser_process->platform_part() focused_user_clock_type_.reset();
->GetSystemClock() } else {
->SetLastFocusedPodHourClockType(use_24hour_clock ? base::k24HourClock base::HourClockType clock_type =
: base::k12HourClock); use_24hour_clock ? base::k24HourClock : base::k12HourClock;
if (focused_user_clock_type_.has_value()) {
focused_user_clock_type_->UpdateClockType(clock_type);
} else {
focused_user_clock_type_ = g_browser_process->platform_part()
->GetSystemClock()
->CreateScopedHourClockType(clock_type);
}
} }
focused_pod_account_id_ = account_id; focused_pod_account_id_ = account_id;
} }
void UserSelectionScreen::HandleNoPodFocused() { void UserSelectionScreen::HandleNoPodFocused() {
focused_pod_account_id_ = EmptyAccountId(); focused_pod_account_id_ = EmptyAccountId();
focused_user_clock_type_.reset();
if (display_type_ == OobeUI::kLoginDisplay) if (display_type_ == OobeUI::kLoginDisplay)
lock_screen_utils::EnforceDevicePolicyInputMethods(std::string()); lock_screen_utils::EnforceDevicePolicyInputMethods(std::string());
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/chromeos/login/signin/token_handle_util.h" #include "chrome/browser/chromeos/login/signin/token_handle_util.h"
#include "chrome/browser/chromeos/login/ui/login_display.h" #include "chrome/browser/chromeos/login/ui/login_display.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/system/system_clock.h"
#include "chromeos/components/proximity_auth/screenlock_bridge.h" #include "chromeos/components/proximity_auth/screenlock_bridge.h"
#include "chromeos/dbus/cryptohome/rpc.pb.h" #include "chromeos/dbus/cryptohome/rpc.pb.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
...@@ -185,6 +186,8 @@ class UserSelectionScreen ...@@ -185,6 +186,8 @@ class UserSelectionScreen
user_manager::UserList users_to_send_; user_manager::UserList users_to_send_;
AccountId focused_pod_account_id_; AccountId focused_pod_account_id_;
base::Optional<system::SystemClock::ScopedHourClockType>
focused_user_clock_type_;
// Sometimes we might get focused pod while user session is still active. e.g. // Sometimes we might get focused pod while user session is still active. e.g.
// while creating lock screen. So postpone any work until after the session // while creating lock screen. So postpone any work until after the session
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_browser_main.h" #include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/chrome_browser_main_extra_parts.h" #include "chrome/browser/chrome_browser_main_extra_parts.h"
#include "components/user_manager/fake_user_manager.h"
#include "components/user_manager/scoped_user_manager.h"
namespace chromeos { namespace chromeos {
...@@ -21,7 +23,16 @@ class TestMainExtraPart : public ChromeBrowserMainExtraParts { ...@@ -21,7 +23,16 @@ class TestMainExtraPart : public ChromeBrowserMainExtraParts {
~TestMainExtraPart() override = default; ~TestMainExtraPart() override = default;
// ChromeBrowserMainExtraParts: // ChromeBrowserMainExtraParts:
void PostEarlyInitialization() override { delegate_->SetUpLocalState(); } void PostEarlyInitialization() override {
// SaveKnownUser depends on UserManager to get the local state that has to
// be updated, and do ephemeral user checks.
// Given that user manager does not exist yet (by design), create a
// temporary fake user manager instance.
auto user_manager = std::make_unique<user_manager::FakeUserManager>();
user_manager->set_local_state(g_browser_process->local_state());
user_manager::ScopedUserManager scoper(std::move(user_manager));
delegate_->SetUpLocalState();
}
private: private:
LocalStateMixin::Delegate* const delegate_; LocalStateMixin::Delegate* const delegate_;
......
...@@ -23,9 +23,7 @@ ...@@ -23,9 +23,7 @@
#include "chromeos/login/auth/user_context.h" #include "chromeos/login/auth/user_context.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
#include "components/user_manager/fake_user_manager.h"
#include "components/user_manager/known_user.h" #include "components/user_manager/known_user.h"
#include "components/user_manager/scoped_user_manager.h"
namespace chromeos { namespace chromeos {
...@@ -108,38 +106,28 @@ bool LoginManagerMixin::SetUpUserDataDirectory() { ...@@ -108,38 +106,28 @@ bool LoginManagerMixin::SetUpUserDataDirectory() {
} }
void LoginManagerMixin::SetUpLocalState() { void LoginManagerMixin::SetUpLocalState() {
// SaveKnownUser depends on UserManager to get the local state that has to for (const auto& user : initial_users_) {
// be updated, and do ephemeral user checks. ListPrefUpdate users_pref(g_browser_process->local_state(),
// Given that user manager does not exist yet (by design), create a "LoggedInUsers");
// temporary fake user manager instance. users_pref->AppendIfNotPresent(
{ std::make_unique<base::Value>(user.account_id.GetUserEmail()));
auto user_manager = std::make_unique<user_manager::FakeUserManager>();
user_manager->set_local_state(g_browser_process->local_state()); DictionaryPrefUpdate user_type_update(g_browser_process->local_state(),
user_manager::ScopedUserManager scoper(std::move(user_manager)); "UserType");
for (const auto& user : initial_users_) { user_type_update->SetKey(user.account_id.GetAccountIdKey(),
ListPrefUpdate users_pref(g_browser_process->local_state(), base::Value(static_cast<int>(user.user_type)));
"LoggedInUsers");
users_pref->AppendIfNotPresent( DictionaryPrefUpdate user_token_update(g_browser_process->local_state(),
std::make_unique<base::Value>(user.account_id.GetUserEmail())); "OAuthTokenStatus");
user_token_update->SetKey(user.account_id.GetUserEmail(),
DictionaryPrefUpdate user_type_update(g_browser_process->local_state(), base::Value(static_cast<int>(user.token_status)));
"UserType");
user_type_update->SetKey(user.account_id.GetAccountIdKey(), user_manager::known_user::UpdateId(user.account_id);
base::Value(static_cast<int>(user.user_type)));
if (user.user_type == user_manager::USER_TYPE_CHILD) {
DictionaryPrefUpdate user_token_update(g_browser_process->local_state(), user_manager::known_user::SetProfileRequiresPolicy(
"OAuthTokenStatus"); user.account_id,
user_token_update->SetKey( user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired);
user.account_id.GetUserEmail(),
base::Value(static_cast<int>(user.token_status)));
user_manager::known_user::UpdateId(user.account_id);
if (user.user_type == user_manager::USER_TYPE_CHILD) {
user_manager::known_user::SetProfileRequiresPolicy(
user.account_id,
user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired);
}
} }
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "chromeos/settings/cros_settings_names.h" #include "chromeos/settings/cros_settings_names.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -113,21 +112,42 @@ void SystemClock::SetProfile(Profile* profile) { ...@@ -113,21 +112,42 @@ void SystemClock::SetProfile(Profile* profile) {
UpdateClockType(); UpdateClockType();
} }
void SystemClock::SetLastFocusedPodHourClockType( SystemClock::ScopedHourClockType::ScopedHourClockType(
base::WeakPtr<SystemClock> system_clock)
: system_clock_(std::move(system_clock)) {}
SystemClock::ScopedHourClockType::~ScopedHourClockType() {
if (!system_clock_)
return;
system_clock_->scoped_hour_clock_type_.reset();
system_clock_->UpdateClockType();
}
SystemClock::ScopedHourClockType::ScopedHourClockType(
ScopedHourClockType&& other) = default;
SystemClock::ScopedHourClockType& SystemClock::ScopedHourClockType::operator=(
ScopedHourClockType&& other) = default;
void SystemClock::ScopedHourClockType::UpdateClockType(
base::HourClockType clock_type) {
if (!system_clock_)
return;
system_clock_->scoped_hour_clock_type_ = clock_type;
system_clock_->UpdateClockType();
}
SystemClock::ScopedHourClockType SystemClock::CreateScopedHourClockType(
base::HourClockType hour_clock_type) { base::HourClockType hour_clock_type) {
user_pod_was_focused_ = true; DCHECK(!scoped_hour_clock_type_.has_value());
last_focused_pod_hour_clock_type_ = hour_clock_type; scoped_hour_clock_type_ = hour_clock_type;
UpdateClockType(); UpdateClockType();
return ScopedHourClockType(weak_ptr_factory_.GetWeakPtr());
} }
bool SystemClock::ShouldUse24HourClock() const { bool SystemClock::ShouldUse24HourClock() const {
const session_manager::SessionState session_state = if (scoped_hour_clock_type_.has_value())
session_manager::SessionManager::Get()->session_state(); return scoped_hour_clock_type_ == base::k24HourClock;
if (session_state == session_manager::SessionState::LOGIN_PRIMARY ||
session_state == session_manager::SessionState::LOCKED) {
if (user_pod_was_focused_)
return last_focused_pod_hour_clock_type_ == base::k24HourClock;
}
// default is used for kUse24HourClock preference on login screen and whenever // default is used for kUse24HourClock preference on login screen and whenever
// set so in user's preference // set so in user's preference
const chromeos::LoginState::LoggedInUserType status = const chromeos::LoginState::LoggedInUserType status =
......
...@@ -39,7 +39,27 @@ class SystemClock : public chromeos::LoginState::Observer, ...@@ -39,7 +39,27 @@ class SystemClock : public chromeos::LoginState::Observer,
SystemClock(); SystemClock();
~SystemClock() override; ~SystemClock() override;
void SetLastFocusedPodHourClockType(base::HourClockType hour_clock_type); // Could be used to temporary set the required clock type. At most one should
// exist at the time.
class ScopedHourClockType {
public:
explicit ScopedHourClockType(base::WeakPtr<SystemClock> system_clock);
~ScopedHourClockType();
ScopedHourClockType(const ScopedHourClockType&) = delete;
ScopedHourClockType& operator=(const ScopedHourClockType&) = delete;
ScopedHourClockType(ScopedHourClockType&&);
ScopedHourClockType& operator=(ScopedHourClockType&&);
void UpdateClockType(base::HourClockType clock_type);
private:
base::WeakPtr<SystemClock> system_clock_;
};
ScopedHourClockType CreateScopedHourClockType(
base::HourClockType hour_clock_type);
void AddObserver(SystemClockObserver* observer); void AddObserver(SystemClockObserver* observer);
void RemoveObserver(SystemClockObserver* observer); void RemoveObserver(SystemClockObserver* observer);
...@@ -67,8 +87,7 @@ class SystemClock : public chromeos::LoginState::Observer, ...@@ -67,8 +87,7 @@ class SystemClock : public chromeos::LoginState::Observer,
void UpdateClockType(); void UpdateClockType();
bool user_pod_was_focused_ = false; base::Optional<base::HourClockType> scoped_hour_clock_type_;
base::HourClockType last_focused_pod_hour_clock_type_ = base::k12HourClock;
Profile* user_profile_ = nullptr; Profile* user_profile_ = nullptr;
ScopedObserver<Profile, ProfileObserver> profile_observer_{this}; ScopedObserver<Profile, ProfileObserver> profile_observer_{this};
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#include "ash/public/cpp/ash_view_ids.h" #include "ash/public/cpp/ash_view_ids.h"
#include "ash/public/cpp/login_screen_test_api.h" #include "ash/public/cpp/login_screen_test_api.h"
#include "ash/public/cpp/system_tray_test_api.h" #include "ash/public/cpp/system_tray_test_api.h"
#include "base/i18n/time_formatting.h"
#include "chrome/browser/chromeos/login/lock/screen_locker_tester.h" #include "chrome/browser/chromeos/login/lock/screen_locker_tester.h"
#include "chrome/browser/chromeos/login/login_manager_test.h" #include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/test/local_state_mixin.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h" #include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h" #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
...@@ -22,6 +24,7 @@ ...@@ -22,6 +24,7 @@
#include "chromeos/strings/grit/chromeos_strings.h" #include "chromeos/strings/grit/chromeos_strings.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/user_manager/known_user.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
...@@ -147,3 +150,36 @@ IN_PROC_BROWSER_TEST_F(SystemTrayClientClockTest, FocusedPod24HourClock) { ...@@ -147,3 +150,36 @@ IN_PROC_BROWSER_TEST_F(SystemTrayClientClockTest, FocusedPod24HourClock) {
EXPECT_TRUE(ash::LoginScreenTestApi::FocusUser(account_id2_)); EXPECT_TRUE(ash::LoginScreenTestApi::FocusUser(account_id2_));
EXPECT_FALSE(tray_test_api->Is24HourClock()); EXPECT_FALSE(tray_test_api->Is24HourClock());
} }
class SystemTrayClientClockUnknownPrefTest
: public SystemTrayClientClockTest,
public chromeos::LocalStateMixin::Delegate {
public:
// chromeos::localStateMixin::Delegate:
void SetUpLocalState() override {
// Set preference for the first user only.
user_manager::known_user::SetBooleanPref(account_id1_,
::prefs::kUse24HourClock, true);
ASSERT_FALSE(user_manager::known_user::GetBooleanPref(
account_id2_, ::prefs::kUse24HourClock, nullptr));
}
protected:
chromeos::LocalStateMixin local_state_{&mixin_host_, this};
};
IN_PROC_BROWSER_TEST_F(SystemTrayClientClockUnknownPrefTest, SwitchToDefault) {
// Check default value.
ASSERT_EQ(base::GetHourClockType(), base::k12HourClock);
auto tray_test_api = ash::SystemTrayTestApi::Create();
// Check user with the set preference.
EXPECT_TRUE(ash::LoginScreenTestApi::FocusUser(account_id1_));
EXPECT_TRUE(tray_test_api->Is24HourClock());
// Should get back to the default 12 hours because there is not preference for
// the second user.
EXPECT_TRUE(ash::LoginScreenTestApi::FocusUser(account_id2_));
EXPECT_FALSE(tray_test_api->Is24HourClock());
}
...@@ -1218,17 +1218,27 @@ void SigninScreenHandler::HandleFocusPod(const AccountId& account_id, ...@@ -1218,17 +1218,27 @@ void SigninScreenHandler::HandleFocusPod(const AccountId& account_id,
lock_screen_utils::SetKeyboardSettings(account_id); lock_screen_utils::SetKeyboardSettings(account_id);
bool use_24hour_clock = false; bool use_24hour_clock = false;
if (user_manager::known_user::GetBooleanPref( if (!user_manager::known_user::GetBooleanPref(
account_id, prefs::kUse24HourClock, &use_24hour_clock)) { account_id, prefs::kUse24HourClock, &use_24hour_clock)) {
g_browser_process->platform_part() focused_user_clock_type_.reset();
->GetSystemClock() return;
->SetLastFocusedPodHourClockType(use_24hour_clock ? base::k24HourClock }
: base::k12HourClock);
base::HourClockType clock_type =
use_24hour_clock ? base::k24HourClock : base::k12HourClock;
if (focused_user_clock_type_.has_value()) {
focused_user_clock_type_->UpdateClockType(clock_type);
} else {
focused_user_clock_type_ = g_browser_process->platform_part()
->GetSystemClock()
->CreateScopedHourClockType(clock_type);
} }
} }
void SigninScreenHandler::HandleNoPodFocused() { void SigninScreenHandler::HandleNoPodFocused() {
focused_pod_account_id_.reset(); focused_pod_account_id_.reset();
focused_user_clock_type_.reset();
} }
void SigninScreenHandler::HandleGetPublicSessionKeyboardLayouts( void SigninScreenHandler::HandleGetPublicSessionKeyboardLayouts(
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "chrome/browser/chromeos/login/signin_specifics.h" #include "chrome/browser/chromeos/login/signin_specifics.h"
#include "chrome/browser/chromeos/login/ui/login_display.h" #include "chrome/browser/chromeos/login/ui/login_display.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/system/system_clock.h"
#include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h" #include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h" #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
...@@ -420,6 +421,8 @@ class SigninScreenHandler ...@@ -420,6 +421,8 @@ class SigninScreenHandler
std::unique_ptr<LoginFeedback> login_feedback_; std::unique_ptr<LoginFeedback> login_feedback_;
std::unique_ptr<AccountId> focused_pod_account_id_; std::unique_ptr<AccountId> focused_pod_account_id_;
base::Optional<system::SystemClock::ScopedHourClockType>
focused_user_clock_type_;
base::WeakPtrFactory<SigninScreenHandler> weak_factory_{this}; base::WeakPtrFactory<SigninScreenHandler> weak_factory_{this};
......
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