| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/login/app_launch_controller.h" | 5 #include "chrome/browser/chromeos/login/app_launch_controller.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace chromeos { | 26 namespace chromeos { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Application install splash screen minimum show time in milliseconds. | 30 // Application install splash screen minimum show time in milliseconds. |
| 31 const int kAppInstallSplashScreenMinTimeMS = 3000; | 31 const int kAppInstallSplashScreenMinTimeMS = 3000; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 // static | |
| 36 bool AppLaunchController::skip_splash_wait_ = false; | |
| 37 | |
| 38 AppLaunchController::AppLaunchController(const std::string& app_id, | 35 AppLaunchController::AppLaunchController(const std::string& app_id, |
| 39 LoginDisplayHost* host, | 36 LoginDisplayHost* host, |
| 40 OobeDisplay* oobe_display) | 37 OobeDisplay* oobe_display) |
| 41 : profile_(NULL), | 38 : profile_(NULL), |
| 42 app_id_(app_id), | 39 app_id_(app_id), |
| 43 host_(host), | 40 host_(host), |
| 44 oobe_display_(oobe_display), | 41 oobe_display_(oobe_display), |
| 45 app_launch_splash_screen_actor_( | 42 app_launch_splash_screen_actor_( |
| 46 oobe_display_->GetAppLaunchSplashScreenActor()), | 43 oobe_display_->GetAppLaunchSplashScreenActor()), |
| 47 error_screen_actor_(oobe_display_->GetErrorScreenActor()), | 44 error_screen_actor_(oobe_display_->GetErrorScreenActor()), |
| 48 waiting_for_network_(false), | 45 waiting_for_network_(false), |
| 49 showing_network_dialog_(false), | 46 showing_network_dialog_(false), |
| 50 launch_splash_start_time_(0) { | 47 launch_splash_start_time_(0), |
| 48 skip_splash_wait_for_testing_(false), |
| 49 network_wait_time_(10), |
| 50 user_manager_for_testing_(NULL) { |
| 51 signin_screen_.reset(new AppLaunchSigninScreen( |
| 52 static_cast<OobeUI*>(oobe_display_), this)); |
| 51 } | 53 } |
| 52 | 54 |
| 53 AppLaunchController::~AppLaunchController() { | 55 AppLaunchController::~AppLaunchController() { |
| 54 } | 56 } |
| 55 | 57 |
| 56 void AppLaunchController::StartAppLaunch() { | 58 void AppLaunchController::StartAppLaunch() { |
| 57 DVLOG(1) << "Starting kiosk mode..."; | 59 DVLOG(1) << "Starting kiosk mode..."; |
| 58 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); | 60 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); |
| 59 | 61 |
| 60 // TODO(tengs): Add a loading profile app launch state. | 62 // TODO(tengs): Add a loading profile app launch state. |
| 61 app_launch_splash_screen_actor_->SetDelegate(this); | 63 app_launch_splash_screen_actor_->SetDelegate(this); |
| 62 app_launch_splash_screen_actor_->Show(app_id_); | 64 app_launch_splash_screen_actor_->Show(app_id_); |
| 63 | 65 |
| 64 kiosk_profile_loader_.reset( | 66 kiosk_profile_loader_.reset( |
| 65 new KioskProfileLoader(KioskAppManager::Get(), app_id_, this)); | 67 new KioskProfileLoader(KioskAppManager::Get(), app_id_, this)); |
| 66 kiosk_profile_loader_->Start(); | 68 kiosk_profile_loader_->Start(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 // static | |
| 70 void AppLaunchController::SkipSplashWaitForTesting() { | 71 void AppLaunchController::SkipSplashWaitForTesting() { |
| 71 skip_splash_wait_ = true; | 72 skip_splash_wait_for_testing_ = true; |
| 73 } |
| 74 |
| 75 void AppLaunchController::SetNetworkWaitForTesting(int wait_time_secs) { |
| 76 network_wait_time_ = wait_time_secs; |
| 77 } |
| 78 |
| 79 void AppLaunchController::SetUserManagerForTesting(UserManager* user_manager) { |
| 80 user_manager_for_testing_ = user_manager; |
| 81 signin_screen_->set_user_manager_for_testing(user_manager); |
| 72 } | 82 } |
| 73 | 83 |
| 74 void AppLaunchController::OnConfigureNetwork() { | 84 void AppLaunchController::OnConfigureNetwork() { |
| 75 DCHECK(profile_); | 85 DCHECK(profile_); |
| 76 showing_network_dialog_ = true; | 86 showing_network_dialog_ = true; |
| 77 const std::string& owner_email = UserManager::Get()->GetOwnerEmail(); | 87 const std::string& owner_email = GetUserManager()->GetOwnerEmail(); |
| 78 if (!owner_email.empty()) { | 88 if (!owner_email.empty()) { |
| 79 signin_screen_.reset(new AppLaunchSigninScreen( | |
| 80 static_cast<OobeUI*>(oobe_display_), this)); | |
| 81 signin_screen_->Show(); | 89 signin_screen_->Show(); |
| 82 } else { | 90 } else { |
| 83 // If kiosk mode was configured through enterprise policy, we may | 91 // If kiosk mode was configured through enterprise policy, we may |
| 84 // not have an owner user. | 92 // not have an owner user. |
| 85 // TODO(tengs): We need to figure out the appropriate security meausres | 93 // TODO(tengs): We need to figure out the appropriate security meausres |
| 86 // for this case. | 94 // for this case. |
| 87 NOTREACHED(); | 95 NOTREACHED(); |
| 88 } | 96 } |
| 89 } | 97 } |
| 90 | 98 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE); | 146 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE); |
| 139 } | 147 } |
| 140 | 148 |
| 141 void AppLaunchController::OnInitializingNetwork() { | 149 void AppLaunchController::OnInitializingNetwork() { |
| 142 app_launch_splash_screen_actor_->UpdateAppLaunchState( | 150 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 143 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK); | 151 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK); |
| 144 | 152 |
| 145 // Show the network configration dialog if network is not initialized | 153 // Show the network configration dialog if network is not initialized |
| 146 // after a brief wait time. | 154 // after a brief wait time. |
| 147 waiting_for_network_ = true; | 155 waiting_for_network_ = true; |
| 148 const int kNetworkConfigWaitSeconds = 10; | |
| 149 network_wait_timer_.Start( | 156 network_wait_timer_.Start( |
| 150 FROM_HERE, | 157 FROM_HERE, |
| 151 base::TimeDelta::FromSeconds(kNetworkConfigWaitSeconds), | 158 base::TimeDelta::FromSeconds(network_wait_time_), |
| 152 this, &AppLaunchController::OnNetworkWaitTimedout); | 159 this, &AppLaunchController::OnNetworkWaitTimedout); |
| 153 } | 160 } |
| 154 | 161 |
| 155 void AppLaunchController::OnNetworkWaitTimedout() { | 162 void AppLaunchController::OnNetworkWaitTimedout() { |
| 156 DCHECK(waiting_for_network_); | 163 DCHECK(waiting_for_network_); |
| 157 LOG(WARNING) << "OnNetworkWaitTimedout... connection = " | 164 LOG(WARNING) << "OnNetworkWaitTimedout... connection = " |
| 158 << net::NetworkChangeNotifier::GetConnectionType(); | 165 << net::NetworkChangeNotifier::GetConnectionType(); |
| 159 app_launch_splash_screen_actor_->ToggleNetworkConfig(true); | 166 app_launch_splash_screen_actor_->ToggleNetworkConfig(true); |
| 167 content::NotificationService::current()->Notify( |
| 168 chrome::NOTIFICATION_KIOSK_APP_LAUNCH_NO_NETWORK, |
| 169 content::NotificationService::AllSources(), |
| 170 content::NotificationService::NoDetails()); |
| 160 } | 171 } |
| 161 | 172 |
| 162 void AppLaunchController::OnInstallingApp() { | 173 void AppLaunchController::OnInstallingApp() { |
| 163 app_launch_splash_screen_actor_->UpdateAppLaunchState( | 174 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 164 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION); | 175 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION); |
| 165 | 176 |
| 166 network_wait_timer_.Stop(); | 177 network_wait_timer_.Stop(); |
| 167 app_launch_splash_screen_actor_->ToggleNetworkConfig(false); | 178 app_launch_splash_screen_actor_->ToggleNetworkConfig(false); |
| 168 | 179 |
| 169 // We have connectivity at this point, so we can skip the network | 180 // We have connectivity at this point, so we can skip the network |
| 170 // configuration dialog if it is being shown. | 181 // configuration dialog if it is being shown. |
| 171 if (showing_network_dialog_) { | 182 if (showing_network_dialog_) { |
| 172 app_launch_splash_screen_actor_->Show(app_id_); | 183 app_launch_splash_screen_actor_->Show(app_id_); |
| 173 showing_network_dialog_ = false; | 184 showing_network_dialog_ = false; |
| 174 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); | 185 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); |
| 175 } | 186 } |
| 176 } | 187 } |
| 177 | 188 |
| 178 void AppLaunchController::OnLaunchSucceeded() { | 189 void AppLaunchController::OnLaunchSucceeded() { |
| 179 const int64 time_taken_ms = (base::TimeTicks::Now() - | 190 const int64 time_taken_ms = (base::TimeTicks::Now() - |
| 180 base::TimeTicks::FromInternalValue(launch_splash_start_time_)). | 191 base::TimeTicks::FromInternalValue(launch_splash_start_time_)). |
| 181 InMilliseconds(); | 192 InMilliseconds(); |
| 182 | 193 |
| 183 // Enforce that we show app install splash screen for some minimum amount | 194 // Enforce that we show app install splash screen for some minimum amount |
| 184 // of time. | 195 // of time. |
| 185 if (!skip_splash_wait_ && time_taken_ms < kAppInstallSplashScreenMinTimeMS) { | 196 if (!skip_splash_wait_for_testing_ |
| 197 && time_taken_ms < kAppInstallSplashScreenMinTimeMS) { |
| 186 content::BrowserThread::PostDelayedTask( | 198 content::BrowserThread::PostDelayedTask( |
| 187 content::BrowserThread::UI, | 199 content::BrowserThread::UI, |
| 188 FROM_HERE, | 200 FROM_HERE, |
| 189 base::Bind(&AppLaunchController::OnLaunchSucceeded, AsWeakPtr()), | 201 base::Bind(&AppLaunchController::OnLaunchSucceeded, AsWeakPtr()), |
| 190 base::TimeDelta::FromMilliseconds( | 202 base::TimeDelta::FromMilliseconds( |
| 191 kAppInstallSplashScreenMinTimeMS - time_taken_ms)); | 203 kAppInstallSplashScreenMinTimeMS - time_taken_ms)); |
| 192 return; | 204 return; |
| 193 } | 205 } |
| 194 | 206 |
| 195 DVLOG(1) << "Kiosk launch succeeded!"; | 207 DVLOG(1) << "Kiosk launch succeeded!"; |
| 196 Cleanup(); | 208 Cleanup(); |
| 197 } | 209 } |
| 198 | 210 |
| 199 void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) { | 211 void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) { |
| 200 LOG(ERROR) << "Kiosk launch failed. Will now shut down."; | 212 LOG(ERROR) << "Kiosk launch failed. Will now shut down."; |
| 201 DCHECK_NE(KioskAppLaunchError::NONE, error); | 213 DCHECK_NE(KioskAppLaunchError::NONE, error); |
| 202 | 214 |
| 203 // Saves the error and ends the session to go back to login screen. | 215 // Saves the error and ends the session to go back to login screen. |
| 204 KioskAppLaunchError::Save(error); | 216 KioskAppLaunchError::Save(error); |
| 205 chrome::AttemptUserExit(); | 217 chrome::AttemptUserExit(); |
| 206 Cleanup(); | 218 Cleanup(); |
| 207 } | 219 } |
| 208 | 220 |
| 221 UserManager* AppLaunchController::GetUserManager() { |
| 222 return user_manager_for_testing_ ? |
| 223 user_manager_for_testing_ : UserManager::Get(); |
| 224 } |
| 225 |
| 209 } // namespace chromeos | 226 } // namespace chromeos |
| OLD | NEW |