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