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/kiosk_mode/kiosk_mode_screensaver.h" | |
| 6 | |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 11 #include "chrome/browser/chromeos/ui/screensaver_extension_dialog.h" | |
| 12 #include "chrome/common/chrome_notification_types.h" | |
| 13 #include "content/public/browser/notification_service.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // This (along with screensaver location) will change once we have the | |
| 18 // retail mode enterprise policy set up. | |
| 19 const int64 kScreensaverIdleTimeout = 60; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 namespace chromeos { | |
| 24 | |
| 25 KioskModeScreensaver::KioskModeScreensaver() { | |
| 26 // We should NOT be created if already logged in. | |
| 27 CHECK(!chromeos::UserManager::Get()->user_is_logged_in()); | |
| 28 | |
| 29 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | |
| 30 content::NotificationService::AllSources()); | |
| 31 | |
| 32 // We will register ourselves now and unregister if a user logs in. | |
| 33 chromeos::PowerManagerClient* power_manager = | |
| 34 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
| 35 if (!power_manager->HasObserver(this)) | |
| 36 power_manager->AddObserver(this); | |
| 37 | |
| 38 // Register for the next Idle for kScreensaverIdleTimeout event. | |
| 39 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 40 RequestIdleNotification(kScreensaverIdleTimeout * 1000); | |
| 41 } | |
| 42 | |
| 43 KioskModeScreensaver::~KioskModeScreensaver() { | |
| 44 chromeos::PowerManagerClient* power_manager = | |
| 45 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
|
xiyuan
2012/02/27 18:26:30
When will this dtor be called? DBusThreadManager w
rkc
2012/02/27 22:24:43
As discussed, made changes to add a shutdown funct
| |
| 46 if (power_manager->HasObserver(this)) | |
| 47 power_manager->RemoveObserver(this); | |
| 48 } | |
| 49 | |
| 50 // NotificationObserver overrides: | |
| 51 void KioskModeScreensaver::Observe( | |
| 52 int type, | |
| 53 const content::NotificationSource& source, | |
| 54 const content::NotificationDetails& details) { | |
| 55 DCHECK_EQ(type, chrome::NOTIFICATION_LOGIN_USER_CHANGED); | |
| 56 // User logged in, remove our observers, screensaver will be deactivated. | |
| 57 chromeos::PowerManagerClient* power_manager = | |
| 58 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
| 59 if (power_manager->HasObserver(this)) | |
| 60 power_manager->RemoveObserver(this); | |
| 61 } | |
| 62 | |
| 63 void KioskModeScreensaver::IdleNotify(int64 threshold) { | |
| 64 // We're idle, next time we go active, we need to know so we can remove | |
| 65 // the logout dialog if it's still up. | |
| 66 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 67 RequestActiveNotification(); | |
| 68 | |
| 69 browser::ShowScreensaverDialog(); | |
| 70 } | |
| 71 | |
| 72 void KioskModeScreensaver::ActiveNotify() { | |
| 73 // Before anything else, close the logout dialog to prevent restart | |
| 74 browser::CloseScreensaverDialog(); | |
| 75 | |
| 76 // Now that we're active, register a request for notification for | |
| 77 // the next time we go idle for kScreensaverIdleTimeout seconds. | |
| 78 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 79 RequestIdleNotification(kScreensaverIdleTimeout * 1000); | |
| 80 } | |
| 81 | |
| 82 static base::LazyInstance<KioskModeScreensaver> | |
| 83 g_kiosk_mode_login_observer = LAZY_INSTANCE_INITIALIZER; | |
| 84 | |
| 85 void InitKioskModeScreensaver() { | |
| 86 g_kiosk_mode_login_observer.Get(); | |
| 87 } | |
| 88 | |
| 89 } // namespace chromeos | |
| OLD | NEW |