| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.h" | 5 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.h" |
| 6 | 6 |
| 7 #include "ash/screensaver/screensaver_view.h" | 7 #include "ash/screensaver/screensaver_view.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/wm/user_activity_detector.h" | 9 #include "ash/wm/user_activity_detector.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | 14 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
| 15 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 15 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 16 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
| 17 #include "chrome/browser/chromeos/login/webui_login_display_host.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/sandboxed_unpacker.h" | 19 #include "chrome/browser/extensions/sandboxed_unpacker.h" |
| 20 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_file_util.h" | 23 #include "chrome/common/extensions/extension_file_util.h" |
| 22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 24 | 26 |
| 25 using extensions::Extension; | 27 using extensions::Extension; |
| 26 using extensions::SandboxedUnpacker; | 28 using extensions::SandboxedUnpacker; |
| 27 | 29 |
| 28 namespace chromeos { | 30 namespace chromeos { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 content::BrowserThread::PostTask( | 123 content::BrowserThread::PostTask( |
| 122 content::BrowserThread::FILE, | 124 content::BrowserThread::FILE, |
| 123 FROM_HERE, | 125 FROM_HERE, |
| 124 base::Bind( | 126 base::Bind( |
| 125 &extension_file_util::DeleteFile, extension_base_path_, true)); | 127 &extension_file_util::DeleteFile, extension_base_path_, true)); |
| 126 } | 128 } |
| 127 | 129 |
| 128 // In case we're shutting down without ever triggering the active | 130 // In case we're shutting down without ever triggering the active |
| 129 // notification and/or logging in. | 131 // notification and/or logging in. |
| 130 if (ash::Shell::GetInstance() && | 132 if (ash::Shell::GetInstance() && |
| 131 ash::Shell::GetInstance()->user_activity_detector()) | 133 ash::Shell::GetInstance()->user_activity_detector() && |
| 134 ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) |
| 132 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 135 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| 133 registrar_.RemoveAll(); | |
| 134 } | 136 } |
| 135 | 137 |
| 136 void KioskModeScreensaver::GetScreensaverCrxPath() { | 138 void KioskModeScreensaver::GetScreensaverCrxPath() { |
| 137 chromeos::KioskModeSettings::Get()->GetScreensaverPath( | 139 chromeos::KioskModeSettings::Get()->GetScreensaverPath( |
| 138 base::Bind(&KioskModeScreensaver::ScreensaverPathCallback, | 140 base::Bind(&KioskModeScreensaver::ScreensaverPathCallback, |
| 139 weak_ptr_factory_.GetWeakPtr())); | 141 weak_ptr_factory_.GetWeakPtr())); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void KioskModeScreensaver::ScreensaverPathCallback( | 144 void KioskModeScreensaver::ScreensaverPathCallback( |
| 143 const FilePath& screensaver_crx) { | 145 const FilePath& screensaver_crx) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 171 void KioskModeScreensaver::SetupScreensaver( | 173 void KioskModeScreensaver::SetupScreensaver( |
| 172 scoped_refptr<Extension> extension, | 174 scoped_refptr<Extension> extension, |
| 173 const FilePath& extension_base_path) { | 175 const FilePath& extension_base_path) { |
| 174 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 175 extension_base_path_ = extension_base_path; | 177 extension_base_path_ = extension_base_path; |
| 176 | 178 |
| 177 // If the user is already logged in, don't need to display the screensaver. | 179 // If the user is already logged in, don't need to display the screensaver. |
| 178 if (chromeos::UserManager::Get()->IsUserLoggedIn()) | 180 if (chromeos::UserManager::Get()->IsUserLoggedIn()) |
| 179 return; | 181 return; |
| 180 | 182 |
| 181 // Add our observers for login and user active. | |
| 182 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, | |
| 183 content::NotificationService::AllSources()); | |
| 184 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); | 183 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); |
| 185 | 184 |
| 186 Profile* default_profile = ProfileManager::GetDefaultProfile(); | 185 Profile* default_profile = ProfileManager::GetDefaultProfile(); |
| 187 // Add the extension to the extension service and display the screensaver. | 186 // Add the extension to the extension service and display the screensaver. |
| 188 if (default_profile) { | 187 if (default_profile) { |
| 189 default_profile->GetExtensionService()->AddExtension(extension); | 188 default_profile->GetExtensionService()->AddExtension(extension); |
| 190 ash::ShowScreensaver(extension->GetFullLaunchURL()); | 189 ash::ShowScreensaver(extension->GetFullLaunchURL()); |
| 191 } else { | 190 } else { |
| 192 LOG(ERROR) << "Couldn't get default profile. Unable to load screensaver!"; | 191 LOG(ERROR) << "Couldn't get default profile. Unable to load screensaver!"; |
| 193 ShutdownKioskModeScreensaver(); | 192 ShutdownKioskModeScreensaver(); |
| 194 } | 193 } |
| 195 } | 194 } |
| 196 | 195 |
| 197 // NotificationObserver overrides: | |
| 198 void KioskModeScreensaver::Observe( | |
| 199 int type, | |
| 200 const content::NotificationSource& source, | |
| 201 const content::NotificationDetails& details) { | |
| 202 DCHECK_EQ(type, chrome::NOTIFICATION_SESSION_STARTED); | |
| 203 | |
| 204 registrar_.RemoveAll(); | |
| 205 | |
| 206 ash::CloseScreensaver(); | |
| 207 ShutdownKioskModeScreensaver(); | |
| 208 } | |
| 209 | |
| 210 void KioskModeScreensaver::OnUserActivity() { | 196 void KioskModeScreensaver::OnUserActivity() { |
| 211 // We don't want to handle further user notifications; we'll either login | 197 // We don't want to handle further user notifications; we'll either login |
| 212 // the user and close out or or at least close the screensaver. | 198 // the user and close out or or at least close the screensaver. |
| 213 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 199 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| 214 | 200 |
| 215 // User is active, log us in. | 201 // Find the retail mode login page. |
| 202 CHECK(WebUILoginDisplayHost::default_host()); |
| 203 WebUILoginDisplayHost* webui_host = |
| 204 static_cast<WebUILoginDisplayHost*>( |
| 205 WebUILoginDisplayHost::default_host()); |
| 206 OobeUI* oobe_ui = webui_host->GetOobeUI(); |
| 207 |
| 208 // Show the login spinner. |
| 209 CHECK(oobe_ui); |
| 210 oobe_ui->ShowRetailModeLoginSpinner(); |
| 211 |
| 212 // Close the screensaver, our login spinner is already showing. |
| 213 ash::CloseScreensaver(); |
| 214 |
| 215 // Log us in. |
| 216 ExistingUserController* controller = | 216 ExistingUserController* controller = |
| 217 ExistingUserController::current_controller(); | 217 ExistingUserController::current_controller(); |
| 218 CHECK(controller); |
| 219 controller->LoginAsDemoUser(); |
| 218 | 220 |
| 219 if (controller) { | 221 ShutdownKioskModeScreensaver(); |
| 220 // Logging in will shut us down and remove the screen saver. | |
| 221 controller->LoginAsDemoUser(); | |
| 222 } else { | |
| 223 // Remove the screensaver so the user can at least use the underlying | |
| 224 // login screen to be able to log in. | |
| 225 ash::CloseScreensaver(); | |
| 226 ShutdownKioskModeScreensaver(); | |
| 227 } | |
| 228 } | 222 } |
| 229 | 223 |
| 230 static KioskModeScreensaver* g_kiosk_mode_screensaver = NULL; | 224 static KioskModeScreensaver* g_kiosk_mode_screensaver = NULL; |
| 231 | 225 |
| 232 void InitializeKioskModeScreensaver() { | 226 void InitializeKioskModeScreensaver() { |
| 233 if (g_kiosk_mode_screensaver) { | 227 if (g_kiosk_mode_screensaver) { |
| 234 LOG(WARNING) << "Screensaver was already initialized"; | 228 LOG(WARNING) << "Screensaver was already initialized"; |
| 235 return; | 229 return; |
| 236 } | 230 } |
| 237 | 231 |
| 238 g_kiosk_mode_screensaver = new KioskModeScreensaver(); | 232 g_kiosk_mode_screensaver = new KioskModeScreensaver(); |
| 239 } | 233 } |
| 240 | 234 |
| 241 void ShutdownKioskModeScreensaver() { | 235 void ShutdownKioskModeScreensaver() { |
| 242 delete g_kiosk_mode_screensaver; | 236 delete g_kiosk_mode_screensaver; |
| 243 g_kiosk_mode_screensaver = NULL; | 237 g_kiosk_mode_screensaver = NULL; |
| 244 } | 238 } |
| 245 | 239 |
| 246 } // namespace chromeos | 240 } // namespace chromeos |
| OLD | NEW |