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/retail_mode/retail_mode_screen_locker.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/dbus/power_manager_client.h" |
| 13 #include "chrome/browser/ui/browser_dialogs.h" |
| 14 #include "chrome/browser/ui/webui/chromeos/retail_mode_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 ShowRetailModeLogoutDialog() { |
| 29 RetailModeLogoutDialog::ShowRetailModeLogoutDialog(); |
| 30 } |
| 31 |
| 32 void CloseRetailModeLogoutDialog() { |
| 33 RetailModeLogoutDialog::CloseRetailModeLogoutDialog(); |
| 34 } |
| 35 |
| 36 } // namespace browser |
| 37 |
| 38 namespace chromeos { |
| 39 |
| 40 class RetailModeLoginObserver : public PowerManagerClient::Observer, |
| 41 public content::NotificationObserver { |
| 42 public: |
| 43 RetailModeLoginObserver() { |
| 44 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 45 content::NotificationService::AllSources()); |
| 46 } |
| 47 |
| 48 // NotificationObserver overrides: |
| 49 virtual void Observe(int type, |
| 50 const content::NotificationSource& source, |
| 51 const content::NotificationDetails& details) OVERRIDE { |
| 52 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
| 53 // Register our observers only when a user logs on. |
| 54 chromeos::PowerManagerClient* power_manager = |
| 55 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
| 56 if (!power_manager->HasObserver(this)) |
| 57 power_manager->AddObserver(this); |
| 58 |
| 59 // Register for the next Idle for kLoginIdleTimeout event. |
| 60 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 61 RequestIdleNotification(kLoginIdleTimeout * 1000); |
| 62 } |
| 63 } |
| 64 |
| 65 virtual void IdleNotify(int64 threshold) OVERRIDE { |
| 66 // We're idle, next time we go active, we need to know so we can remove |
| 67 // the logout dialog if it's still up. |
| 68 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 69 RequestActiveNotification(); |
| 70 |
| 71 browser::ShowRetailModeLogoutDialog(); |
| 72 } |
| 73 |
| 74 virtual void ActiveNotify() OVERRIDE { |
| 75 // Before anything else, close the logout dialog to prevent restart |
| 76 browser::CloseRetailModeLogoutDialog(); |
| 77 |
| 78 // Now that we're active, register a request for notification for |
| 79 // the next time we go idle for kLoginIdleTimeout seconds. |
| 80 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 81 RequestIdleNotification(kLoginIdleTimeout * 1000); |
| 82 } |
| 83 |
| 84 private: |
| 85 content::NotificationRegistrar registrar_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(RetailModeLoginObserver); |
| 88 }; |
| 89 |
| 90 static base::LazyInstance<RetailModeLoginObserver> |
| 91 g_retail_mode_login_observer = LAZY_INSTANCE_INITIALIZER; |
| 92 |
| 93 // static |
| 94 void RetailModeScreenLocker::InitClass() { |
| 95 g_retail_mode_login_observer.Get(); |
| 96 } |
| 97 |
| 98 } // namespace chromeos |
OLD | NEW |