| 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 fdd7bc5f500525cc74e017c276ce6529e8a5cb83..cb2bf6dcae3fc0c533111ae7eaa157180477d986 100644
|
| --- a/chrome/browser/chromeos/app_mode/startup_app_launcher.cc
|
| +++ b/chrome/browser/chromeos/app_mode/startup_app_launcher.cc
|
| @@ -178,8 +178,7 @@ void StartupAppLauncher::RestartLauncher() {
|
| void StartupAppLauncher::MaybeInitializeNetwork() {
|
| network_ready_handled_ = false;
|
|
|
| - const Extension* extension = extensions::ExtensionSystem::Get(profile_)->
|
| - extension_service()->GetInstalledExtension(app_id_);
|
| + const Extension* extension = GetPrimaryAppExtension();
|
| bool crx_cached = KioskAppManager::Get()->HasCachedCrx(app_id_);
|
| const bool requires_network =
|
| (!extension && !crx_cached) ||
|
| @@ -247,9 +246,7 @@ void StartupAppLauncher::OnRefreshTokensLoaded() {
|
|
|
| void StartupAppLauncher::MaybeLaunchApp() {
|
| // Check if the app is offline enabled.
|
| - const Extension* extension = extensions::ExtensionSystem::Get(profile_)
|
| - ->extension_service()
|
| - ->GetInstalledExtension(app_id_);
|
| + const Extension* extension = GetPrimaryAppExtension();
|
| DCHECK(extension);
|
| const bool offline_enabled =
|
| extensions::OfflineEnabledInfo::IsOfflineEnabled(extension);
|
| @@ -289,14 +286,23 @@ void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id,
|
| return;
|
| }
|
|
|
| - if (success) {
|
| - MaybeLaunchApp();
|
| + if (extension_id == app_id_) {
|
| + if (success) {
|
| + MaybeInstallSecondaryApps();
|
| + } else {
|
| + LOG(ERROR) << "Failed to install the kiosk application app_id: "
|
| + << extension_id;
|
| + OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
|
| + }
|
| return;
|
| }
|
|
|
| - LOG(ERROR) << "Failed to install the kiosk application app_id: "
|
| - << extension_id;
|
| - OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
|
| + if (AreSecondaryAppsInstalled()) {
|
| + MaybeLaunchApp();
|
| + } else {
|
| + LOG(ERROR) << "Failed to install one or more secondary apps.";
|
| + OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
|
| + }
|
| }
|
|
|
| void StartupAppLauncher::OnKioskExtensionLoadedInCache(
|
| @@ -321,14 +327,57 @@ void StartupAppLauncher::OnKioskAppDataLoadStatusChanged(
|
| OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_DOWNLOAD);
|
| }
|
|
|
| +bool StartupAppLauncher::IsAnySecondaryAppPending() const {
|
| + DCHECK(HasSecondaryApps());
|
| + const extensions::Extension* extension = GetPrimaryAppExtension();
|
| + DCHECK(extension);
|
| + extensions::KioskModeInfo* info = extensions::KioskModeInfo::Get(extension);
|
| + for (const auto& id : info->secondary_app_ids) {
|
| + if (extensions::ExtensionSystem::Get(profile_)
|
| + ->extension_service()
|
| + ->pending_extension_manager()
|
| + ->IsIdPending(id)) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +bool StartupAppLauncher::AreSecondaryAppsInstalled() const {
|
| + DCHECK(HasSecondaryApps());
|
| + const extensions::Extension* extension = GetPrimaryAppExtension();
|
| + DCHECK(extension);
|
| + extensions::KioskModeInfo* info = extensions::KioskModeInfo::Get(extension);
|
| + for (const auto& id : info->secondary_app_ids) {
|
| + if (!extensions::ExtensionSystem::Get(profile_)
|
| + ->extension_service()
|
| + ->GetInstalledExtension(id)) {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +bool StartupAppLauncher::HasSecondaryApps() const {
|
| + const extensions::Extension* extension = GetPrimaryAppExtension();
|
| + DCHECK(extension);
|
| + return extensions::KioskModeInfo::HasSecondaryApps(extension);
|
| +}
|
| +
|
| +const extensions::Extension* StartupAppLauncher::GetPrimaryAppExtension()
|
| + const {
|
| + return extensions::ExtensionSystem::Get(profile_)
|
| + ->extension_service()
|
| + ->GetInstalledExtension(app_id_);
|
| +}
|
| +
|
| void StartupAppLauncher::LaunchApp() {
|
| if (!ready_to_launch_) {
|
| NOTREACHED();
|
| LOG(ERROR) << "LaunchApp() called but launcher is not initialized.";
|
| }
|
|
|
| - const Extension* extension = extensions::ExtensionSystem::Get(profile_)->
|
| - extension_service()->GetInstalledExtension(app_id_);
|
| + const Extension* extension = GetPrimaryAppExtension();
|
| CHECK(extension);
|
|
|
| if (!extensions::KioskModeInfo::IsKioskEnabled(extension)) {
|
| @@ -380,17 +429,47 @@ void StartupAppLauncher::BeginInstall() {
|
| return;
|
| }
|
|
|
| - if (extensions::ExtensionSystem::Get(profile_)
|
| - ->extension_service()
|
| - ->GetInstalledExtension(app_id_)) {
|
| - // Launch the app.
|
| - OnReadyToLaunch();
|
| + if (GetPrimaryAppExtension()) {
|
| + // Install secondary apps.
|
| + MaybeInstallSecondaryApps();
|
| } else {
|
| // The extension is skipped for installation due to some error.
|
| OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
|
| }
|
| }
|
|
|
| +void StartupAppLauncher::MaybeInstallSecondaryApps() {
|
| + if (!HasSecondaryApps()) {
|
| + // Launch the primary app.
|
| + MaybeLaunchApp();
|
| + return;
|
| + }
|
| +
|
| + if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) {
|
| + OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
|
| + return;
|
| + }
|
| +
|
| + extensions::KioskModeInfo* info =
|
| + extensions::KioskModeInfo::Get(GetPrimaryAppExtension());
|
| + KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids);
|
| + if (IsAnySecondaryAppPending()) {
|
| + delegate_->OnInstallingApp();
|
| + // Observe the crx installation events.
|
| + extensions::InstallTracker* tracker =
|
| + extensions::InstallTrackerFactory::GetForBrowserContext(profile_);
|
| + tracker->AddObserver(this);
|
| + return;
|
| + }
|
| +
|
| + if (AreSecondaryAppsInstalled()) {
|
| + // Launch the primary app.
|
| + MaybeLaunchApp();
|
| + } else {
|
| + OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
|
| + }
|
| +}
|
| +
|
| void StartupAppLauncher::OnReadyToLaunch() {
|
| ready_to_launch_ = true;
|
| UpdateAppData();
|
|
|