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/app_mode/startup_app_launcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 | 65 |
| 66 } // namespace | 66 } // namespace |
| 67 | 67 |
| 68 StartupAppLauncher::StartupAppLauncher(Profile* profile, | 68 StartupAppLauncher::StartupAppLauncher(Profile* profile, |
| 69 const std::string& app_id, | 69 const std::string& app_id, |
| 70 bool diagnostic_mode, | 70 bool diagnostic_mode, |
| 71 StartupAppLauncher::Delegate* delegate) | 71 StartupAppLauncher::Delegate* delegate) |
| 72 : profile_(profile), | 72 : profile_(profile), |
| 73 app_id_(app_id), | 73 app_id_(app_id), |
| 74 diagnostic_mode_(diagnostic_mode), | 74 diagnostic_mode_(diagnostic_mode), |
| 75 delegate_(delegate), | 75 delegate_(delegate) { |
| 76 network_ready_handled_(false), | |
| 77 launch_attempt_(0), | |
| 78 ready_to_launch_(false), | |
| 79 wait_for_crx_update_(false), | |
| 80 secondary_apps_updated_(false) { | |
| 81 DCHECK(profile_); | 76 DCHECK(profile_); |
| 82 DCHECK(crx_file::id_util::IdIsValid(app_id_)); | 77 DCHECK(crx_file::id_util::IdIsValid(app_id_)); |
| 83 KioskAppManager::Get()->AddObserver(this); | 78 KioskAppManager::Get()->AddObserver(this); |
| 84 } | 79 } |
| 85 | 80 |
| 86 StartupAppLauncher::~StartupAppLauncher() { | 81 StartupAppLauncher::~StartupAppLauncher() { |
| 87 KioskAppManager::Get()->RemoveObserver(this); | 82 KioskAppManager::Get()->RemoveObserver(this); |
| 88 | 83 |
| 89 // StartupAppLauncher can be deleted at anytime during the launch process | 84 // StartupAppLauncher can be deleted at anytime during the launch process |
| 90 // through a user bailout shortcut. | 85 // through a user bailout shortcut. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 BrowserThread::PostTask( | 257 BrowserThread::PostTask( |
| 263 BrowserThread::UI, | 258 BrowserThread::UI, |
| 264 FROM_HERE, | 259 FROM_HERE, |
| 265 base::Bind(&StartupAppLauncher::MaybeInitializeNetwork, AsWeakPtr())); | 260 base::Bind(&StartupAppLauncher::MaybeInitializeNetwork, AsWeakPtr())); |
| 266 return; | 261 return; |
| 267 } | 262 } |
| 268 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_LAUNCH); | 263 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_LAUNCH); |
| 269 } | 264 } |
| 270 } | 265 } |
| 271 | 266 |
| 267 void StartupAppLauncher::MaybeCheckExtensionUpdate() { | |
| 268 extensions::ExtensionUpdater* updater = | |
| 269 extensions::ExtensionSystem::Get(profile_) | |
| 270 ->extension_service() | |
| 271 ->updater(); | |
| 272 if (!delegate_->IsNetworkReady() || !updater) { | |
| 273 MaybeLaunchApp(); | |
| 274 return; | |
| 275 } | |
| 276 | |
| 277 // Enforce an immediate version update check for all extensions before | |
| 278 // launching the primary app. After the chromeos is updated, the shared | |
| 279 // module(e.g. ARC runtime) may need to be updated to a newer version | |
| 280 // compatible with the new chromeos. See crbug.com/555083. | |
| 281 extensions::ExtensionUpdater::CheckParams params; | |
| 282 params.install_immediately = true; | |
| 283 params.callback = base::Bind( | |
| 284 &StartupAppLauncher::OnExtensionUpdateCheckFinished, AsWeakPtr()); | |
| 285 updater->CheckNow(params); | |
| 286 extension_update_found_ = false; | |
| 287 registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND, | |
| 288 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.
| |
| 289 } | |
| 290 | |
| 291 void StartupAppLauncher::OnExtensionUpdateCheckFinished() { | |
| 292 if (extension_update_found_) { | |
| 293 // Disable and re-enable primary app to make sure any reference to the | |
| 294 // previous version of the shared module, extension, etc will be cleaned | |
| 295 // up and the new version will be loaded. | |
| 296 extensions::ExtensionSystem::Get(profile_) | |
| 297 ->extension_service() | |
| 298 ->DisableExtension(app_id_, Extension::DISABLE_RELOAD); | |
| 299 extensions::ExtensionSystem::Get(profile_) | |
| 300 ->extension_service() | |
| 301 ->EnableExtension(app_id_); | |
|
xiyuan
2015/12/02 21:04:20
Can we use ExtensionService::ReloadExtension?
jennyz
2015/12/03 00:27:55
Done.
| |
| 302 registrar_.Remove(this, extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND, | |
| 303 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.
| |
| 304 extension_update_found_ = false; | |
| 305 } | |
| 306 | |
| 307 MaybeLaunchApp(); | |
| 308 } | |
| 309 | |
| 310 void StartupAppLauncher::Observe(int type, | |
| 311 const content::NotificationSource& source, | |
| 312 const content::NotificationDetails& details) { | |
| 313 DCHECK(type == extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND); | |
| 314 typedef const std::pair<std::string, Version> UpdateDetails; | |
| 315 const std::string& id = content::Details<UpdateDetails>(details)->first; | |
| 316 const Version& version = content::Details<UpdateDetails>(details)->second; | |
| 317 VLOG(1) << "Found extension update id=" << id | |
| 318 << " version=" << version.GetString(); | |
| 319 extension_update_found_ = true; | |
| 320 } | |
| 321 | |
| 272 void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id, | 322 void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id, |
| 273 bool success) { | 323 bool success) { |
| 274 // Wait for pending updates or dependent extensions to download. | 324 // Wait for pending updates or dependent extensions to download. |
| 275 if (extensions::ExtensionSystem::Get(profile_) | 325 if (extensions::ExtensionSystem::Get(profile_) |
| 276 ->extension_service() | 326 ->extension_service() |
| 277 ->pending_extension_manager() | 327 ->pending_extension_manager() |
| 278 ->HasPendingExtensions()) { | 328 ->HasPendingExtensions()) { |
| 279 return; | 329 return; |
| 280 } | 330 } |
| 281 | 331 |
| 282 extensions::InstallTracker* tracker = | 332 extensions::InstallTracker* tracker = |
| 283 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); | 333 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); |
| 284 tracker->RemoveObserver(this); | 334 tracker->RemoveObserver(this); |
| 285 if (delegate_->IsShowingNetworkConfigScreen()) { | 335 if (delegate_->IsShowingNetworkConfigScreen()) { |
| 286 LOG(WARNING) << "Showing network config screen"; | 336 LOG(WARNING) << "Showing network config screen"; |
| 287 return; | 337 return; |
| 288 } | 338 } |
| 289 | 339 |
| 290 if (DidPrimaryOrSecondaryAppFailedToInstall(success, extension_id)) { | 340 if (DidPrimaryOrSecondaryAppFailedToInstall(success, extension_id)) { |
| 291 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 341 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
| 292 return; | 342 return; |
| 293 } | 343 } |
| 294 | 344 |
| 295 if (GetPrimaryAppExtension()) { | 345 if (GetPrimaryAppExtension()) { |
| 296 if (!secondary_apps_updated_) | 346 if (!secondary_apps_installed_) |
| 297 MaybeInstallSecondaryApps(); | 347 MaybeInstallSecondaryApps(); |
| 298 else | 348 else |
| 299 MaybeLaunchApp(); | 349 MaybeCheckExtensionUpdate(); |
| 300 } | 350 } |
| 301 } | 351 } |
| 302 | 352 |
| 303 void StartupAppLauncher::OnKioskExtensionLoadedInCache( | 353 void StartupAppLauncher::OnKioskExtensionLoadedInCache( |
| 304 const std::string& app_id) { | 354 const std::string& app_id) { |
| 305 OnKioskAppDataLoadStatusChanged(app_id); | 355 OnKioskAppDataLoadStatusChanged(app_id); |
| 306 } | 356 } |
| 307 | 357 |
| 308 void StartupAppLauncher::OnKioskExtensionDownloadFailed( | 358 void StartupAppLauncher::OnKioskExtensionDownloadFailed( |
| 309 const std::string& app_id) { | 359 const std::string& app_id) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 508 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
| 459 } | 509 } |
| 460 } | 510 } |
| 461 | 511 |
| 462 void StartupAppLauncher::MaybeInstallSecondaryApps() { | 512 void StartupAppLauncher::MaybeInstallSecondaryApps() { |
| 463 if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) { | 513 if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) { |
| 464 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 514 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
| 465 return; | 515 return; |
| 466 } | 516 } |
| 467 | 517 |
| 468 secondary_apps_updated_ = true; | 518 secondary_apps_installed_ = true; |
| 469 extensions::KioskModeInfo* info = | 519 extensions::KioskModeInfo* info = |
| 470 extensions::KioskModeInfo::Get(GetPrimaryAppExtension()); | 520 extensions::KioskModeInfo::Get(GetPrimaryAppExtension()); |
| 471 KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids); | 521 KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids); |
| 472 if (IsAnySecondaryAppPending()) { | 522 if (IsAnySecondaryAppPending()) { |
| 473 delegate_->OnInstallingApp(); | 523 delegate_->OnInstallingApp(); |
| 474 // Observe the crx installation events. | 524 // Observe the crx installation events. |
| 475 extensions::InstallTracker* tracker = | 525 extensions::InstallTracker* tracker = |
| 476 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); | 526 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); |
| 477 tracker->AddObserver(this); | 527 tracker->AddObserver(this); |
| 478 return; | 528 return; |
| 479 } | 529 } |
| 480 | 530 |
| 481 if (AreSecondaryAppsInstalled()) { | 531 if (AreSecondaryAppsInstalled()) { |
| 482 // Launch the primary app. | 532 // Check extension update before launching the primary kiosk app. |
| 483 MaybeLaunchApp(); | 533 MaybeCheckExtensionUpdate(); |
| 484 } else { | 534 } else { |
| 485 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 535 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
| 486 } | 536 } |
| 487 } | 537 } |
| 488 | 538 |
| 489 void StartupAppLauncher::OnReadyToLaunch() { | 539 void StartupAppLauncher::OnReadyToLaunch() { |
| 490 ready_to_launch_ = true; | 540 ready_to_launch_ = true; |
| 491 UpdateAppData(); | 541 UpdateAppData(); |
| 492 delegate_->OnReadyToLaunch(); | 542 delegate_->OnReadyToLaunch(); |
| 493 } | 543 } |
| 494 | 544 |
| 495 void StartupAppLauncher::UpdateAppData() { | 545 void StartupAppLauncher::UpdateAppData() { |
| 496 KioskAppManager::Get()->ClearAppData(app_id_); | 546 KioskAppManager::Get()->ClearAppData(app_id_); |
| 497 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL); | 547 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL); |
| 498 } | 548 } |
| 499 | 549 |
| 500 } // namespace chromeos | 550 } // namespace chromeos |
| OLD | NEW |