OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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/login/app_launch_controller.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/time/time.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" |
| 13 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 14 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h" |
| 15 #include "chrome/browser/chromeos/login/login_display_host.h" |
| 16 #include "chrome/browser/chromeos/login/oobe_display.h" |
| 17 #include "chrome/browser/lifetime/application_lifetime.h" |
| 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handle
r.h" |
| 20 #include "content/public/browser/browser_thread.h" |
| 21 |
| 22 namespace chromeos { |
| 23 |
| 24 namespace { |
| 25 |
| 26 // Application install splash screen minimum show time in milliseconds. |
| 27 const int kAppInstallSplashScreenMinTimeMS = 3000; |
| 28 |
| 29 } // namespace |
| 30 |
| 31 // static |
| 32 bool AppLaunchController::skip_splash_wait_ = false; |
| 33 |
| 34 AppLaunchController::AppLaunchController(const std::string& app_id, |
| 35 LoginDisplayHost* host, |
| 36 OobeDisplay* oobe_display) |
| 37 : profile_(NULL), |
| 38 app_id_(app_id), |
| 39 host_(host), |
| 40 oobe_display_(oobe_display), |
| 41 app_launch_splash_screen_actor_( |
| 42 oobe_display_->GetAppLaunchSplashScreenActor()), |
| 43 launch_splash_start_time_(0) { |
| 44 } |
| 45 |
| 46 AppLaunchController::~AppLaunchController() { |
| 47 } |
| 48 |
| 49 void AppLaunchController::StartAppLaunch() { |
| 50 DVLOG(1) << "Starting kiosk mode..."; |
| 51 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); |
| 52 |
| 53 // TODO(tengs): Add a loading profile app launch state. |
| 54 app_launch_splash_screen_actor_->SetDelegate(this); |
| 55 app_launch_splash_screen_actor_->Show(app_id_); |
| 56 |
| 57 // KioskProfileLoader manages its own lifetime. |
| 58 kiosk_profile_loader_.reset( |
| 59 new KioskProfileLoader(KioskAppManager::Get(), app_id_, this)); |
| 60 kiosk_profile_loader_->Start(); |
| 61 } |
| 62 |
| 63 // static |
| 64 void AppLaunchController::SkipSplashWaitForTesting() { |
| 65 skip_splash_wait_ = true; |
| 66 } |
| 67 |
| 68 void AppLaunchController::OnConfigureNetwork() { |
| 69 // TODO(tengs): Implement network configuration in app launch. |
| 70 } |
| 71 |
| 72 void AppLaunchController::OnCancelAppLaunch() { |
| 73 if (KioskAppManager::Get()->GetDisableBailoutShortcut()) |
| 74 return; |
| 75 |
| 76 OnLaunchFailed(KioskAppLaunchError::USER_CANCEL); |
| 77 } |
| 78 |
| 79 void AppLaunchController::OnProfileLoaded(Profile* profile) { |
| 80 DVLOG(1) << "Profile loaded... Starting app launch."; |
| 81 profile_ = profile; |
| 82 |
| 83 // StartupAppLauncher manages its own lifetime. |
| 84 startup_app_launcher_.reset(new StartupAppLauncher(profile_, app_id_)); |
| 85 startup_app_launcher_->AddObserver(this); |
| 86 startup_app_launcher_->Start(); |
| 87 } |
| 88 |
| 89 void AppLaunchController::OnProfileLoadFailed( |
| 90 KioskAppLaunchError::Error error) { |
| 91 OnLaunchFailed(error); |
| 92 } |
| 93 |
| 94 void AppLaunchController::Cleanup() { |
| 95 kiosk_profile_loader_.reset(); |
| 96 startup_app_launcher_.reset(); |
| 97 |
| 98 if (host_) |
| 99 host_->Finalize(); |
| 100 } |
| 101 |
| 102 void AppLaunchController::OnLoadingOAuthFile() { |
| 103 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 104 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_AUTH_FILE); |
| 105 } |
| 106 |
| 107 void AppLaunchController::OnInitializingTokenService() { |
| 108 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 109 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE); |
| 110 } |
| 111 |
| 112 void AppLaunchController::OnInitializingNetwork() { |
| 113 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 114 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK); |
| 115 } |
| 116 |
| 117 void AppLaunchController::OnNetworkWaitTimedout() { |
| 118 } |
| 119 |
| 120 void AppLaunchController::OnInstallingApp() { |
| 121 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 122 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION); |
| 123 } |
| 124 |
| 125 void AppLaunchController::OnLaunchSucceeded() { |
| 126 const int64 time_taken_ms = (base::TimeTicks::Now() - |
| 127 base::TimeTicks::FromInternalValue(launch_splash_start_time_)). |
| 128 InMilliseconds(); |
| 129 |
| 130 // Enforce that we show app install splash screen for some minimum amount |
| 131 // of time. |
| 132 if (!skip_splash_wait_ && time_taken_ms < kAppInstallSplashScreenMinTimeMS) { |
| 133 content::BrowserThread::PostDelayedTask( |
| 134 content::BrowserThread::UI, |
| 135 FROM_HERE, |
| 136 base::Bind(&AppLaunchController::OnLaunchSucceeded, AsWeakPtr()), |
| 137 base::TimeDelta::FromMilliseconds( |
| 138 kAppInstallSplashScreenMinTimeMS - time_taken_ms)); |
| 139 return; |
| 140 } |
| 141 |
| 142 DVLOG(1) << "Kiosk launch succeeded!"; |
| 143 Cleanup(); |
| 144 } |
| 145 |
| 146 void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) { |
| 147 LOG(ERROR) << "Kiosk launch failed. Will now shut down."; |
| 148 DCHECK_NE(KioskAppLaunchError::NONE, error); |
| 149 |
| 150 // Saves the error and ends the session to go back to login screen. |
| 151 KioskAppLaunchError::Save(error); |
| 152 chrome::AttemptUserExit(); |
| 153 Cleanup(); |
| 154 } |
| 155 |
| 156 |
| 157 } // namespace chromeos |
OLD | NEW |