Chromium Code Reviews| 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/ui/webui/chromeos/login/oobe_ui.h" | |
|
xiyuan
2012/10/24 22:03:19
nit: sort alphabetically
rkc
2012/10/24 22:05:58
Done.
| |
| 16 #include "chrome/browser/chromeos/login/user_manager.h" | 17 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #include "chrome/browser/chromeos/login/webui_login_display_host.h" | |
| 17 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/sandboxed_unpacker.h" | 20 #include "chrome/browser/extensions/sandboxed_unpacker.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; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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()) |
| 132 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 134 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| 133 registrar_.RemoveAll(); | |
| 134 } | 135 } |
| 135 | 136 |
| 136 void KioskModeScreensaver::GetScreensaverCrxPath() { | 137 void KioskModeScreensaver::GetScreensaverCrxPath() { |
| 137 chromeos::KioskModeSettings::Get()->GetScreensaverPath( | 138 chromeos::KioskModeSettings::Get()->GetScreensaverPath( |
| 138 base::Bind(&KioskModeScreensaver::ScreensaverPathCallback, | 139 base::Bind(&KioskModeScreensaver::ScreensaverPathCallback, |
| 139 weak_ptr_factory_.GetWeakPtr())); | 140 weak_ptr_factory_.GetWeakPtr())); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void KioskModeScreensaver::ScreensaverPathCallback( | 143 void KioskModeScreensaver::ScreensaverPathCallback( |
| 143 const FilePath& screensaver_crx) { | 144 const FilePath& screensaver_crx) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 171 void KioskModeScreensaver::SetupScreensaver( | 172 void KioskModeScreensaver::SetupScreensaver( |
| 172 scoped_refptr<Extension> extension, | 173 scoped_refptr<Extension> extension, |
| 173 const FilePath& extension_base_path) { | 174 const FilePath& extension_base_path) { |
| 174 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 175 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 175 extension_base_path_ = extension_base_path; | 176 extension_base_path_ = extension_base_path; |
| 176 | 177 |
| 177 // If the user is already logged in, don't need to display the screensaver. | 178 // If the user is already logged in, don't need to display the screensaver. |
| 178 if (chromeos::UserManager::Get()->IsUserLoggedIn()) | 179 if (chromeos::UserManager::Get()->IsUserLoggedIn()) |
| 179 return; | 180 return; |
| 180 | 181 |
| 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); | 182 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); |
| 185 | 183 |
| 186 Profile* default_profile = ProfileManager::GetDefaultProfile(); | 184 Profile* default_profile = ProfileManager::GetDefaultProfile(); |
| 187 // Add the extension to the extension service and display the screensaver. | 185 // Add the extension to the extension service and display the screensaver. |
| 188 if (default_profile) { | 186 if (default_profile) { |
| 189 default_profile->GetExtensionService()->AddExtension(extension); | 187 default_profile->GetExtensionService()->AddExtension(extension); |
| 190 ash::ShowScreensaver(extension->GetFullLaunchURL()); | 188 ash::ShowScreensaver(extension->GetFullLaunchURL()); |
| 191 } else { | 189 } else { |
| 192 LOG(ERROR) << "Couldn't get default profile. Unable to load screensaver!"; | 190 LOG(ERROR) << "Couldn't get default profile. Unable to load screensaver!"; |
| 193 ShutdownKioskModeScreensaver(); | 191 ShutdownKioskModeScreensaver(); |
| 194 } | 192 } |
| 195 } | 193 } |
| 196 | 194 |
| 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() { | 195 void KioskModeScreensaver::OnUserActivity() { |
| 211 // We don't want to handle further user notifications; we'll either login | 196 // 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. | 197 // the user and close out or or at least close the screensaver. |
| 213 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 198 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| 214 | 199 |
| 215 // User is active, log us in. | 200 // Find the retail mode login page. |
| 201 CHECK(WebUILoginDisplayHost::default_host()); | |
| 202 WebUILoginDisplayHost* webui_host = | |
| 203 static_cast<WebUILoginDisplayHost*>( | |
| 204 WebUILoginDisplayHost::default_host()); | |
| 205 OobeUI* oobe_ui = webui_host->GetOobeUI(); | |
| 206 | |
| 207 // Show the login spinner. | |
| 208 CHECK(oobe_ui); | |
| 209 oobe_ui->ShowRetailModeLoginSpinner(); | |
| 210 | |
| 211 // Close the screensaver, our login spinner is already showing. | |
| 212 ash::CloseScreensaver(); | |
| 213 | |
| 214 // Log us in. | |
| 216 ExistingUserController* controller = | 215 ExistingUserController* controller = |
| 217 ExistingUserController::current_controller(); | 216 ExistingUserController::current_controller(); |
| 217 CHECK(controller); | |
| 218 controller->LoginAsDemoUser(); | |
| 218 | 219 |
| 219 if (controller) { | 220 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 } | 221 } |
| 229 | 222 |
| 230 static KioskModeScreensaver* g_kiosk_mode_screensaver = NULL; | 223 static KioskModeScreensaver* g_kiosk_mode_screensaver = NULL; |
| 231 | 224 |
| 232 void InitializeKioskModeScreensaver() { | 225 void InitializeKioskModeScreensaver() { |
| 233 if (g_kiosk_mode_screensaver) { | 226 if (g_kiosk_mode_screensaver) { |
| 234 LOG(WARNING) << "Screensaver was already initialized"; | 227 LOG(WARNING) << "Screensaver was already initialized"; |
| 235 return; | 228 return; |
| 236 } | 229 } |
| 237 | 230 |
| 238 g_kiosk_mode_screensaver = new KioskModeScreensaver(); | 231 g_kiosk_mode_screensaver = new KioskModeScreensaver(); |
| 239 } | 232 } |
| 240 | 233 |
| 241 void ShutdownKioskModeScreensaver() { | 234 void ShutdownKioskModeScreensaver() { |
| 235 if (ash::Shell::GetInstance()->user_activity_detector()->HasObserver( | |
| 236 g_kiosk_mode_screensaver)) | |
| 237 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver( | |
| 238 g_kiosk_mode_screensaver); | |
|
xiyuan
2012/10/24 22:03:19
There is similar code in KioskModeScreensaver's dt
rkc
2012/10/24 22:05:58
Crap, didn't realize this was already being handle
| |
| 239 | |
| 242 delete g_kiosk_mode_screensaver; | 240 delete g_kiosk_mode_screensaver; |
| 243 g_kiosk_mode_screensaver = NULL; | 241 g_kiosk_mode_screensaver = NULL; |
| 244 } | 242 } |
| 245 | 243 |
| 246 } // namespace chromeos | 244 } // namespace chromeos |
| OLD | NEW |