diff options
author | alemate <alemate@chromium.org> | 2015-08-13 04:42:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-13 11:42:48 +0000 |
commit | adfa5ab1a7cd3f26767a05428c4060356ed45049 (patch) | |
tree | ebd8cfd2831b016c9a52cb7f1fa76d8f33367cc2 | |
parent | 809d9853c1a28fa042be91057ff67c3ba9ecee07 (diff) | |
download | chromium_src-adfa5ab1a7cd3f26767a05428c4060356ed45049.zip chromium_src-adfa5ab1a7cd3f26767a05428c4060356ed45049.tar.gz chromium_src-adfa5ab1a7cd3f26767a05428c4060356ed45049.tar.bz2 |
Refactoring ash::SystemTrayDelegate: extracting Clock-related stuff.
SystemTrayDelegate has become a bit of a dumping ground. This CL moves all
Clock-related stuff from systemTrayDelegateChromeOS to new object
chromeos::system::SystemClock .
BUG=513120
TEST=manual
Review URL: https://codereview.chromium.org/1261903005
Cr-Commit-Position: refs/heads/master@{#343178}
-rw-r--r-- | ash/system/tray/system_tray_delegate.cc | 6 | ||||
-rw-r--r-- | ash/system/tray/system_tray_delegate.h | 6 | ||||
-rw-r--r-- | chrome/browser/browser_process_platform_part_chromeos.cc | 7 | ||||
-rw-r--r-- | chrome/browser/browser_process_platform_part_chromeos.h | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/system_clock.cc | 219 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/system_clock.h | 89 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/system_clock_observer.cc | 14 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/system_clock_observer.h | 25 | ||||
-rw-r--r-- | chrome/browser/ui/ash/system_tray_delegate_chromeos.cc | 112 | ||||
-rw-r--r-- | chrome/browser/ui/ash/system_tray_delegate_chromeos.h | 24 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc | 6 | ||||
-rw-r--r-- | chrome/chrome_browser_chromeos.gypi | 4 |
12 files changed, 384 insertions, 133 deletions
diff --git a/ash/system/tray/system_tray_delegate.cc b/ash/system/tray/system_tray_delegate.cc index 1cfb5e5..022ee4e 100644 --- a/ash/system/tray/system_tray_delegate.cc +++ b/ash/system/tray/system_tray_delegate.cc @@ -4,8 +4,6 @@ #include "ash/system/tray/system_tray_delegate.h" -#include "base/logging.h" - namespace ash { NetworkIconInfo::NetworkIconInfo() @@ -289,8 +287,4 @@ VPNDelegate* SystemTrayDelegate::GetVPNDelegate() const { return nullptr; } -void SystemTrayDelegate::SetLastFocusedPodHourClockType( - base::HourClockType user_hour_clock_type) { -} - } // namespace ash diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h index be1c96c..cd1ee8b 100644 --- a/ash/system/tray/system_tray_delegate.h +++ b/ash/system/tray/system_tray_delegate.h @@ -337,12 +337,6 @@ class ASH_EXPORT SystemTrayDelegate { // Returns VPNDelegate. May return nullptr. virtual VPNDelegate* GetVPNDelegate() const; - - // For ChromeOS login screen updates focused POD clock type. - // TODO (alemate): Move all clock-related stuff to a separate file. - // See https://crbug.com/513120 . - virtual void SetLastFocusedPodHourClockType( - base::HourClockType hour_clock_type); }; } // namespace ash diff --git a/chrome/browser/browser_process_platform_part_chromeos.cc b/chrome/browser/browser_process_platform_part_chromeos.cc index 978db1a..4ee4608 100644 --- a/chrome/browser/browser_process_platform_part_chromeos.cc +++ b/chrome/browser/browser_process_platform_part_chromeos.cc @@ -18,6 +18,7 @@ #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" #include "chrome/browser/chromeos/system/device_disabling_manager.h" #include "chrome/browser/chromeos/system/device_disabling_manager_default_delegate.h" +#include "chrome/browser/chromeos/system/system_clock.h" #include "chrome/browser/chromeos/system/timezone_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" @@ -126,6 +127,12 @@ chromeos::TimeZoneResolver* BrowserProcessPlatformPart::GetTimezoneResolver() { return timezone_resolver_.get(); } +chromeos::system::SystemClock* BrowserProcessPlatformPart::GetSystemClock() { + if (!system_clock_.get()) + system_clock_.reset(new chromeos::system::SystemClock()); + + return system_clock_.get(); +} void BrowserProcessPlatformPart::StartTearDown() { // interactive_ui_tests check for memory leaks before this object is // destroyed. So we need to destroy |timezone_resolver_| here. diff --git a/chrome/browser/browser_process_platform_part_chromeos.h b/chrome/browser/browser_process_platform_part_chromeos.h index a06cbbc..a067b51 100644 --- a/chrome/browser/browser_process_platform_part_chromeos.h +++ b/chrome/browser/browser_process_platform_part_chromeos.h @@ -25,6 +25,7 @@ namespace system { class AutomaticRebootManager; class DeviceDisablingManager; class DeviceDisablingManagerDefaultDelegate; +class SystemClock; } } @@ -94,6 +95,8 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase, scoped_ptr<policy::BrowserPolicyConnector> CreateBrowserPolicyConnector() override; + chromeos::system::SystemClock* GetSystemClock(); + private: void CreateProfileHelper(); @@ -114,6 +117,8 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase, scoped_ptr<chromeos::TimeZoneResolver> timezone_resolver_; + scoped_ptr<chromeos::system::SystemClock> system_clock_; + DISALLOW_COPY_AND_ASSIGN(BrowserProcessPlatformPart); }; diff --git a/chrome/browser/chromeos/system/system_clock.cc b/chrome/browser/chromeos/system/system_clock.cc new file mode 100644 index 0000000..2b3fdc8 --- /dev/null +++ b/chrome/browser/chromeos/system/system_clock.cc @@ -0,0 +1,219 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/system/system_clock.h" + +#include "base/logging.h" +#include "base/memory/scoped_ptr.h" +#include "base/prefs/pref_change_registrar.h" +#include "base/prefs/pref_service.h" +#include "chrome/browser/chrome_notification_types.h" +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" +#include "chrome/browser/chromeos/profiles/profile_helper.h" +#include "chrome/browser/chromeos/settings/cros_settings.h" +#include "chrome/browser/chromeos/system/system_clock_observer.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/common/pref_names.h" +#include "chromeos/login/login_state.h" +#include "chromeos/settings/cros_settings_names.h" +#include "components/user_manager/user.h" +#include "components/user_manager/user_manager.h" +#include "content/public/browser/notification_service.h" + +namespace chromeos { +namespace system { + +namespace { + +void SetShouldUse24HourClock(bool use_24_hour_clock) { + user_manager::User* const user = + user_manager::UserManager::Get()->GetActiveUser(); + CHECK(user); + Profile* const profile = ProfileHelper::Get()->GetProfileByUser(user); + if (!profile) + return; // May occur in tests or if not running on a device. + OwnerSettingsServiceChromeOS* const service = + OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile); + CHECK(service); + service->SetBoolean(kSystemUse24HourClock, use_24_hour_clock); +} + +} // anonymous namespace + +SystemClock::SystemClock() + : user_pod_was_focused_(false), + last_focused_pod_hour_clock_type_(base::k12HourClock), + user_profile_(NULL), + device_settings_observer_(CrosSettings::Get()->AddSettingsObserver( + kSystemUse24HourClock, + base::Bind(&SystemClock::OnSystemPrefChanged, + base::Unretained(this)))) { + if (LoginState::IsInitialized()) + LoginState::Get()->AddObserver(this); + // Register notifications on construction so that events such as + // PROFILE_CREATED do not get missed if they happen before Initialize(). + registrar_.reset(new content::NotificationRegistrar); + if (!LoginState::IsInitialized() || + LoginState::Get()->GetLoggedInUserType() == + LoginState::LOGGED_IN_USER_NONE) { + registrar_->Add(this, chrome::NOTIFICATION_SESSION_STARTED, + content::NotificationService::AllSources()); + } + registrar_->Add(this, chrome::NOTIFICATION_PROFILE_CREATED, + content::NotificationService::AllSources()); + registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, + content::NotificationService::AllSources()); + registrar_->Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, + content::NotificationService::AllSources()); + user_manager::UserManager::Get()->AddSessionStateObserver(this); +} + +SystemClock::~SystemClock() { + registrar_.reset(); + device_settings_observer_.reset(); + if (LoginState::IsInitialized()) + LoginState::Get()->RemoveObserver(this); + if (user_manager::UserManager::IsInitialized()) + user_manager::UserManager::Get()->RemoveSessionStateObserver(this); +} + +// LoginState::Observer overrides. +void SystemClock::LoggedInStateChanged() { + // It apparently sometimes takes a while after login before the current user + // is recognized as the owner. Make sure that the system-wide clock setting + // is updated when the recognition eventually happens (crbug.com/278601). + if (user_manager::UserManager::Get()->IsCurrentUserOwner()) + SetShouldUse24HourClock(ShouldUse24HourClock()); +} + +// content::NotificationObserver implementation. +void SystemClock::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + switch (type) { + case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: { + UpdateClockType(); + break; + } + case chrome::NOTIFICATION_PROFILE_CREATED: { + OnActiveProfileChanged(content::Source<Profile>(source).ptr()); + registrar_->Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, + content::NotificationService::AllSources()); + break; + } + case chrome::NOTIFICATION_PROFILE_DESTROYED: { + if (OnProfileDestroyed(content::Source<Profile>(source).ptr())) { + registrar_->Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, + content::NotificationService::AllSources()); + } + break; + } + case chrome::NOTIFICATION_SESSION_STARTED: { + OnActiveProfileChanged(ProfileManager::GetActiveUserProfile()); + break; + } + default: + NOTREACHED(); + } +} + +void SystemClock::ActiveUserChanged(const user_manager::User* /*user*/) { + UpdateClockType(); +} + +void SystemClock::AddObserver(SystemClockObserver* observer) { + observer_list_.AddObserver(observer); +} + +void SystemClock::RemoveObserver(SystemClockObserver* observer) { + observer_list_.RemoveObserver(observer); +} + +void SystemClock::OnActiveProfileChanged(Profile* profile) { + user_profile_ = profile; + PrefService* prefs = profile->GetPrefs(); + user_pref_registrar_.reset(new PrefChangeRegistrar); + user_pref_registrar_->Init(prefs); + user_pref_registrar_->Add( + prefs::kUse24HourClock, + base::Bind(&SystemClock::UpdateClockType, base::Unretained(this))); +} + +bool SystemClock::OnProfileDestroyed(Profile* profile) { + if (profile != user_profile_) + return false; + user_pref_registrar_.reset(); + user_profile_ = NULL; + return true; +} + +void SystemClock::SetLastFocusedPodHourClockType( + base::HourClockType hour_clock_type) { + user_pod_was_focused_ = true; + last_focused_pod_hour_clock_type_ = hour_clock_type; + UpdateClockType(); +} + +bool SystemClock::ShouldUse24HourClock() const { + // On login screen and in guest mode owner default is used for + // kUse24HourClock preference. + const chromeos::LoginState::LoggedInUserType status = + LoginState::IsInitialized() ? LoginState::Get()->GetLoggedInUserType() + : LoginState::LOGGED_IN_USER_NONE; + + if (status == LoginState::LOGGED_IN_USER_NONE && user_pod_was_focused_) + return last_focused_pod_hour_clock_type_ == base::k24HourClock; + + const CrosSettings* const cros_settings = CrosSettings::Get(); + bool system_use_24_hour_clock = true; + const bool system_value_found = cros_settings->GetBoolean( + kSystemUse24HourClock, &system_use_24_hour_clock); + + if ((status == LoginState::LOGGED_IN_USER_NONE) || !user_pref_registrar_) { + return (system_value_found + ? system_use_24_hour_clock + : (base::GetHourClockType() == base::k24HourClock)); + } + + const PrefService::Preference* user_pref = + user_pref_registrar_->prefs()->FindPreference(prefs::kUse24HourClock); + if (status == LoginState::LOGGED_IN_USER_GUEST && + user_pref->IsDefaultValue()) { + return (system_value_found + ? system_use_24_hour_clock + : (base::GetHourClockType() == base::k24HourClock)); + } + + user_manager::User* active_user = + user_manager::UserManager::Get()->GetActiveUser(); + if (active_user) { + Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(active_user); + if (user_profile) { + user_pref = + user_profile->GetPrefs()->FindPreference(prefs::kUse24HourClock); + } + } + + bool use_24_hour_clock = true; + user_pref->GetValue()->GetAsBoolean(&use_24_hour_clock); + return use_24_hour_clock; +} + +void SystemClock::OnSystemPrefChanged() { + UpdateClockType(); +} + +void SystemClock::UpdateClockType() { + // This also works for enterprise-managed devices because they never have + // a local owner. + if (user_manager::UserManager::Get()->IsCurrentUserOwner()) + SetShouldUse24HourClock(ShouldUse24HourClock()); + FOR_EACH_OBSERVER(SystemClockObserver, observer_list_, + OnSystemClockChanged(this)); +} + +} // namespace system +} // namespace chromeos diff --git a/chrome/browser/chromeos/system/system_clock.h b/chrome/browser/chromeos/system/system_clock.h new file mode 100644 index 0000000..f6a5d32 --- /dev/null +++ b/chrome/browser/chromeos/system/system_clock.h @@ -0,0 +1,89 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_H_ + +#include "base/callback_list.h" +#include "base/i18n/time_formatting.h" +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "chromeos/login/login_state.h" +#include "components/user_manager/user_manager.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" + +class Profile; +class PrefChangeRegistrar; + +namespace user_manager { +class User; +} + +namespace chromeos { +namespace system { + +class SystemClockObserver; + +// This is a global singleton (actually a member of BrowserProcessPlatformPart) +// that is responsible for correct time formatting. It listens to events that +// modify on-screen time representation (like ActiveUserChanged) and notifies +// observers. +// +// (Most of) this code used to be a part of ash::SystemTrayDelegate. +class SystemClock : public chromeos::LoginState::Observer, + public content::NotificationObserver, + public user_manager::UserManager::UserSessionStateObserver { + public: + SystemClock(); + ~SystemClock() override; + + void SetLastFocusedPodHourClockType(base::HourClockType hour_clock_type); + + void AddObserver(SystemClockObserver* observer); + void RemoveObserver(SystemClockObserver* observer); + + bool ShouldUse24HourClock() const; + + // content::NotificationObserver implementation. + void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) override; + + // user_manager::UserManager::UserSessionStateObserver overrides + void ActiveUserChanged(const user_manager::User* user) override; + + private: + // Should be the same as CrosSettings::ObserverSubscription. + typedef base::CallbackList<void(void)>::Subscription + CrosSettingsObserverSubscription; + + void OnActiveProfileChanged(Profile* profile); + bool OnProfileDestroyed(Profile* profile); + + // LoginState::Observer overrides. + void LoggedInStateChanged() override; + + void OnSystemPrefChanged(); + + void UpdateClockType(); + + bool user_pod_was_focused_; + base::HourClockType last_focused_pod_hour_clock_type_; + + Profile* user_profile_; + scoped_ptr<content::NotificationRegistrar> registrar_; + scoped_ptr<PrefChangeRegistrar> user_pref_registrar_; + + base::ObserverList<SystemClockObserver> observer_list_; + + scoped_ptr<CrosSettingsObserverSubscription> device_settings_observer_; + + DISALLOW_COPY_AND_ASSIGN(SystemClock); +}; + +} // namespace system +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_H_ diff --git a/chrome/browser/chromeos/system/system_clock_observer.cc b/chrome/browser/chromeos/system/system_clock_observer.cc new file mode 100644 index 0000000..52a8dc1 --- /dev/null +++ b/chrome/browser/chromeos/system/system_clock_observer.cc @@ -0,0 +1,14 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/system/system_clock_observer.h" + +namespace chromeos { +namespace system { + +SystemClockObserver::~SystemClockObserver() { +} + +} // namespace system +} // namespace chromeos diff --git a/chrome/browser/chromeos/system/system_clock_observer.h b/chrome/browser/chromeos/system/system_clock_observer.h new file mode 100644 index 0000000..08f4494 --- /dev/null +++ b/chrome/browser/chromeos/system/system_clock_observer.h @@ -0,0 +1,25 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_OBSERVER_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_OBSERVER_H_ + +#include "base/macros.h" + +namespace chromeos { +namespace system { + +class SystemClock; + +// This is observer for chromeos::system::SystemClock . +class SystemClockObserver { + public: + virtual ~SystemClockObserver(); + virtual void OnSystemClockChanged(SystemClock*) = 0; +}; + +} // namespace system +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_OBSERVER_H_ diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc index 31c4c04..4f80cb6 100644 --- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc @@ -58,8 +58,6 @@ #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" #include "chrome/browser/chromeos/options/network_config_view.h" -#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" -#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" @@ -180,19 +178,6 @@ void OnAcceptMultiprofilesIntro(bool no_show_again) { UserAddingScreen::Get()->Start(); } -void SetShouldUse24HourClock(bool use_24_hour_clock) { - user_manager::User* const user = - user_manager::UserManager::Get()->GetActiveUser(); - CHECK(user); - Profile* const profile = ProfileHelper::Get()->GetProfileByUser(user); - if (!profile) - return; // May occur in tests or if not running on a device. - OwnerSettingsServiceChromeOS* const service = - OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile); - CHECK(service); - service->SetBoolean(kSystemUse24HourClock, use_24_hour_clock); -} - } // namespace SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() @@ -207,13 +192,7 @@ SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() cast_config_delegate_(new CastConfigDelegateChromeos()), networking_config_delegate_(new NetworkingConfigDelegateChromeos()), volume_control_delegate_(new VolumeController()), - device_settings_observer_(CrosSettings::Get()->AddSettingsObserver( - kSystemUse24HourClock, - base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, - base::Unretained(this)))), vpn_delegate_(new VPNDelegateChromeOS), - user_pod_was_focused_(false), - last_focused_pod_hour_clock_type_(base::k12HourClock), weak_ptr_factory_(this) { // Register notifications on construction so that events such as // PROFILE_CREATED do not get missed if they happen before Initialize(). @@ -235,8 +214,6 @@ SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, content::NotificationService::AllSources()); - registrar_->Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, - content::NotificationService::AllSources()); AccessibilityManager* accessibility_manager = AccessibilityManager::Get(); CHECK(accessibility_manager); @@ -254,7 +231,10 @@ void SystemTrayDelegateChromeOS::Initialize() { input_method::InputMethodManager::Get()->AddObserver(this); ui::ime::InputMethodMenuManager::GetInstance()->AddObserver(this); - UpdateClockType(); + + g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); + + OnSystemClockChanged(g_browser_process->platform_part()->GetSystemClock()); device::BluetoothAdapterFactory::GetAdapter( base::Bind(&SystemTrayDelegateChromeOS::InitializeOnAdapterReady, @@ -263,9 +243,6 @@ void SystemTrayDelegateChromeOS::Initialize() { ash::Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver( this); - if (LoginState::IsInitialized()) - LoginState::Get()->AddObserver(this); - if (CrasAudioHandler::IsInitialized()) CrasAudioHandler::Get()->AddAudioObserver(this); @@ -273,7 +250,6 @@ void SystemTrayDelegateChromeOS::Initialize() { } void SystemTrayDelegateChromeOS::Shutdown() { - device_settings_observer_.reset(); } void SystemTrayDelegateChromeOS::InitializeOnAdapterReady( @@ -317,6 +293,7 @@ SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() { // Unregister a11y status subscription. accessibility_subscription_.reset(); + g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); input_method::InputMethodManager::Get()->RemoveObserver(this); ui::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this); @@ -324,7 +301,6 @@ SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() { ash::Shell::GetInstance() ->session_state_delegate() ->RemoveSessionStateObserver(this); - LoginState::Get()->RemoveObserver(this); if (CrasAudioHandler::IsInitialized()) CrasAudioHandler::Get()->RemoveAudioObserver(this); @@ -934,10 +910,6 @@ void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) { user_pref_registrar_.reset(new PrefChangeRegistrar); user_pref_registrar_->Init(prefs); user_pref_registrar_->Add( - prefs::kUse24HourClock, - base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, - base::Unretained(this))); - user_pref_registrar_->Add( prefs::kLanguageRemapSearchKeyTo, base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged, base::Unretained(this))); @@ -986,64 +958,16 @@ bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) { } bool SystemTrayDelegateChromeOS::GetShouldUse24HourClockForTesting() const { - return ShouldUse24HourClock(); -} - -void SystemTrayDelegateChromeOS::SetLastFocusedPodHourClockType( - base::HourClockType user_hour_clock_type) { - user_pod_was_focused_ = true; - last_focused_pod_hour_clock_type_ = user_hour_clock_type; - UpdateClockType(); -} - -bool SystemTrayDelegateChromeOS::ShouldUse24HourClock() const { - // On login screen and in guest mode owner default is used for - // kUse24HourClock preference. - const ash::user::LoginStatus status = GetUserLoginStatus(); - - if (status == ash::user::LOGGED_IN_NONE && user_pod_was_focused_) - return last_focused_pod_hour_clock_type_ == base::k24HourClock; - - const CrosSettings* const cros_settings = CrosSettings::Get(); - bool system_use_24_hour_clock = true; - const bool system_value_found = cros_settings->GetBoolean( - kSystemUse24HourClock, &system_use_24_hour_clock); - - if ((status == ash::user::LOGGED_IN_NONE) || !user_pref_registrar_) - return (system_value_found - ? system_use_24_hour_clock - : (base::GetHourClockType() == base::k24HourClock)); - - const PrefService::Preference* user_pref = - user_pref_registrar_->prefs()->FindPreference(prefs::kUse24HourClock); - if (status == ash::user::LOGGED_IN_GUEST && user_pref->IsDefaultValue()) - return (system_value_found - ? system_use_24_hour_clock - : (base::GetHourClockType() == base::k24HourClock)); - - user_manager::User* active_user = - user_manager::UserManager::Get()->GetActiveUser(); - if (active_user) { - Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(active_user); - if (user_profile) { - user_pref = - user_profile->GetPrefs()->FindPreference(prefs::kUse24HourClock); - } - } - - bool use_24_hour_clock = true; - user_pref->GetValue()->GetAsBoolean(&use_24_hour_clock); - return use_24_hour_clock; + return g_browser_process->platform_part() + ->GetSystemClock() + ->ShouldUse24HourClock(); } -void SystemTrayDelegateChromeOS::UpdateClockType() { - const bool use_24_hour_clock = ShouldUse24HourClock(); +void SystemTrayDelegateChromeOS::OnSystemClockChanged( + system::SystemClock* system_clock) { + const bool use_24_hour_clock = system_clock->ShouldUse24HourClock(); clock_type_ = use_24_hour_clock ? base::k24HourClock : base::k12HourClock; GetSystemTrayNotifier()->NotifyDateFormatChanged(); - // This also works for enterprise-managed devices because they never have - // local owner. - if (user_manager::UserManager::Get()->IsCurrentUserOwner()) - SetShouldUse24HourClock(use_24_hour_clock); } void SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray() { @@ -1132,15 +1056,6 @@ void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() { GetSystemTrayNotifier()->NotifyLastWindowClosed(); } -// LoginState::Observer overrides. -void SystemTrayDelegateChromeOS::LoggedInStateChanged() { - // It apparently sometimes takes a while after login before the current user - // is recognized as the owner. Make sure that the system-wide clock setting - // is updated when the recognition eventually happens (crbug.com/278601). - if (user_manager::UserManager::Get()->IsCurrentUserOwner()) - SetShouldUse24HourClock(ShouldUse24HourClock()); -} - // Overridden from SessionManagerClient::Observer. void SystemTrayDelegateChromeOS::ScreenIsLocked() { screen_locked_ = true; @@ -1165,10 +1080,6 @@ void SystemTrayDelegateChromeOS::Observe( const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: { - UpdateClockType(); - break; - } case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { ash::UpdateInfo info; GetUpdateInfo(content::Source<UpgradeDetector>(source).ptr(), &info); @@ -1348,7 +1259,6 @@ void SystemTrayDelegateChromeOS::UserAddedToSession( void SystemTrayDelegateChromeOS::ActiveUserChanged( const std::string& /* user_id */) { - UpdateClockType(); } // Overridden from chrome::BrowserListObserver. diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.h b/chrome/browser/ui/ash/system_tray_delegate_chromeos.h index c1c193d..58f93a8 100644 --- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.h +++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.h @@ -23,12 +23,13 @@ #include "base/prefs/pref_change_registrar.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/settings/shutdown_policy_handler.h" +#include "chrome/browser/chromeos/system/system_clock.h" +#include "chrome/browser/chromeos/system/system_clock_observer.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/supervised_user/supervised_user_service_observer.h" #include "chrome/browser/ui/browser_list_observer.h" #include "chromeos/audio/cras_audio_handler.h" #include "chromeos/dbus/session_manager_client.h" -#include "chromeos/login/login_state.h" #include "components/policy/core/common/cloud/cloud_policy_store.h" #include "components/user_manager/user_manager.h" #include "content/public/browser/notification_observer.h" @@ -55,7 +56,6 @@ class SystemTrayDelegateChromeOS public SessionManagerClient::Observer, public content::NotificationObserver, public input_method::InputMethodManager::Observer, - public chromeos::LoginState::Observer, public chromeos::CrasAudioHandler::AudioObserver, public device::BluetoothAdapter::Observer, public policy::CloudPolicyStore::Observer, @@ -64,7 +64,8 @@ class SystemTrayDelegateChromeOS public extensions::AppWindowRegistry::Observer, public user_manager::UserManager::UserSessionStateObserver, public SupervisedUserServiceObserver, - public ShutdownPolicyHandler::Delegate { + public ShutdownPolicyHandler::Delegate, + public system::SystemClockObserver { public: SystemTrayDelegateChromeOS(); @@ -147,8 +148,6 @@ class SystemTrayDelegateChromeOS void ShouldRebootOnShutdown( const ash::RebootOnShutdownCallback& callback) override; ash::VPNDelegate* GetVPNDelegate() const override; - void SetLastFocusedPodHourClockType( - base::HourClockType hour_clock_type) override; // Overridden from user_manager::UserManager::UserSessionStateObserver: void UserAddedToSession(const user_manager::User* active_user) override; @@ -159,10 +158,10 @@ class SystemTrayDelegateChromeOS // browser tests need to call ShouldUse24HourClock(). bool GetShouldUse24HourClockForTesting() const; + // chromeos::system::SystemClockObserver implementation. + void OnSystemClockChanged(system::SystemClock*) override; + private: - // Should be the same as CrosSettings::ObserverSubscription. - typedef base::CallbackList<void(void)>::Subscription - CrosSettingsObserverSubscription; ash::SystemTray* GetPrimarySystemTray(); @@ -174,8 +173,6 @@ class SystemTrayDelegateChromeOS bool ShouldUse24HourClock() const; - void UpdateClockType(); - void UpdateShowLogoutButtonInTray(); void UpdateLogoutDialogDuration(); @@ -192,9 +189,6 @@ class SystemTrayDelegateChromeOS // windows. void NotifyIfLastWindowClosed(); - // LoginState::Observer overrides. - void LoggedInStateChanged() override; - // Overridden from SessionManagerClient::Observer. void ScreenIsLocked() override; void ScreenIsUnlocked() override; @@ -297,7 +291,6 @@ class SystemTrayDelegateChromeOS scoped_ptr<ash::CastConfigDelegate> cast_config_delegate_; scoped_ptr<ash::NetworkingConfigDelegate> networking_config_delegate_; scoped_ptr<ash::VolumeControlDelegate> volume_control_delegate_; - scoped_ptr<CrosSettingsObserverSubscription> device_settings_observer_; scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_; base::ScopedPtrHashMap<std::string, scoped_ptr<ash::tray::UserAccountsDelegate>> @@ -310,9 +303,6 @@ class SystemTrayDelegateChromeOS base::ObserverList<ash::ShutdownPolicyObserver> shutdown_policy_observers_; - bool user_pod_was_focused_; - base::HourClockType last_focused_pod_hour_clock_type_; - base::WeakPtrFactory<SystemTrayDelegateChromeOS> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOS); diff --git a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc index 31c06b6..6465c61 100644 --- a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc +++ b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc @@ -9,7 +9,6 @@ #include "ash/shell.h" #include "ash/system/chromeos/devicetype_utils.h" -#include "ash/system/tray/system_tray_delegate.h" #include "ash/wm/lock_state_controller.h" #include "base/bind.h" #include "base/location.h" @@ -49,6 +48,7 @@ #include "chrome/browser/chromeos/policy/device_local_account.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/settings/cros_settings.h" +#include "chrome/browser/chromeos/system/system_clock.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_metrics.h" @@ -1285,8 +1285,8 @@ void SigninScreenHandler::HandleFocusPod(const std::string& user_id) { bool use_24hour_clock = false; if (user_manager::UserManager::Get()->GetKnownUserBooleanPref( user_id, prefs::kUse24HourClock, &use_24hour_clock)) { - ash::Shell::GetInstance() - ->system_tray_delegate() + g_browser_process->platform_part() + ->GetSystemClock() ->SetLastFocusedPodHourClockType(use_24hour_clock ? base::k24HourClock : base::k12HourClock); } diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index 2fc7cc6..9833ab8 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -995,6 +995,10 @@ 'browser/chromeos/system/input_device_settings_impl_x11.cc', 'browser/chromeos/system/pointer_device_observer.cc', 'browser/chromeos/system/pointer_device_observer.h', + 'browser/chromeos/system/system_clock.cc', + 'browser/chromeos/system/system_clock.h', + 'browser/chromeos/system/system_clock_observer.cc', + 'browser/chromeos/system/system_clock_observer.h', 'browser/chromeos/system/timezone_util.cc', 'browser/chromeos/system/timezone_util.h', 'browser/chromeos/system_logs/command_line_log_source.cc', |