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..88f3937ebe3583195a3172de3f52673437e4f11d |
--- /dev/null |
+++ b/chrome/browser/chromeos/retail_mode/retail_mode_screen_locker.cc |
@@ -0,0 +1,98 @@ |
+// 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/browser/ui/webui/chromeos/retail_mode_logout_dialog.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 { |
+ |
+const int64 kLoginIdleTimeout = 100; // seconds |
+ |
+} // namespace |
+ |
+namespace browser { |
+ |
+void ShowRetailModeLogoutDialog() { |
+ RetailModeLogoutDialog::ShowRetailModeLogoutDialog(); |
+} |
+ |
+void CloseRetailModeLogoutDialog() { |
+ RetailModeLogoutDialog::CloseRetailModeLogoutDialog(); |
+} |
+ |
+} // namespace browser |
+ |
+namespace chromeos { |
+ |
+class RetailModeLoginObserver : public PowerManagerClient::Observer, |
+ public content::NotificationObserver { |
+ 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; |
+ |
+// static |
+void RetailModeScreenLocker::InitClass() { |
+ g_retail_mode_login_observer.Get(); |
+} |
+ |
+} // namespace chromeos |