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/kiosk_mode/kiosk_mode_settings.h" | 11 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
12 #include "chrome/browser/chromeos/login/user_manager.h" | 12 #include "chrome/browser/chromeos/login/user_manager.h" |
13 #include "chrome/browser/chromeos/ui/idle_logout_dialog_view.h" | 13 #include "chrome/browser/chromeos/ui/idle_logout_dialog_view.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "chromeos/dbus/power_manager_client.h" | 16 #include "chromeos/dbus/power_manager_client.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 | 20 |
| 21 namespace chromeos { |
| 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 const int64 kLoginIdleTimeout = 100; // seconds | 25 const int64 kLoginIdleTimeout = 100; // seconds |
24 | 26 |
| 27 static base::LazyInstance<KioskModeIdleLogout> |
| 28 g_kiosk_mode_idle_logout = LAZY_INSTANCE_INITIALIZER; |
| 29 |
25 } // namespace | 30 } // namespace |
26 | 31 |
27 namespace browser { | 32 // static |
28 | 33 void KioskModeIdleLogout::Initialize() { |
29 void ShowIdleLogoutDialog() { | 34 g_kiosk_mode_idle_logout.Get(); |
30 chromeos::IdleLogoutDialogView::ShowDialog(); | |
31 } | 35 } |
32 | 36 |
33 void CloseIdleLogoutDialog() { | |
34 chromeos::IdleLogoutDialogView::CloseDialog(); | |
35 } | |
36 | |
37 } // namespace browser | |
38 | |
39 namespace chromeos { | |
40 | |
41 KioskModeIdleLogout::KioskModeIdleLogout() { | 37 KioskModeIdleLogout::KioskModeIdleLogout() { |
42 if (chromeos::KioskModeSettings::Get()->is_initialized()) | 38 if (KioskModeSettings::Get()->is_initialized()) |
43 Setup(); | 39 Setup(); |
44 else | 40 else |
45 chromeos::KioskModeSettings::Get()->Initialize( | 41 KioskModeSettings::Get()->Initialize(base::Bind(&KioskModeIdleLogout::Setup, |
46 base::Bind(&KioskModeIdleLogout::Setup, | 42 base::Unretained(this))); |
47 base::Unretained(this))); | |
48 } | 43 } |
49 | 44 |
50 void KioskModeIdleLogout::Setup() { | 45 void KioskModeIdleLogout::Setup() { |
51 if (UserManager::Get()->IsLoggedInAsDemoUser()) { | 46 if (UserManager::Get()->IsLoggedInAsDemoUser()) { |
52 // This means that we're recovering from a crash; user is already | 47 // This means that we're recovering from a crash; user is already |
53 // logged in, go ahead and setup the notifications. | 48 // logged in, go ahead and setup the notifications. |
54 // We might get notified twice for the same idle event, in case the | 49 // We might get notified twice for the same idle event, in case the |
55 // previous notification hasn't fired yet - but that's taken care of | 50 // previous notification hasn't fired yet - but that's taken care of |
56 // in the IdleLogout dialog; if you try to show another while one is | 51 // in the IdleLogout dialog; if you try to show another while one is |
57 // still showing, it'll just be ignored. | 52 // still showing, it'll just be ignored. |
(...skipping 13 matching lines...) Expand all Loading... |
71 SetupIdleNotifications(); | 66 SetupIdleNotifications(); |
72 RequestNextIdleNotification(); | 67 RequestNextIdleNotification(); |
73 } | 68 } |
74 } | 69 } |
75 | 70 |
76 void KioskModeIdleLogout::IdleNotify(int64 threshold) { | 71 void KioskModeIdleLogout::IdleNotify(int64 threshold) { |
77 // We're idle, next time we go active, we need to know so we can remove | 72 // We're idle, next time we go active, we need to know so we can remove |
78 // the logout dialog if it's still up. | 73 // the logout dialog if it's still up. |
79 RequestNextActiveNotification(); | 74 RequestNextActiveNotification(); |
80 | 75 |
81 browser::ShowIdleLogoutDialog(); | 76 IdleLogoutDialogView::ShowDialog(); |
82 } | 77 } |
83 | 78 |
84 void KioskModeIdleLogout::ActiveNotify() { | 79 void KioskModeIdleLogout::ActiveNotify() { |
85 // Before anything else, close the logout dialog to prevent restart | 80 // Before anything else, close the logout dialog to prevent restart |
86 browser::CloseIdleLogoutDialog(); | 81 IdleLogoutDialogView::CloseDialog(); |
87 | 82 |
88 // Now that we're active, register a request for notification for | 83 // Now that we're active, register a request for notification for |
89 // the next time we go idle. | 84 // the next time we go idle. |
90 RequestNextIdleNotification(); | 85 RequestNextIdleNotification(); |
91 } | 86 } |
92 | 87 |
93 void KioskModeIdleLogout::SetupIdleNotifications() { | 88 void KioskModeIdleLogout::SetupIdleNotifications() { |
94 chromeos::PowerManagerClient* power_manager = | 89 PowerManagerClient* power_manager = |
95 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | 90 DBusThreadManager::Get()->GetPowerManagerClient(); |
96 if (!power_manager->HasObserver(this)) | 91 if (!power_manager->HasObserver(this)) |
97 power_manager->AddObserver(this); | 92 power_manager->AddObserver(this); |
98 } | 93 } |
99 | 94 |
100 void KioskModeIdleLogout::RequestNextActiveNotification() { | 95 void KioskModeIdleLogout::RequestNextActiveNotification() { |
101 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 96 DBusThreadManager::Get()->GetPowerManagerClient()-> |
102 RequestActiveNotification(); | 97 RequestActiveNotification(); |
103 } | 98 } |
104 | 99 |
105 void KioskModeIdleLogout::RequestNextIdleNotification() { | 100 void KioskModeIdleLogout::RequestNextIdleNotification() { |
106 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 101 DBusThreadManager::Get()->GetPowerManagerClient()-> |
107 RequestIdleNotification(chromeos::KioskModeSettings::Get()-> | 102 RequestIdleNotification(KioskModeSettings::Get()-> |
108 GetIdleLogoutTimeout().InMilliseconds()); | 103 GetIdleLogoutTimeout().InMilliseconds()); |
109 } | 104 } |
110 | 105 |
111 static base::LazyInstance<KioskModeIdleLogout> | |
112 g_kiosk_mode_idle_logout = LAZY_INSTANCE_INITIALIZER; | |
113 | |
114 void InitializeKioskModeIdleLogout() { | |
115 g_kiosk_mode_idle_logout.Get(); | |
116 } | |
117 | |
118 } // namespace chromeos | 106 } // namespace chromeos |
OLD | NEW |