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