| 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/callback.h" |
| 7 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 8 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 12 #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/app_session_lifetime.h" |
| 13 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 14 #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/app_mode/startup_app_launcher.h" |
| 15 #include "chrome/browser/chromeos/login/login_display_host.h" | 16 #include "chrome/browser/chromeos/login/login_display_host.h" |
| 16 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 17 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // Application install splash screen minimum show time in milliseconds. | 31 // Application install splash screen minimum show time in milliseconds. |
| 31 const int kAppInstallSplashScreenMinTimeMS = 3000; | 32 const int kAppInstallSplashScreenMinTimeMS = 3000; |
| 32 | 33 |
| 33 } // namespace | 34 } // namespace |
| 34 | 35 |
| 35 // static | 36 // static |
| 36 bool AppLaunchController::skip_splash_wait_ = false; | 37 bool AppLaunchController::skip_splash_wait_ = false; |
| 38 int AppLaunchController::network_wait_time_ = 10; |
| 39 base::Closure* AppLaunchController::network_timeout_callback_ = NULL; |
| 40 UserManager* AppLaunchController::test_user_manager_ = NULL; |
| 37 | 41 |
| 38 AppLaunchController::AppLaunchController(const std::string& app_id, | 42 AppLaunchController::AppLaunchController(const std::string& app_id, |
| 39 LoginDisplayHost* host, | 43 LoginDisplayHost* host, |
| 40 OobeDisplay* oobe_display) | 44 OobeDisplay* oobe_display) |
| 41 : profile_(NULL), | 45 : profile_(NULL), |
| 42 app_id_(app_id), | 46 app_id_(app_id), |
| 43 host_(host), | 47 host_(host), |
| 44 oobe_display_(oobe_display), | 48 oobe_display_(oobe_display), |
| 45 app_launch_splash_screen_actor_( | 49 app_launch_splash_screen_actor_( |
| 46 oobe_display_->GetAppLaunchSplashScreenActor()), | 50 oobe_display_->GetAppLaunchSplashScreenActor()), |
| 47 error_screen_actor_(oobe_display_->GetErrorScreenActor()), | 51 error_screen_actor_(oobe_display_->GetErrorScreenActor()), |
| 48 waiting_for_network_(false), | 52 waiting_for_network_(false), |
| 53 network_wait_timedout_(false), |
| 49 showing_network_dialog_(false), | 54 showing_network_dialog_(false), |
| 50 launch_splash_start_time_(0) { | 55 launch_splash_start_time_(0) { |
| 56 signin_screen_.reset(new AppLaunchSigninScreen( |
| 57 static_cast<OobeUI*>(oobe_display_), this)); |
| 51 } | 58 } |
| 52 | 59 |
| 53 AppLaunchController::~AppLaunchController() { | 60 AppLaunchController::~AppLaunchController() { |
| 54 } | 61 } |
| 55 | 62 |
| 56 void AppLaunchController::StartAppLaunch() { | 63 void AppLaunchController::StartAppLaunch() { |
| 57 DVLOG(1) << "Starting kiosk mode..."; | 64 DVLOG(1) << "Starting kiosk mode..."; |
| 58 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); | 65 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); |
| 59 | 66 |
| 60 // TODO(tengs): Add a loading profile app launch state. | 67 // TODO(tengs): Add a loading profile app launch state. |
| 61 app_launch_splash_screen_actor_->SetDelegate(this); | 68 app_launch_splash_screen_actor_->SetDelegate(this); |
| 62 app_launch_splash_screen_actor_->Show(app_id_); | 69 app_launch_splash_screen_actor_->Show(app_id_); |
| 63 | 70 |
| 64 kiosk_profile_loader_.reset( | 71 kiosk_profile_loader_.reset( |
| 65 new KioskProfileLoader(KioskAppManager::Get(), app_id_, this)); | 72 new KioskProfileLoader(KioskAppManager::Get(), app_id_, this)); |
| 66 kiosk_profile_loader_->Start(); | 73 kiosk_profile_loader_->Start(); |
| 67 } | 74 } |
| 68 | 75 |
| 69 // static | |
| 70 void AppLaunchController::SkipSplashWaitForTesting() { | 76 void AppLaunchController::SkipSplashWaitForTesting() { |
| 71 skip_splash_wait_ = true; | 77 skip_splash_wait_ = true; |
| 72 } | 78 } |
| 73 | 79 |
| 80 void AppLaunchController::SetNetworkWaitForTesting(int wait_time_secs) { |
| 81 network_wait_time_ = wait_time_secs; |
| 82 } |
| 83 |
| 84 void AppLaunchController::SetNetworkTimeoutCallbackForTesting( |
| 85 base::Closure* callback) { |
| 86 network_timeout_callback_ = callback; |
| 87 } |
| 88 |
| 89 void AppLaunchController::SetUserManagerForTesting(UserManager* user_manager) { |
| 90 test_user_manager_ = user_manager; |
| 91 AppLaunchSigninScreen::SetUserManagerForTesting(user_manager); |
| 92 } |
| 93 |
| 74 void AppLaunchController::OnConfigureNetwork() { | 94 void AppLaunchController::OnConfigureNetwork() { |
| 75 DCHECK(profile_); | 95 DCHECK(profile_); |
| 76 showing_network_dialog_ = true; | 96 showing_network_dialog_ = true; |
| 77 const std::string& owner_email = UserManager::Get()->GetOwnerEmail(); | 97 const std::string& owner_email = GetUserManager()->GetOwnerEmail(); |
| 78 if (!owner_email.empty()) { | 98 if (!owner_email.empty()) { |
| 79 signin_screen_.reset(new AppLaunchSigninScreen( | |
| 80 static_cast<OobeUI*>(oobe_display_), this)); | |
| 81 signin_screen_->Show(); | 99 signin_screen_->Show(); |
| 82 } else { | 100 } else { |
| 83 // If kiosk mode was configured through enterprise policy, we may | 101 // If kiosk mode was configured through enterprise policy, we may |
| 84 // not have an owner user. | 102 // not have an owner user. |
| 85 // TODO(tengs): We need to figure out the appropriate security meausres | 103 // TODO(tengs): We need to figure out the appropriate security meausres |
| 86 // for this case. | 104 // for this case. |
| 87 NOTREACHED(); | 105 NOTREACHED(); |
| 88 } | 106 } |
| 89 } | 107 } |
| 90 | 108 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE); | 156 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE); |
| 139 } | 157 } |
| 140 | 158 |
| 141 void AppLaunchController::OnInitializingNetwork() { | 159 void AppLaunchController::OnInitializingNetwork() { |
| 142 app_launch_splash_screen_actor_->UpdateAppLaunchState( | 160 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 143 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK); | 161 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK); |
| 144 | 162 |
| 145 // Show the network configration dialog if network is not initialized | 163 // Show the network configration dialog if network is not initialized |
| 146 // after a brief wait time. | 164 // after a brief wait time. |
| 147 waiting_for_network_ = true; | 165 waiting_for_network_ = true; |
| 148 const int kNetworkConfigWaitSeconds = 10; | |
| 149 network_wait_timer_.Start( | 166 network_wait_timer_.Start( |
| 150 FROM_HERE, | 167 FROM_HERE, |
| 151 base::TimeDelta::FromSeconds(kNetworkConfigWaitSeconds), | 168 base::TimeDelta::FromSeconds(network_wait_time_), |
| 152 this, &AppLaunchController::OnNetworkWaitTimedout); | 169 this, &AppLaunchController::OnNetworkWaitTimedout); |
| 153 } | 170 } |
| 154 | 171 |
| 155 void AppLaunchController::OnNetworkWaitTimedout() { | 172 void AppLaunchController::OnNetworkWaitTimedout() { |
| 156 DCHECK(waiting_for_network_); | 173 DCHECK(waiting_for_network_); |
| 157 LOG(WARNING) << "OnNetworkWaitTimedout... connection = " | 174 LOG(WARNING) << "OnNetworkWaitTimedout... connection = " |
| 158 << net::NetworkChangeNotifier::GetConnectionType(); | 175 << net::NetworkChangeNotifier::GetConnectionType(); |
| 176 network_wait_timedout_ = true; |
| 159 app_launch_splash_screen_actor_->ToggleNetworkConfig(true); | 177 app_launch_splash_screen_actor_->ToggleNetworkConfig(true); |
| 178 if (network_timeout_callback_) |
| 179 network_timeout_callback_->Run(); |
| 160 } | 180 } |
| 161 | 181 |
| 162 void AppLaunchController::OnInstallingApp() { | 182 void AppLaunchController::OnInstallingApp() { |
| 163 app_launch_splash_screen_actor_->UpdateAppLaunchState( | 183 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 164 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION); | 184 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION); |
| 165 | 185 |
| 166 network_wait_timer_.Stop(); | 186 network_wait_timer_.Stop(); |
| 167 app_launch_splash_screen_actor_->ToggleNetworkConfig(false); | 187 app_launch_splash_screen_actor_->ToggleNetworkConfig(false); |
| 168 | 188 |
| 169 // We have connectivity at this point, so we can skip the network | 189 // We have connectivity at this point, so we can skip the network |
| (...skipping 29 matching lines...) Expand all Loading... |
| 199 void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) { | 219 void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) { |
| 200 LOG(ERROR) << "Kiosk launch failed. Will now shut down."; | 220 LOG(ERROR) << "Kiosk launch failed. Will now shut down."; |
| 201 DCHECK_NE(KioskAppLaunchError::NONE, error); | 221 DCHECK_NE(KioskAppLaunchError::NONE, error); |
| 202 | 222 |
| 203 // Saves the error and ends the session to go back to login screen. | 223 // Saves the error and ends the session to go back to login screen. |
| 204 KioskAppLaunchError::Save(error); | 224 KioskAppLaunchError::Save(error); |
| 205 chrome::AttemptUserExit(); | 225 chrome::AttemptUserExit(); |
| 206 Cleanup(); | 226 Cleanup(); |
| 207 } | 227 } |
| 208 | 228 |
| 229 UserManager* AppLaunchController::GetUserManager() { |
| 230 return test_user_manager_ ? test_user_manager_ : UserManager::Get(); |
| 231 } |
| 232 |
| 209 } // namespace chromeos | 233 } // namespace chromeos |
| OLD | NEW |