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/webui/chromeos/idle_logout_dialog.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/notification_service.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 const int64 kLoginIdleTimeout = 100; // seconds |
| 23 |
| 24 } // namespace |
| 25 |
| 26 namespace browser { |
| 27 |
| 28 void ShowIdleLogoutDialog() { |
| 29 IdleLogoutDialog::ShowIdleLogoutDialog(); |
| 30 } |
| 31 |
| 32 void CloseIdleLogoutDialog() { |
| 33 IdleLogoutDialog::CloseIdleLogoutDialog(); |
| 34 } |
| 35 |
| 36 } // namespace browser |
| 37 |
| 38 namespace chromeos { |
| 39 |
| 40 KioskModeIdleLogout::KioskModeIdleLogout() { |
| 41 if (chromeos::KioskModeHelper::Get()->is_initialized()) |
| 42 Setup(); |
| 43 else |
| 44 chromeos::KioskModeHelper::Get()->Initialize( |
| 45 base::Bind(&KioskModeIdleLogout::Setup, |
| 46 base::Unretained(this))); |
| 47 } |
| 48 |
| 49 void KioskModeIdleLogout::Setup() { |
| 50 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 51 content::NotificationService::AllSources()); |
| 52 } |
| 53 |
| 54 void KioskModeIdleLogout::Observe( |
| 55 int type, |
| 56 const content::NotificationSource& source, |
| 57 const content::NotificationDetails& details) { |
| 58 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
| 59 // Register our observers only when a user logs on. |
| 60 chromeos::PowerManagerClient* power_manager = |
| 61 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
| 62 if (!power_manager->HasObserver(this)) |
| 63 power_manager->AddObserver(this); |
| 64 |
| 65 // Register for the next Idle for kLoginIdleTimeout event. |
| 66 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 67 RequestIdleNotification( |
| 68 chromeos::KioskModeHelper::Get()->GetIdleLogoutTimeout() * 1000); |
| 69 } |
| 70 } |
| 71 |
| 72 void KioskModeIdleLogout::IdleNotify(int64 threshold) { |
| 73 // 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 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 76 RequestActiveNotification(); |
| 77 |
| 78 browser::ShowIdleLogoutDialog(); |
| 79 } |
| 80 |
| 81 void KioskModeIdleLogout::ActiveNotify() { |
| 82 // Before anything else, close the logout dialog to prevent restart |
| 83 browser::CloseIdleLogoutDialog(); |
| 84 |
| 85 // Now that we're active, register a request for notification for |
| 86 // the next time we go idle for kLoginIdleTimeout seconds. |
| 87 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 88 RequestIdleNotification( |
| 89 chromeos::KioskModeHelper::Get()->GetIdleLogoutTimeout() * 1000); |
| 90 } |
| 91 |
| 92 static base::LazyInstance<KioskModeIdleLogout> |
| 93 g_kiosk_mode_idle_logout = LAZY_INSTANCE_INITIALIZER; |
| 94 |
| 95 void InitializeKioskModeIdleLogout() { |
| 96 g_kiosk_mode_idle_logout.Get(); |
| 97 } |
| 98 |
| 99 } // namespace chromeos |
OLD | NEW |