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