Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/startup_app_launcher.cc |
| diff --git a/chrome/browser/chromeos/app_mode/startup_app_launcher.cc b/chrome/browser/chromeos/app_mode/startup_app_launcher.cc |
| index 151562451ca3f0d2db7d3ac29f007cd0d1dd4f76..7b4ee4fa2e9123e1dd87f275e6f779ec2142905d 100644 |
| --- a/chrome/browser/chromeos/app_mode/startup_app_launcher.cc |
| +++ b/chrome/browser/chromeos/app_mode/startup_app_launcher.cc |
| @@ -72,12 +72,7 @@ StartupAppLauncher::StartupAppLauncher(Profile* profile, |
| : profile_(profile), |
| app_id_(app_id), |
| diagnostic_mode_(diagnostic_mode), |
| - delegate_(delegate), |
| - network_ready_handled_(false), |
| - launch_attempt_(0), |
| - ready_to_launch_(false), |
| - wait_for_crx_update_(false), |
| - secondary_apps_updated_(false) { |
| + delegate_(delegate) { |
| DCHECK(profile_); |
| DCHECK(crx_file::id_util::IdIsValid(app_id_)); |
| KioskAppManager::Get()->AddObserver(this); |
| @@ -269,6 +264,61 @@ void StartupAppLauncher::MaybeLaunchApp() { |
| } |
| } |
| +void StartupAppLauncher::MaybeCheckExtensionUpdate() { |
| + extensions::ExtensionUpdater* updater = |
| + extensions::ExtensionSystem::Get(profile_) |
| + ->extension_service() |
| + ->updater(); |
| + if (!delegate_->IsNetworkReady() || !updater) { |
| + MaybeLaunchApp(); |
| + return; |
| + } |
| + |
| + // Enforce an immediate version update check for all extensions before |
| + // launching the primary app. After the chromeos is updated, the shared |
| + // module(e.g. ARC runtime) may need to be updated to a newer version |
| + // compatible with the new chromeos. See crbug.com/555083. |
| + extensions::ExtensionUpdater::CheckParams params; |
| + params.install_immediately = true; |
| + params.callback = base::Bind( |
| + &StartupAppLauncher::OnExtensionUpdateCheckFinished, AsWeakPtr()); |
| + updater->CheckNow(params); |
| + extension_update_found_ = false; |
| + registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND, |
| + content::NotificationService::AllSources()); |
|
xiyuan
2015/12/02 21:04:20
Move line 286-287 before updater->CheckNow() call,
jennyz
2015/12/03 00:27:54
Done.
|
| +} |
| + |
| +void StartupAppLauncher::OnExtensionUpdateCheckFinished() { |
| + if (extension_update_found_) { |
| + // Disable and re-enable primary app to make sure any reference to the |
| + // previous version of the shared module, extension, etc will be cleaned |
| + // up and the new version will be loaded. |
| + extensions::ExtensionSystem::Get(profile_) |
| + ->extension_service() |
| + ->DisableExtension(app_id_, Extension::DISABLE_RELOAD); |
| + extensions::ExtensionSystem::Get(profile_) |
| + ->extension_service() |
| + ->EnableExtension(app_id_); |
|
xiyuan
2015/12/02 21:04:20
Can we use ExtensionService::ReloadExtension?
jennyz
2015/12/03 00:27:55
Done.
|
| + registrar_.Remove(this, extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND, |
| + content::NotificationService::AllSources()); |
|
xiyuan
2015/12/02 21:04:20
Should we move this out of the "if"?
jennyz
2015/12/03 00:27:55
Done.
|
| + extension_update_found_ = false; |
| + } |
| + |
| + MaybeLaunchApp(); |
| +} |
| + |
| +void StartupAppLauncher::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + DCHECK(type == extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND); |
| + typedef const std::pair<std::string, Version> UpdateDetails; |
| + const std::string& id = content::Details<UpdateDetails>(details)->first; |
| + const Version& version = content::Details<UpdateDetails>(details)->second; |
| + VLOG(1) << "Found extension update id=" << id |
| + << " version=" << version.GetString(); |
| + extension_update_found_ = true; |
| +} |
| + |
| void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id, |
| bool success) { |
| // Wait for pending updates or dependent extensions to download. |
| @@ -293,10 +343,10 @@ void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id, |
| } |
| if (GetPrimaryAppExtension()) { |
| - if (!secondary_apps_updated_) |
| + if (!secondary_apps_installed_) |
| MaybeInstallSecondaryApps(); |
| else |
| - MaybeLaunchApp(); |
| + MaybeCheckExtensionUpdate(); |
| } |
| } |
| @@ -465,7 +515,7 @@ void StartupAppLauncher::MaybeInstallSecondaryApps() { |
| return; |
| } |
| - secondary_apps_updated_ = true; |
| + secondary_apps_installed_ = true; |
| extensions::KioskModeInfo* info = |
| extensions::KioskModeInfo::Get(GetPrimaryAppExtension()); |
| KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids); |
| @@ -479,8 +529,8 @@ void StartupAppLauncher::MaybeInstallSecondaryApps() { |
| } |
| if (AreSecondaryAppsInstalled()) { |
| - // Launch the primary app. |
| - MaybeLaunchApp(); |
| + // Check extension update before launching the primary kiosk app. |
| + MaybeCheckExtensionUpdate(); |
| } else { |
| OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
| } |