summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_process_platform_part_chromeos.cc7
-rw-r--r--chrome/browser/browser_process_platform_part_chromeos.h5
-rw-r--r--chrome/browser/chromeos/system/system_clock.cc219
-rw-r--r--chrome/browser/chromeos/system/system_clock.h89
-rw-r--r--chrome/browser/chromeos/system/system_clock_observer.cc14
-rw-r--r--chrome/browser/chromeos/system/system_clock_observer.h25
-rw-r--r--chrome/browser/ui/ash/system_tray_delegate_chromeos.cc112
-rw-r--r--chrome/browser/ui/ash/system_tray_delegate_chromeos.h24
-rw-r--r--chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc6
9 files changed, 380 insertions, 121 deletions
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);
}