Chromium Code Reviews| Index: chrome/browser/chromeos/kiosk_mode/kiosk_mode_screen_locker.cc |
| diff --git a/chrome/browser/chromeos/kiosk_mode/kiosk_mode_screen_locker.cc b/chrome/browser/chromeos/kiosk_mode/kiosk_mode_screen_locker.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0330d0f7353a3aed4376d8d9f2db7c3feda5ff9d |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/kiosk_mode/kiosk_mode_screen_locker.cc |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_screen_locker.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/logging.h" |
| +#include "base/message_loop.h" |
| +#include "chrome/browser/ui/browser_dialogs.h" |
|
flackr
2012/01/20 16:16:58
nit: sort.
rkc
2012/01/26 03:37:23
Done.
|
| +#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| +#include "chrome/browser/chromeos/dbus/power_manager_client.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| +#include "content/public/browser/notification_service.h" |
| + |
| + |
| +namespace { |
|
xiyuan
2012/01/20 18:23:44
nit: blank line before and after code block in nam
rkc
2012/01/26 03:37:23
Done.
|
| +const int64 kLoginIdleTimeout = 100; // seconds |
|
xiyuan
2012/01/20 18:23:44
nit: This is not 2m. :)
rkc
2012/01/26 03:37:23
This is intended; this is meant to be idle time -
|
| +} // namespace |
| + |
| +namespace chromeos { |
| + |
| +class KioskModeLoginObserver : public PowerManagerClient::Observer, |
| + public content::NotificationObserver { |
| + public: |
| + KioskModeLoginObserver() { |
| + registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| + content::NotificationService::AllSources()); |
| + } |
| + |
| + // NotificationObserver overrides: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE { |
| + if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
| + // Register our observers only when a user logs on. |
| + chromeos::PowerManagerClient* power_manager = |
| + chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
| + if (!power_manager->HasObserver(this)) |
| + power_manager->AddObserver(this); |
| + |
| + // Register for the next Idle for kLoginIdleTimeout event. |
| + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| + RequestIdleNotification(kLoginIdleTimeout * 1000); |
| + } |
| + } |
| + |
| + virtual void IdleNotify(int64 threshold) OVERRIDE { |
| + // We're idle, next time we go active, we need to know so we can remove |
| + // the logout dialog if it's still up. |
| + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| + RequestActiveNotification(); |
| + |
| + browser::ShowKioskModeLogoutDialog(); |
| + } |
| + |
| + virtual void ActiveNotify() OVERRIDE { |
| + // Before anything else, close the logout dialog to prevent restart |
| + browser::CloseKioskModeLogoutDialog(); |
| + |
| + // Now that we're active, register a request for notification for |
| + // the next time we go idle for kLoginIdleTimeout seconds. |
| + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| + RequestIdleNotification(kLoginIdleTimeout * 1000); |
| + } |
| + |
| + private: |
| + content::NotificationRegistrar registrar_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(KioskModeLoginObserver); |
| +}; |
| + |
| +static base::LazyInstance<KioskModeLoginObserver> g_kiosk_mode_login_observer = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| + |
| +void KioskModeScreenLocker::InitClass() { |
| + g_kiosk_mode_login_observer.Get(); |
| +} |
| + |
| +} // namespace chromeos |