1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_H_
6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_H_
8 #include "base/callback_list.h"
9 #include "base/i18n/time_formatting.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chromeos/login/login_state.h"
13 #include "components/user_manager/user_manager.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
18 class PrefChangeRegistrar
;
20 namespace user_manager
{
27 class SystemClockObserver
;
29 // This is a global singleton (actually a member of BrowserProcessPlatformPart)
30 // that is responsible for correct time formatting. It listens to events that
31 // modify on-screen time representation (like ActiveUserChanged) and notifies
34 // (Most of) this code used to be a part of ash::SystemTrayDelegate.
35 class SystemClock
: public chromeos::LoginState::Observer
,
36 public content::NotificationObserver
,
37 public user_manager::UserManager::UserSessionStateObserver
{
40 ~SystemClock() override
;
42 void SetLastFocusedPodHourClockType(base::HourClockType hour_clock_type
);
44 void AddObserver(SystemClockObserver
* observer
);
45 void RemoveObserver(SystemClockObserver
* observer
);
47 bool ShouldUse24HourClock() const;
49 // content::NotificationObserver implementation.
50 void Observe(int type
,
51 const content::NotificationSource
& source
,
52 const content::NotificationDetails
& details
) override
;
54 // user_manager::UserManager::UserSessionStateObserver overrides
55 void ActiveUserChanged(const user_manager::User
* user
) override
;
58 // Should be the same as CrosSettings::ObserverSubscription.
59 typedef base::CallbackList
<void(void)>::Subscription
60 CrosSettingsObserverSubscription
;
62 void OnActiveProfileChanged(Profile
* profile
);
63 bool OnProfileDestroyed(Profile
* profile
);
65 // LoginState::Observer overrides.
66 void LoggedInStateChanged() override
;
68 void OnSystemPrefChanged();
70 void UpdateClockType();
72 bool user_pod_was_focused_
;
73 base::HourClockType last_focused_pod_hour_clock_type_
;
75 Profile
* user_profile_
;
76 scoped_ptr
<content::NotificationRegistrar
> registrar_
;
77 scoped_ptr
<PrefChangeRegistrar
> user_pref_registrar_
;
79 base::ObserverList
<SystemClockObserver
> observer_list_
;
81 scoped_ptr
<CrosSettingsObserverSubscription
> device_settings_observer_
;
83 DISALLOW_COPY_AND_ASSIGN(SystemClock
);
87 } // namespace chromeos
89 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_SYSTEM_CLOCK_H_