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/ui/views/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 KioskModeScreensaverObserver::KioskModeScreensaverObserver() { | |
| 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); | |
|
sky
2012/02/24 05:03:53
What if this object is deleted before you get the
rkc
2012/02/25 02:14:02
Very unlikely considering that this class lives fo
| |
| 37 | |
| 38 // Register for the next Idle for kScreensaverIdleTimeout event. | |
| 39 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 40 RequestIdleNotification(kScreensaverIdleTimeout * 1000); | |
| 41 } | |
| 42 | |
| 43 // NotificationObserver overrides: | |
| 44 void KioskModeScreensaverObserver::Observe(int type, | |
|
sky
2012/02/24 05:03:53
nit: wrap type onto the next line
rkc
2012/02/25 02:14:02
Done.
| |
| 45 const content::NotificationSource& source, | |
| 46 const content::NotificationDetails& details) { | |
| 47 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | |
|
sky
2012/02/24 05:03:53
Since you only register one type, this should be a
rkc
2012/02/25 02:14:02
Done.
| |
| 48 // User logged in, remove our observers, screensaver will be deactivated. | |
| 49 chromeos::PowerManagerClient* power_manager = | |
| 50 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
| 51 if (power_manager->HasObserver(this)) | |
| 52 power_manager->RemoveObserver(this); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void KioskModeScreensaverObserver::IdleNotify(int64 threshold) { | |
| 57 // We're idle, next time we go active, we need to know so we can remove | |
| 58 // the logout dialog if it's still up. | |
| 59 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 60 RequestActiveNotification(); | |
| 61 | |
| 62 browser::ShowScreensaverDialog(); | |
| 63 } | |
| 64 | |
| 65 void KioskModeScreensaverObserver::ActiveNotify() { | |
| 66 // Before anything else, close the logout dialog to prevent restart | |
| 67 browser::CloseScreensaverDialog(); | |
| 68 | |
| 69 // Now that we're active, register a request for notification for | |
| 70 // the next time we go idle for kScreensaverIdleTimeout seconds. | |
| 71 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 72 RequestIdleNotification(kScreensaverIdleTimeout * 1000); | |
| 73 } | |
| 74 | |
|
sky
2012/02/24 05:03:53
nit: only one newline here.
rkc
2012/02/25 02:14:02
Done.
| |
| 75 | |
| 76 | |
| 77 static base::LazyInstance<KioskModeScreensaverObserver> | |
| 78 g_kiosk_mode_login_observer = LAZY_INSTANCE_INITIALIZER; | |
| 79 | |
| 80 // static | |
| 81 void KioskModeScreensaver::InitClass() { | |
| 82 g_kiosk_mode_login_observer.Get(); | |
| 83 } | |
| 84 | |
| 85 } // namespace chromeos | |
| OLD | NEW |