| 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..45072006ad78ec49a829b9e08b92c37f9e547d94 100644
|
| --- a/chrome/browser/chromeos/app_mode/startup_app_launcher.cc
|
| +++ b/chrome/browser/chromeos/app_mode/startup_app_launcher.cc
|
| @@ -36,6 +36,7 @@
|
| #include "extensions/common/constants.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
|
| +#include "extensions/common/manifest_handlers/kiosk_secondary_apps_info.h"
|
| #include "extensions/common/manifest_handlers/offline_enabled_info.h"
|
| #include "extensions/common/manifest_url_handlers.h"
|
| #include "google_apis/gaia/gaia_auth_consumer.h"
|
| @@ -178,8 +179,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 +247,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 +287,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 +328,59 @@ void StartupAppLauncher::OnKioskAppDataLoadStatusChanged(
|
| OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_DOWNLOAD);
|
| }
|
|
|
| +bool StartupAppLauncher::IsAnySecondaryAppPending() const {
|
| + DCHECK(HaveSecondaryApps());
|
| + const extensions::Extension* extension = GetPrimaryAppExtension();
|
| + DCHECK(extension);
|
| + extensions::KioskSecondaryAppsInfo* info =
|
| + extensions::KioskSecondaryAppsInfo::Get(extension);
|
| + for (size_t i = 0; i < info->ids.size(); ++i) {
|
| + if (extensions::ExtensionSystem::Get(profile_)
|
| + ->extension_service()
|
| + ->pending_extension_manager()
|
| + ->IsIdPending(info->ids[i])) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +bool StartupAppLauncher::AreSecondaryAppsInstalled() const {
|
| + DCHECK(HaveSecondaryApps());
|
| + const extensions::Extension* extension = GetPrimaryAppExtension();
|
| + DCHECK(extension);
|
| + extensions::KioskSecondaryAppsInfo* info =
|
| + extensions::KioskSecondaryAppsInfo::Get(extension);
|
| + for (size_t i = 0; i < info->ids.size(); ++i) {
|
| + if (!extensions::ExtensionSystem::Get(profile_)
|
| + ->extension_service()
|
| + ->GetInstalledExtension(info->ids[i])) {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +bool StartupAppLauncher::HaveSecondaryApps() const {
|
| + const extensions::Extension* extension = GetPrimaryAppExtension();
|
| + DCHECK(extension);
|
| + return extensions::KioskSecondaryAppsInfo::HaveSecondaryApps(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 +432,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 (!HaveSecondaryApps()) {
|
| + // Launch the primary app.
|
| + MaybeLaunchApp();
|
| + return;
|
| + }
|
| +
|
| + if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) {
|
| + OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
|
| + return;
|
| + }
|
| +
|
| + extensions::KioskSecondaryAppsInfo* info =
|
| + extensions::KioskSecondaryAppsInfo::Get(GetPrimaryAppExtension());
|
| + KioskAppManager::Get()->InstallSecondaryApps(info->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();
|
|
|