Chromium Code Reviews| Index: chrome/browser/chromeos/retail_mode/retail_mode_screen_locker.cc |
| diff --git a/chrome/browser/chromeos/retail_mode/retail_mode_screen_locker.cc b/chrome/browser/chromeos/retail_mode/retail_mode_screen_locker.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8a6d19464ad41b463dd6239aabebe90a226bb1f7 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/retail_mode/retail_mode_screen_locker.cc |
| @@ -0,0 +1,87 @@ |
| +// 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/retail_mode/retail_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/chromeos/dbus/dbus_thread_manager.h" |
| +#include "chrome/browser/chromeos/dbus/power_manager_client.h" |
| +#include "chrome/browser/ui/browser_dialogs.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" |
| + |
| + |
|
xiyuan
2012/01/26 19:34:18
nit: one blank line should be enough.
rkc
2012/01/26 21:36:06
Done.
|
| +namespace { |
| + |
| +const int64 kLoginIdleTimeout = 100; // seconds |
| + |
| +} // namespace |
| + |
| +namespace chromeos { |
| + |
| +class RetailModeLoginObserver : public PowerManagerClient::Observer, |
| + public content::NotificationObserver { |
|
xiyuan
2012/01/26 19:34:18
nit: alignment
rkc
2012/01/26 21:36:06
Done.
|
| + public: |
| + RetailModeLoginObserver() { |
| + 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::ShowRetailModeLogoutDialog(); |
| + } |
| + |
| + virtual void ActiveNotify() OVERRIDE { |
| + // Before anything else, close the logout dialog to prevent restart |
| + browser::CloseRetailModeLogoutDialog(); |
| + |
| + // 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(RetailModeLoginObserver); |
| +}; |
| + |
| +static base::LazyInstance<RetailModeLoginObserver> |
| + g_retail_mode_login_observer = LAZY_INSTANCE_INITIALIZER; |
| + |
| + |
|
xiyuan
2012/01/26 19:34:18
nit: one blank line.
rkc
2012/01/26 21:36:06
Done.
|
| +// static |
| +void RetailModeScreenLocker::InitClass() { |
| + g_retail_mode_login_observer.Get(); |
| +} |
| + |
| +} // namespace chromeos |