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 extension_update_found_ = false; |
| 278 registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND, |
| 279 content::NotificationService::AllSources()); |
| 280 |
| 281 // Enforce an immediate version update check for all extensions before |
| 282 // launching the primary app. After the chromeos is updated, the shared |
| 283 // module(e.g. ARC runtime) may need to be updated to a newer version |
| 284 // compatible with the new chromeos. See crbug.com/555083. |
| 285 extensions::ExtensionUpdater::CheckParams params; |
| 286 params.install_immediately = true; |
| 287 params.callback = base::Bind( |
| 288 &StartupAppLauncher::OnExtensionUpdateCheckFinished, AsWeakPtr()); |
| 289 updater->CheckNow(params); |
| 290 } |
| 291 |
| 292 void StartupAppLauncher::OnExtensionUpdateCheckFinished() { |
| 293 if (extension_update_found_) { |
| 294 // Reload the primary app to make sure any reference to the previous version |
| 295 // of the shared module, extension, etc will be cleaned up andthe new |
| 296 // version will be loaded. |
| 297 extensions::ExtensionSystem::Get(profile_) |
| 298 ->extension_service() |
| 299 ->ReloadExtension(app_id_); |
| 300 extension_update_found_ = false; |
| 301 } |
| 302 registrar_.Remove(this, extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND, |
| 303 content::NotificationService::AllSources()); |
| 304 |
| 305 MaybeLaunchApp(); |
| 306 } |
| 307 |
| 308 void StartupAppLauncher::Observe(int type, |
| 309 const content::NotificationSource& source, |
| 310 const content::NotificationDetails& details) { |
| 311 DCHECK(type == extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND); |
| 312 typedef const std::pair<std::string, Version> UpdateDetails; |
| 313 const std::string& id = content::Details<UpdateDetails>(details)->first; |
| 314 const Version& version = content::Details<UpdateDetails>(details)->second; |
| 315 VLOG(1) << "Found extension update id=" << id |
| 316 << " version=" << version.GetString(); |
| 317 extension_update_found_ = true; |
| 318 } |
| 319 |
272 void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id, | 320 void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id, |
273 bool success) { | 321 bool success) { |
274 // Wait for pending updates or dependent extensions to download. | 322 // Wait for pending updates or dependent extensions to download. |
275 if (extensions::ExtensionSystem::Get(profile_) | 323 if (extensions::ExtensionSystem::Get(profile_) |
276 ->extension_service() | 324 ->extension_service() |
277 ->pending_extension_manager() | 325 ->pending_extension_manager() |
278 ->HasPendingExtensions()) { | 326 ->HasPendingExtensions()) { |
279 return; | 327 return; |
280 } | 328 } |
281 | 329 |
282 extensions::InstallTracker* tracker = | 330 extensions::InstallTracker* tracker = |
283 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); | 331 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); |
284 tracker->RemoveObserver(this); | 332 tracker->RemoveObserver(this); |
285 if (delegate_->IsShowingNetworkConfigScreen()) { | 333 if (delegate_->IsShowingNetworkConfigScreen()) { |
286 LOG(WARNING) << "Showing network config screen"; | 334 LOG(WARNING) << "Showing network config screen"; |
287 return; | 335 return; |
288 } | 336 } |
289 | 337 |
290 if (DidPrimaryOrSecondaryAppFailedToInstall(success, extension_id)) { | 338 if (DidPrimaryOrSecondaryAppFailedToInstall(success, extension_id)) { |
291 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 339 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
292 return; | 340 return; |
293 } | 341 } |
294 | 342 |
295 if (GetPrimaryAppExtension()) { | 343 if (GetPrimaryAppExtension()) { |
296 if (!secondary_apps_updated_) | 344 if (!secondary_apps_installed_) |
297 MaybeInstallSecondaryApps(); | 345 MaybeInstallSecondaryApps(); |
298 else | 346 else |
299 MaybeLaunchApp(); | 347 MaybeCheckExtensionUpdate(); |
300 } | 348 } |
301 } | 349 } |
302 | 350 |
303 void StartupAppLauncher::OnKioskExtensionLoadedInCache( | 351 void StartupAppLauncher::OnKioskExtensionLoadedInCache( |
304 const std::string& app_id) { | 352 const std::string& app_id) { |
305 OnKioskAppDataLoadStatusChanged(app_id); | 353 OnKioskAppDataLoadStatusChanged(app_id); |
306 } | 354 } |
307 | 355 |
308 void StartupAppLauncher::OnKioskExtensionDownloadFailed( | 356 void StartupAppLauncher::OnKioskExtensionDownloadFailed( |
309 const std::string& app_id) { | 357 const std::string& app_id) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 506 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
459 } | 507 } |
460 } | 508 } |
461 | 509 |
462 void StartupAppLauncher::MaybeInstallSecondaryApps() { | 510 void StartupAppLauncher::MaybeInstallSecondaryApps() { |
463 if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) { | 511 if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) { |
464 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 512 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
465 return; | 513 return; |
466 } | 514 } |
467 | 515 |
468 secondary_apps_updated_ = true; | 516 secondary_apps_installed_ = true; |
469 extensions::KioskModeInfo* info = | 517 extensions::KioskModeInfo* info = |
470 extensions::KioskModeInfo::Get(GetPrimaryAppExtension()); | 518 extensions::KioskModeInfo::Get(GetPrimaryAppExtension()); |
471 KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids); | 519 KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids); |
472 if (IsAnySecondaryAppPending()) { | 520 if (IsAnySecondaryAppPending()) { |
473 delegate_->OnInstallingApp(); | 521 delegate_->OnInstallingApp(); |
474 // Observe the crx installation events. | 522 // Observe the crx installation events. |
475 extensions::InstallTracker* tracker = | 523 extensions::InstallTracker* tracker = |
476 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); | 524 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); |
477 tracker->AddObserver(this); | 525 tracker->AddObserver(this); |
478 return; | 526 return; |
479 } | 527 } |
480 | 528 |
481 if (AreSecondaryAppsInstalled()) { | 529 if (AreSecondaryAppsInstalled()) { |
482 // Launch the primary app. | 530 // Check extension update before launching the primary kiosk app. |
483 MaybeLaunchApp(); | 531 MaybeCheckExtensionUpdate(); |
484 } else { | 532 } else { |
485 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); | 533 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); |
486 } | 534 } |
487 } | 535 } |
488 | 536 |
489 void StartupAppLauncher::OnReadyToLaunch() { | 537 void StartupAppLauncher::OnReadyToLaunch() { |
490 ready_to_launch_ = true; | 538 ready_to_launch_ = true; |
491 UpdateAppData(); | 539 UpdateAppData(); |
492 delegate_->OnReadyToLaunch(); | 540 delegate_->OnReadyToLaunch(); |
493 } | 541 } |
494 | 542 |
495 void StartupAppLauncher::UpdateAppData() { | 543 void StartupAppLauncher::UpdateAppData() { |
496 KioskAppManager::Get()->ClearAppData(app_id_); | 544 KioskAppManager::Get()->ClearAppData(app_id_); |
497 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL); | 545 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL); |
498 } | 546 } |
499 | 547 |
500 } // namespace chromeos | 548 } // namespace chromeos |
OLD | NEW |