OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout.h" | 5 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 11 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
12 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_helper.h" | 12 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
13 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 13 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
14 #include "chrome/browser/chromeos/ui/idle_logout_dialog_view.h" | 14 #include "chrome/browser/chromeos/ui/idle_logout_dialog_view.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const int64 kLoginIdleTimeout = 100; // seconds | 22 const int64 kLoginIdleTimeout = 100; // seconds |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 namespace browser { | 26 namespace browser { |
27 | 27 |
28 void ShowIdleLogoutDialog() { | 28 void ShowIdleLogoutDialog() { |
29 IdleLogoutDialogView::ShowDialog(); | 29 IdleLogoutDialogView::ShowDialog(); |
30 } | 30 } |
31 | 31 |
32 void CloseIdleLogoutDialog() { | 32 void CloseIdleLogoutDialog() { |
33 IdleLogoutDialogView::CloseDialog(); | 33 IdleLogoutDialogView::CloseDialog(); |
34 } | 34 } |
35 | 35 |
36 } // namespace browser | 36 } // namespace browser |
37 | 37 |
38 namespace chromeos { | 38 namespace chromeos { |
39 | 39 |
40 KioskModeIdleLogout::KioskModeIdleLogout() { | 40 KioskModeIdleLogout::KioskModeIdleLogout() { |
41 if (chromeos::KioskModeHelper::Get()->is_initialized()) | 41 if (chromeos::KioskModeSettings::Get()->is_initialized()) |
42 Setup(); | 42 Setup(); |
43 else | 43 else |
44 chromeos::KioskModeHelper::Get()->Initialize( | 44 chromeos::KioskModeSettings::Get()->Initialize( |
45 base::Bind(&KioskModeIdleLogout::Setup, | 45 base::Bind(&KioskModeIdleLogout::Setup, |
46 base::Unretained(this))); | 46 base::Unretained(this))); |
47 } | 47 } |
48 | 48 |
49 void KioskModeIdleLogout::Setup() { | 49 void KioskModeIdleLogout::Setup() { |
50 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 50 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
51 content::NotificationService::AllSources()); | 51 content::NotificationService::AllSources()); |
52 } | 52 } |
53 | 53 |
54 void KioskModeIdleLogout::Observe( | 54 void KioskModeIdleLogout::Observe( |
55 int type, | 55 int type, |
56 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
57 const content::NotificationDetails& details) { | 57 const content::NotificationDetails& details) { |
58 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 58 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
59 // Register our observers only when a user logs on. | 59 // Register our observers only when a user logs on. |
60 chromeos::PowerManagerClient* power_manager = | 60 chromeos::PowerManagerClient* power_manager = |
61 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | 61 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
62 if (!power_manager->HasObserver(this)) | 62 if (!power_manager->HasObserver(this)) |
63 power_manager->AddObserver(this); | 63 power_manager->AddObserver(this); |
64 | 64 |
65 // Register for the next Idle for kLoginIdleTimeout event. | 65 // Register for the next Idle for kLoginIdleTimeout event. |
66 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 66 power_manager->RequestIdleNotification( |
67 RequestIdleNotification( | 67 chromeos::KioskModeSettings::Get()-> |
68 chromeos::KioskModeHelper::Get()->GetIdleLogoutTimeout() * 1000); | 68 GetIdleLogoutTimeout().InMilliseconds()); |
| 69 |
69 } | 70 } |
70 } | 71 } |
71 | 72 |
72 void KioskModeIdleLogout::IdleNotify(int64 threshold) { | 73 void KioskModeIdleLogout::IdleNotify(int64 threshold) { |
73 // We're idle, next time we go active, we need to know so we can remove | 74 // We're idle, next time we go active, we need to know so we can remove |
74 // the logout dialog if it's still up. | 75 // the logout dialog if it's still up. |
75 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 76 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
76 RequestActiveNotification(); | 77 RequestActiveNotification(); |
77 | 78 |
78 browser::ShowIdleLogoutDialog(); | 79 browser::ShowIdleLogoutDialog(); |
79 } | 80 } |
80 | 81 |
81 void KioskModeIdleLogout::ActiveNotify() { | 82 void KioskModeIdleLogout::ActiveNotify() { |
82 // Before anything else, close the logout dialog to prevent restart | 83 // Before anything else, close the logout dialog to prevent restart |
83 browser::CloseIdleLogoutDialog(); | 84 browser::CloseIdleLogoutDialog(); |
84 | 85 |
85 // Now that we're active, register a request for notification for | 86 // Now that we're active, register a request for notification for |
86 // the next time we go idle for kLoginIdleTimeout seconds. | 87 // the next time we go idle for kLoginIdleTimeout seconds. |
87 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 88 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
88 RequestIdleNotification( | 89 RequestIdleNotification(chromeos::KioskModeSettings::Get()-> |
89 chromeos::KioskModeHelper::Get()->GetIdleLogoutTimeout() * 1000); | 90 GetIdleLogoutTimeout().InMilliseconds()); |
90 } | 91 } |
91 | 92 |
92 static base::LazyInstance<KioskModeIdleLogout> | 93 static base::LazyInstance<KioskModeIdleLogout> |
93 g_kiosk_mode_idle_logout = LAZY_INSTANCE_INITIALIZER; | 94 g_kiosk_mode_idle_logout = LAZY_INSTANCE_INITIALIZER; |
94 | 95 |
95 void InitializeKioskModeIdleLogout() { | 96 void InitializeKioskModeIdleLogout() { |
96 g_kiosk_mode_idle_logout.Get(); | 97 g_kiosk_mode_idle_logout.Get(); |
97 } | 98 } |
98 | 99 |
99 } // namespace chromeos | 100 } // namespace chromeos |
OLD | NEW |