Chromium Code Reviews| 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/app_mode/startup_app_launcher.h" | 5 #include "chrome/browser/chromeos/login/app_launch_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
| 11 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 12 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 13 #include "base/values.h" | 11 #include "base/values.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" | 13 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" |
| 16 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 15 #include "chrome/browser/chromeos/login/login_display_host.h" | |
| 16 #include "chrome/browser/chromeos/login/oobe_display.h" | |
| 17 #include "chrome/browser/chromeos/login/user_manager.h" | 17 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #include "chrome/browser/chromeos/ui/app_launch_view.h" | |
| 19 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/extension_system.h" | 19 #include "chrome/browser/extensions/extension_system.h" |
| 21 #include "chrome/browser/extensions/webstore_startup_installer.h" | 20 #include "chrome/browser/extensions/webstore_startup_installer.h" |
| 22 #include "chrome/browser/lifetime/application_lifetime.h" | 21 #include "chrome/browser/lifetime/application_lifetime.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | |
| 23 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 23 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 25 #include "chrome/browser/signin/token_service.h" | 25 #include "chrome/browser/signin/token_service.h" |
| 26 #include "chrome/browser/signin/token_service_factory.h" | 26 #include "chrome/browser/signin/token_service_factory.h" |
| 27 #include "chrome/browser/ui/extensions/application_launch.h" | 27 #include "chrome/browser/ui/extensions/application_launch.h" |
| 28 #include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handle r.h" | |
| 28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
| 31 #include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h" | 32 #include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 34 #include "google_apis/gaia/gaia_auth_consumer.h" | 35 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 35 #include "google_apis/gaia/gaia_constants.h" | 36 #include "google_apis/gaia/gaia_constants.h" |
| 37 #include "ui/base/events/event.h" | |
| 36 | 38 |
| 37 using content::BrowserThread; | 39 using content::BrowserThread; |
| 38 using extensions::Extension; | 40 using extensions::Extension; |
| 39 using extensions::WebstoreStartupInstaller; | 41 using extensions::WebstoreStartupInstaller; |
| 40 | 42 |
| 41 namespace chromeos { | 43 namespace chromeos { |
| 42 | 44 |
| 43 namespace { | 45 namespace { |
| 44 | 46 |
| 45 const char kOAuthRefreshToken[] = "refresh_token"; | 47 const char kOAuthRefreshToken[] = "refresh_token"; |
| 46 const char kOAuthClientId[] = "client_id"; | 48 const char kOAuthClientId[] = "client_id"; |
| 47 const char kOAuthClientSecret[] = "client_secret"; | 49 const char kOAuthClientSecret[] = "client_secret"; |
| 48 | 50 |
| 49 const base::FilePath::CharType kOAuthFileName[] = | 51 const base::FilePath::CharType kOAuthFileName[] = |
| 50 FILE_PATH_LITERAL("kiosk_auth"); | 52 FILE_PATH_LITERAL("kiosk_auth"); |
| 51 | 53 |
| 52 // Application install splash screen minimum show time in milliseconds. | 54 // Application install splash screen minimum show time in milliseconds. |
| 53 const int kAppInstallSplashScreenMinTimeMS = 3000; | 55 const int kAppInstallSplashScreenMinTimeMS = 3000; |
| 54 | 56 |
| 55 bool IsAppInstalled(Profile* profile, const std::string& app_id) { | 57 bool IsAppInstalled(Profile* profile, const std::string& app_id) { |
| 56 return extensions::ExtensionSystem::Get(profile)->extension_service()-> | 58 return extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| 57 GetInstalledExtension(app_id); | 59 GetInstalledExtension(app_id); |
| 58 } | 60 } |
| 59 | 61 |
| 60 } // namespace | 62 } // namespace |
| 61 | 63 |
| 62 StartupAppLauncher::StartupAppLauncher(Profile* profile, | 64 AppLaunchController::AppLaunchController(const std::string& app_id, |
| 63 const std::string& app_id) | 65 LoginDisplayHost* host, |
| 64 : profile_(profile), | 66 OobeDisplay* oobe_display) |
| 67 : profile_(NULL), | |
| 65 app_id_(app_id), | 68 app_id_(app_id), |
| 69 host_(host), | |
| 70 oobe_display_(oobe_display), | |
| 66 launch_splash_start_time_(0) { | 71 launch_splash_start_time_(0) { |
| 67 DCHECK(profile_); | 72 app_launch_splash_screen_actor_= |
| 73 oobe_display_->GetAppLaunchSplashScreenActor(); | |
|
xiyuan
2013/08/15 18:19:42
nit: This can be part of the member initializer li
Tim Song
2013/08/16 19:07:59
Done.
| |
| 68 DCHECK(Extension::IdIsValid(app_id_)); | 74 DCHECK(Extension::IdIsValid(app_id_)); |
| 69 DCHECK(ash::Shell::HasInstance()); | |
| 70 ash::Shell::GetInstance()->AddPreTargetHandler(this); | |
| 71 } | 75 } |
| 72 | 76 |
| 73 StartupAppLauncher::~StartupAppLauncher() { | 77 AppLaunchController::~AppLaunchController() { |
| 74 DCHECK(ash::Shell::HasInstance()); | |
| 75 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | |
| 76 } | 78 } |
| 77 | 79 |
| 78 void StartupAppLauncher::Start() { | 80 void AppLaunchController::StartAppLaunch() { |
| 79 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); | 81 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); |
| 80 DVLOG(1) << "Starting... connection = " | 82 DVLOG(1) << "Starting app launch... connection = " |
| 81 << net::NetworkChangeNotifier::GetConnectionType(); | 83 << net::NetworkChangeNotifier::GetConnectionType(); |
| 82 chromeos::ShowAppLaunchSplashScreen(app_id_); | 84 |
| 83 StartLoadingOAuthFile(); | 85 // TODO(tengs): Add a loading profile app launch state. |
| 86 app_launch_splash_screen_actor_->SetDelegate(this); | |
| 87 app_launch_splash_screen_actor_->Show(app_id_); | |
| 88 | |
| 89 // KioskProfileLoader manages its own lifetime. | |
| 90 (new KioskProfileLoader(KioskAppManager::Get(), app_id_, this))->Start(); | |
|
xiyuan
2013/08/15 18:19:42
I know I started this managing-its-own-life thing
Tim Song
2013/08/16 19:07:59
Done. Now using a scoped_ptr.
| |
| 84 } | 91 } |
| 85 | 92 |
| 86 void StartupAppLauncher::StartLoadingOAuthFile() { | 93 void AppLaunchController::StartLoadingOAuthFile() { |
| 94 app_launch_splash_screen_actor_->UpdateAppLaunchState( | |
| 95 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_AUTH_FILE); | |
| 87 KioskOAuthParams* auth_params = new KioskOAuthParams(); | 96 KioskOAuthParams* auth_params = new KioskOAuthParams(); |
| 88 BrowserThread::PostBlockingPoolTaskAndReply( | 97 BrowserThread::PostBlockingPoolTaskAndReply( |
| 89 FROM_HERE, | 98 FROM_HERE, |
| 90 base::Bind(&StartupAppLauncher::LoadOAuthFileOnBlockingPool, | 99 base::Bind(&AppLaunchController::LoadOAuthFileOnBlockingPool, |
| 91 auth_params), | 100 auth_params), |
| 92 base::Bind(&StartupAppLauncher::OnOAuthFileLoaded, | 101 base::Bind(&AppLaunchController::OnOAuthFileLoaded, |
| 93 AsWeakPtr(), | 102 AsWeakPtr(), |
| 94 base::Owned(auth_params))); | 103 base::Owned(auth_params))); |
| 95 } | 104 } |
| 96 | 105 |
| 97 // static. | 106 // static. |
| 98 void StartupAppLauncher::LoadOAuthFileOnBlockingPool( | 107 void AppLaunchController::LoadOAuthFileOnBlockingPool( |
| 99 KioskOAuthParams* auth_params) { | 108 KioskOAuthParams* auth_params) { |
| 100 int error_code = JSONFileValueSerializer::JSON_NO_ERROR; | 109 int error_code = JSONFileValueSerializer::JSON_NO_ERROR; |
| 101 std::string error_msg; | 110 std::string error_msg; |
| 102 base::FilePath user_data_dir; | 111 base::FilePath user_data_dir; |
| 103 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 112 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
| 104 base::FilePath auth_file = user_data_dir.Append(kOAuthFileName); | 113 base::FilePath auth_file = user_data_dir.Append(kOAuthFileName); |
| 105 scoped_ptr<JSONFileValueSerializer> serializer( | 114 scoped_ptr<JSONFileValueSerializer> serializer( |
| 106 new JSONFileValueSerializer(user_data_dir.Append(kOAuthFileName))); | 115 new JSONFileValueSerializer(user_data_dir.Append(kOAuthFileName))); |
| 107 scoped_ptr<base::Value> value( | 116 scoped_ptr<base::Value> value( |
| 108 serializer->Deserialize(&error_code, &error_msg)); | 117 serializer->Deserialize(&error_code, &error_msg)); |
| 109 base::DictionaryValue* dict = NULL; | 118 base::DictionaryValue* dict = NULL; |
| 110 if (error_code != JSONFileValueSerializer::JSON_NO_ERROR || | 119 if (error_code != JSONFileValueSerializer::JSON_NO_ERROR || |
| 111 !value.get() || !value->GetAsDictionary(&dict)) { | 120 !value.get() || !value->GetAsDictionary(&dict)) { |
| 112 LOG(WARNING) << "Can't find auth file at " << auth_file.value(); | |
| 113 return; | 121 return; |
| 114 } | 122 } |
| 115 | 123 |
| 116 dict->GetString(kOAuthRefreshToken, &auth_params->refresh_token); | 124 dict->GetString(kOAuthRefreshToken, &auth_params->refresh_token); |
| 117 dict->GetString(kOAuthClientId, &auth_params->client_id); | 125 dict->GetString(kOAuthClientId, &auth_params->client_id); |
| 118 dict->GetString(kOAuthClientSecret, &auth_params->client_secret); | 126 dict->GetString(kOAuthClientSecret, &auth_params->client_secret); |
| 119 } | 127 } |
| 120 | 128 |
| 121 void StartupAppLauncher::OnOAuthFileLoaded(KioskOAuthParams* auth_params) { | 129 void AppLaunchController::OnOAuthFileLoaded(KioskOAuthParams* auth_params) { |
| 122 auth_params_ = *auth_params; | 130 auth_params_ = *auth_params; |
| 123 // Override chrome client_id and secret that will be used for identity | 131 // Override chrome client_id and secret that will be used for identity |
| 124 // API token minting. | 132 // API token minting. |
| 125 if (!auth_params_.client_id.empty() && !auth_params_.client_secret.empty()) { | 133 if (!auth_params_.client_id.empty() && !auth_params_.client_secret.empty()) { |
| 126 UserManager::Get()->SetAppModeChromeClientOAuthInfo( | 134 UserManager::Get()->SetAppModeChromeClientOAuthInfo( |
| 127 auth_params_.client_id, | 135 auth_params_.client_id, |
| 128 auth_params_.client_secret); | 136 auth_params_.client_secret); |
| 129 } | 137 } |
| 130 | 138 |
| 131 // If we are restarting chrome (i.e. on crash), we need to initialize | 139 // If we are restarting chrome (i.e. on crash), we need to initialize |
| 132 // TokenService as well. | 140 // TokenService as well. |
| 133 InitializeTokenService(); | 141 InitializeTokenService(); |
| 134 } | 142 } |
| 135 | 143 |
| 136 void StartupAppLauncher::InitializeNetwork() { | 144 void AppLaunchController::InitializeNetwork() { |
| 137 chromeos::UpdateAppLaunchSplashScreenState( | 145 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 138 chromeos::APP_LAUNCH_STATE_PREPARING_NETWORK); | 146 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK); |
| 147 | |
| 139 // Set a maximum allowed wait time for network. | 148 // Set a maximum allowed wait time for network. |
| 140 const int kMaxNetworkWaitSeconds = 5 * 60; | 149 const int kMaxNetworkWaitSeconds = 5 * 60; |
| 141 network_wait_timer_.Start( | 150 network_wait_timer_.Start( |
| 142 FROM_HERE, | 151 FROM_HERE, |
| 143 base::TimeDelta::FromSeconds(kMaxNetworkWaitSeconds), | 152 base::TimeDelta::FromSeconds(kMaxNetworkWaitSeconds), |
| 144 this, &StartupAppLauncher::OnNetworkWaitTimedout); | 153 this, &AppLaunchController::OnNetworkWaitTimedout); |
| 145 | 154 |
| 146 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 155 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 147 OnNetworkChanged(net::NetworkChangeNotifier::GetConnectionType()); | 156 OnNetworkChanged(net::NetworkChangeNotifier::GetConnectionType()); |
| 148 } | 157 } |
| 149 | 158 |
| 150 void StartupAppLauncher::InitializeTokenService() { | 159 void AppLaunchController::InitializeTokenService() { |
| 151 chromeos::UpdateAppLaunchSplashScreenState( | 160 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 152 chromeos::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE); | 161 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE); |
| 153 ProfileOAuth2TokenService* profile_token_service = | 162 ProfileOAuth2TokenService* profile_token_service = |
| 154 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 163 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 155 if (profile_token_service->RefreshTokenIsAvailable()) { | 164 if (profile_token_service->RefreshTokenIsAvailable()) { |
| 156 InitializeNetwork(); | 165 InitializeNetwork(); |
| 157 return; | 166 return; |
| 158 } | 167 } |
| 159 | 168 |
| 160 // At the end of this method, the execution will be put on hold until | 169 // At the end of this method, the execution will be put on hold until |
| 161 // ProfileOAuth2TokenService triggers either OnRefreshTokenAvailable or | 170 // ProfileOAuth2TokenService triggers either OnRefreshTokenAvailable or |
| 162 // OnRefreshTokensLoaded. Given that we want to handle exactly one event, | 171 // OnRefreshTokensLoaded. Given that we want to handle exactly one event, |
| 163 // whichever comes first, both handlers call RemoveObserver on PO2TS. Handling | 172 // whichever comes first, both handlers call RemoveObserver on PO2TS. Handling |
| 164 // any of the two events is the only way to resume the execution and enable | 173 // any of the two events is the only way to resume the execution and enable |
| 165 // Cleanup method to be called, self-invoking a destructor. In destructor | 174 // Cleanup method to be called, self-invoking a destructor. In destructor |
| 166 // StartupAppLauncher is no longer an observer of PO2TS and there is no need | 175 // AppLaunchController is no longer an observer of PO2TS and there is no need |
| 167 // to call RemoveObserver again. | 176 // to call RemoveObserver again. |
| 168 profile_token_service->AddObserver(this); | 177 profile_token_service->AddObserver(this); |
| 169 | 178 |
| 170 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 179 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 171 token_service->Initialize(GaiaConstants::kChromeSource, profile_); | 180 token_service->Initialize(GaiaConstants::kChromeSource, profile_); |
| 172 | 181 |
| 173 // Pass oauth2 refresh token from the auth file. | 182 // Pass oauth2 refresh token from the auth file. |
| 174 // TODO(zelidrag): We should probably remove this option after M27. | 183 // TODO(zelidrag): We should probably remove this option after M27. |
| 175 // TODO(fgorski): This can go when we have persistence implemented on PO2TS. | 184 // TODO(fgorski): This can go when we have persistence implemented on PO2TS. |
| 176 // Unless the code is no longer needed. | 185 // Unless the code is no longer needed. |
| 177 if (!auth_params_.refresh_token.empty()) { | 186 if (!auth_params_.refresh_token.empty()) { |
| 178 token_service->UpdateCredentialsWithOAuth2( | 187 token_service->UpdateCredentialsWithOAuth2( |
| 179 GaiaAuthConsumer::ClientOAuthResult( | 188 GaiaAuthConsumer::ClientOAuthResult( |
| 180 auth_params_.refresh_token, | 189 auth_params_.refresh_token, |
| 181 std::string(), // access_token | 190 std::string(), // access_token |
| 182 0)); // new_expires_in_secs | 191 0)); // new_expires_in_secs |
| 183 } else { | 192 } else { |
| 184 // Load whatever tokens we have stored there last time around. | 193 // Load whatever tokens we have stored there last time around. |
| 185 token_service->LoadTokensFromDB(); | 194 token_service->LoadTokensFromDB(); |
| 186 } | 195 } |
| 187 } | 196 } |
| 188 | 197 |
| 189 void StartupAppLauncher::OnRefreshTokenAvailable( | 198 void AppLaunchController::OnRefreshTokenAvailable( |
| 190 const std::string& account_id) { | 199 const std::string& account_id) { |
| 191 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | 200 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) |
| 192 ->RemoveObserver(this); | 201 ->RemoveObserver(this); |
| 193 InitializeNetwork(); | 202 InitializeNetwork(); |
| 194 } | 203 } |
| 195 | 204 |
| 196 void StartupAppLauncher::OnRefreshTokensLoaded() { | 205 void AppLaunchController::OnRefreshTokensLoaded() { |
| 197 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | 206 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) |
| 198 ->RemoveObserver(this); | 207 ->RemoveObserver(this); |
| 199 InitializeNetwork(); | 208 InitializeNetwork(); |
| 200 } | 209 } |
| 201 | 210 |
| 202 void StartupAppLauncher::Cleanup() { | 211 void AppLaunchController::OnConfigureNetwork() { |
| 203 chromeos::CloseAppLaunchSplashScreen(); | 212 // TODO(tengs): Implement network configuration in app launch. |
| 204 | |
| 205 delete this; | |
| 206 } | 213 } |
| 207 | 214 |
| 208 void StartupAppLauncher::OnLaunchSuccess() { | 215 void AppLaunchController::OnCancelAppLaunch() { |
| 216 if (KioskAppManager::Get()->GetDisableBailoutShortcut()) | |
| 217 return; | |
| 218 | |
| 219 OnLaunchFailure(KioskAppLaunchError::USER_CANCEL); | |
| 220 } | |
| 221 | |
| 222 void AppLaunchController::OnProfileLoaded(Profile* profile) { | |
| 223 profile_ = profile; | |
| 224 StartLoadingOAuthFile(); | |
| 225 } | |
| 226 | |
| 227 void AppLaunchController::OnProfileLoadFailed( | |
| 228 KioskAppLaunchError::Error error) { | |
| 229 OnLaunchFailure(error); | |
| 230 } | |
| 231 | |
| 232 void AppLaunchController::Cleanup() { | |
| 233 if (host_) | |
| 234 host_->Finalize(); | |
| 235 } | |
| 236 | |
| 237 void AppLaunchController::OnLaunchSuccess() { | |
| 209 const int64 time_taken_ms = (base::TimeTicks::Now() - | 238 const int64 time_taken_ms = (base::TimeTicks::Now() - |
| 210 base::TimeTicks::FromInternalValue(launch_splash_start_time_)). | 239 base::TimeTicks::FromInternalValue(launch_splash_start_time_)). |
| 211 InMilliseconds(); | 240 InMilliseconds(); |
| 212 | 241 |
| 213 // Enforce that we show app install splash screen for some minimum amount | 242 // Enforce that we show app install splash screen for some minimum amount |
| 214 // of time. | 243 // of time. |
| 215 if (time_taken_ms < kAppInstallSplashScreenMinTimeMS) { | 244 if (time_taken_ms < kAppInstallSplashScreenMinTimeMS) { |
| 216 BrowserThread::PostDelayedTask( | 245 BrowserThread::PostDelayedTask( |
| 217 BrowserThread::UI, | 246 BrowserThread::UI, |
| 218 FROM_HERE, | 247 FROM_HERE, |
| 219 base::Bind(&StartupAppLauncher::OnLaunchSuccess, AsWeakPtr()), | 248 base::Bind(&AppLaunchController::OnLaunchSuccess, AsWeakPtr()), |
| 220 base::TimeDelta::FromMilliseconds( | 249 base::TimeDelta::FromMilliseconds( |
| 221 kAppInstallSplashScreenMinTimeMS - time_taken_ms)); | 250 kAppInstallSplashScreenMinTimeMS - time_taken_ms)); |
| 222 return; | 251 return; |
| 223 } | 252 } |
| 224 | 253 |
| 225 Cleanup(); | 254 Cleanup(); |
| 226 } | 255 } |
| 227 | 256 |
| 228 void StartupAppLauncher::OnLaunchFailure(KioskAppLaunchError::Error error) { | 257 void AppLaunchController::OnLaunchFailure(KioskAppLaunchError::Error error) { |
| 229 DCHECK_NE(KioskAppLaunchError::NONE, error); | 258 DCHECK_NE(KioskAppLaunchError::NONE, error); |
| 230 | 259 |
| 231 // Saves the error and ends the session to go back to login screen. | 260 // Saves the error and ends the session to go back to login screen. |
| 232 KioskAppLaunchError::Save(error); | 261 KioskAppLaunchError::Save(error); |
| 233 chrome::AttemptUserExit(); | 262 chrome::AttemptUserExit(); |
| 234 | 263 |
| 235 Cleanup(); | 264 Cleanup(); |
| 236 } | 265 } |
| 237 | 266 |
| 238 void StartupAppLauncher::Launch() { | 267 void AppLaunchController::Launch() { |
| 239 const Extension* extension = extensions::ExtensionSystem::Get(profile_)-> | 268 const Extension* extension = extensions::ExtensionSystem::Get(profile_)-> |
| 240 extension_service()->GetInstalledExtension(app_id_); | 269 extension_service()->GetInstalledExtension(app_id_); |
| 241 CHECK(extension); | 270 CHECK(extension); |
| 242 | 271 |
| 243 if (!extensions::KioskEnabledInfo::IsKioskEnabled(extension)) { | 272 if (!extensions::KioskEnabledInfo::IsKioskEnabled(extension)) { |
| 244 OnLaunchFailure(KioskAppLaunchError::NOT_KIOSK_ENABLED); | 273 OnLaunchFailure(KioskAppLaunchError::NOT_KIOSK_ENABLED); |
| 245 return; | 274 return; |
| 246 } | 275 } |
| 247 | 276 |
| 248 // Always open the app in a window. | 277 // Always open the app in a window. |
| 249 chrome::OpenApplication(chrome::AppLaunchParams(profile_, | 278 chrome::OpenApplication(chrome::AppLaunchParams(profile_, |
| 250 extension, | 279 extension, |
| 251 extension_misc::LAUNCH_WINDOW, | 280 extension_misc::LAUNCH_WINDOW, |
| 252 NEW_WINDOW)); | 281 NEW_WINDOW)); |
| 253 InitAppSession(profile_, app_id_); | 282 InitAppSession(profile_, app_id_); |
| 254 | 283 |
| 255 content::NotificationService::current()->Notify( | 284 content::NotificationService::current()->Notify( |
| 256 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED, | 285 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED, |
| 257 content::NotificationService::AllSources(), | 286 content::NotificationService::AllSources(), |
| 258 content::NotificationService::NoDetails()); | 287 content::NotificationService::NoDetails()); |
| 259 | 288 |
| 260 OnLaunchSuccess(); | 289 OnLaunchSuccess(); |
| 261 } | 290 } |
| 262 | 291 |
| 263 void StartupAppLauncher::BeginInstall() { | 292 void AppLaunchController::BeginInstall() { |
| 264 DVLOG(1) << "BeginInstall... connection = " | 293 DVLOG(1) << "BeginInstall... connection = " |
| 265 << net::NetworkChangeNotifier::GetConnectionType(); | 294 << net::NetworkChangeNotifier::GetConnectionType(); |
| 266 | 295 |
| 267 chromeos::UpdateAppLaunchSplashScreenState( | 296 app_launch_splash_screen_actor_->UpdateAppLaunchState( |
| 268 chromeos::APP_LAUNCH_STATE_INSTALLING_APPLICATION); | 297 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION); |
| 269 | 298 |
| 270 if (IsAppInstalled(profile_, app_id_)) { | 299 if (IsAppInstalled(profile_, app_id_)) { |
| 271 Launch(); | 300 Launch(); |
| 272 return; | 301 return; |
| 273 } | 302 } |
| 274 | 303 |
| 275 installer_ = new WebstoreStartupInstaller( | 304 installer_ = new WebstoreStartupInstaller( |
| 276 app_id_, | 305 app_id_, |
| 277 profile_, | 306 profile_, |
| 278 false, | 307 false, |
| 279 base::Bind(&StartupAppLauncher::InstallCallback, AsWeakPtr())); | 308 base::Bind(&AppLaunchController::InstallCallback, AsWeakPtr())); |
| 280 installer_->BeginInstall(); | 309 installer_->BeginInstall(); |
| 281 } | 310 } |
| 282 | 311 |
| 283 void StartupAppLauncher::InstallCallback(bool success, | 312 void AppLaunchController::InstallCallback(bool success, |
| 284 const std::string& error) { | 313 const std::string& error) { |
| 285 installer_ = NULL; | 314 installer_ = NULL; |
| 286 if (success) { | 315 if (success) { |
| 287 // Schedules Launch() to be called after the callback returns. | 316 // Schedules Launch() to be called after the callback returns. |
| 288 // So that the app finishes its installation. | 317 // So that the app finishes its installation. |
| 289 BrowserThread::PostTask( | 318 BrowserThread::PostTask( |
| 290 BrowserThread::UI, | 319 BrowserThread::UI, |
| 291 FROM_HERE, | 320 FROM_HERE, |
| 292 base::Bind(&StartupAppLauncher::Launch, AsWeakPtr())); | 321 base::Bind(&AppLaunchController::Launch, AsWeakPtr())); |
| 293 return; | 322 return; |
| 294 } | 323 } |
| 295 | 324 |
| 296 LOG(ERROR) << "Failed to install app with error: " << error; | 325 LOG(ERROR) << "Failed to install app with error: " << error; |
| 297 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 326 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
| 298 } | 327 } |
| 299 | 328 |
| 300 void StartupAppLauncher::OnNetworkWaitTimedout() { | 329 void AppLaunchController::OnNetworkWaitTimedout() { |
| 301 LOG(WARNING) << "OnNetworkWaitTimedout... connection = " | 330 LOG(WARNING) << "OnNetworkWaitTimedout... connection = " |
| 302 << net::NetworkChangeNotifier::GetConnectionType(); | 331 << net::NetworkChangeNotifier::GetConnectionType(); |
| 303 // Timeout in waiting for online. Try the install anyway. | 332 // Timeout in waiting for online. Try the install anyway. |
| 304 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 333 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 305 BeginInstall(); | 334 BeginInstall(); |
| 306 } | 335 } |
| 307 | 336 |
| 308 void StartupAppLauncher::OnNetworkChanged( | 337 void AppLaunchController::OnNetworkChanged( |
| 309 net::NetworkChangeNotifier::ConnectionType type) { | 338 net::NetworkChangeNotifier::ConnectionType type) { |
| 310 DVLOG(1) << "OnNetworkChanged... connection = " | 339 DVLOG(1) << "OnNetworkChanged... connection = " |
| 311 << net::NetworkChangeNotifier::GetConnectionType(); | 340 << net::NetworkChangeNotifier::GetConnectionType(); |
| 312 if (!net::NetworkChangeNotifier::IsOffline()) { | 341 if (!net::NetworkChangeNotifier::IsOffline()) { |
| 313 DVLOG(1) << "Network up and running!"; | 342 DVLOG(1) << "Network up and running!"; |
| 314 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 343 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 315 network_wait_timer_.Stop(); | 344 network_wait_timer_.Stop(); |
| 316 | 345 |
| 317 BeginInstall(); | 346 BeginInstall(); |
| 318 } else { | 347 } else { |
| 319 DVLOG(1) << "Network not running yet!"; | 348 DVLOG(1) << "Network not running yet!"; |
| 320 } | 349 } |
| 321 } | 350 } |
| 322 | 351 |
| 323 void StartupAppLauncher::OnKeyEvent(ui::KeyEvent* event) { | |
| 324 if (event->type() != ui::ET_KEY_PRESSED) | |
| 325 return; | |
| 326 | |
| 327 if (KioskAppManager::Get()->GetDisableBailoutShortcut()) | |
| 328 return; | |
| 329 | |
| 330 if (event->key_code() != ui::VKEY_S || | |
| 331 !(event->flags() & ui::EF_CONTROL_DOWN) || | |
| 332 !(event->flags() & ui::EF_ALT_DOWN)) { | |
| 333 return; | |
| 334 } | |
| 335 | |
| 336 OnLaunchFailure(KioskAppLaunchError::USER_CANCEL); | |
| 337 } | |
| 338 | |
| 339 } // namespace chromeos | 352 } // namespace chromeos |
| OLD | NEW |