Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(855)

Side by Side Diff: chrome/browser/chromeos/app_mode/startup_app_launcher.cc

Issue 1488393002: Check import module update before launching the primary kiosk app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix browser tests and address code review commnents. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 extension_update_found_ = false;
286 registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND,
287 content::NotificationService::AllSources());
xiyuan 2015/12/03 00:46:53 Sorry for the confusion. I meant to moving this be
jennyz 2015/12/03 01:23:47 Done.
288 updater->CheckNow(params);
289 }
290
291 void StartupAppLauncher::OnExtensionUpdateCheckFinished() {
292 if (extension_update_found_) {
293 // Reload the primary app to make sure any reference to the previous version
294 // of the shared module, extension, etc will be cleaned up andthe new
295 // version will be loaded.
296 extensions::ExtensionSystem::Get(profile_)
297 ->extension_service()
298 ->ReloadExtension(app_id_);
299 extension_update_found_ = false;
300 }
301 registrar_.Remove(this, extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND,
302 content::NotificationService::AllSources());
303
304 MaybeLaunchApp();
305 }
306
307 void StartupAppLauncher::Observe(int type,
308 const content::NotificationSource& source,
309 const content::NotificationDetails& details) {
310 DCHECK(type == extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND);
311 typedef const std::pair<std::string, Version> UpdateDetails;
312 const std::string& id = content::Details<UpdateDetails>(details)->first;
313 const Version& version = content::Details<UpdateDetails>(details)->second;
314 VLOG(1) << "Found extension update id=" << id
315 << " version=" << version.GetString();
316 extension_update_found_ = true;
317 }
318
272 void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id, 319 void StartupAppLauncher::OnFinishCrxInstall(const std::string& extension_id,
273 bool success) { 320 bool success) {
274 // Wait for pending updates or dependent extensions to download. 321 // Wait for pending updates or dependent extensions to download.
275 if (extensions::ExtensionSystem::Get(profile_) 322 if (extensions::ExtensionSystem::Get(profile_)
276 ->extension_service() 323 ->extension_service()
277 ->pending_extension_manager() 324 ->pending_extension_manager()
278 ->HasPendingExtensions()) { 325 ->HasPendingExtensions()) {
279 return; 326 return;
280 } 327 }
281 328
282 extensions::InstallTracker* tracker = 329 extensions::InstallTracker* tracker =
283 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); 330 extensions::InstallTrackerFactory::GetForBrowserContext(profile_);
284 tracker->RemoveObserver(this); 331 tracker->RemoveObserver(this);
285 if (delegate_->IsShowingNetworkConfigScreen()) { 332 if (delegate_->IsShowingNetworkConfigScreen()) {
286 LOG(WARNING) << "Showing network config screen"; 333 LOG(WARNING) << "Showing network config screen";
287 return; 334 return;
288 } 335 }
289 336
290 if (DidPrimaryOrSecondaryAppFailedToInstall(success, extension_id)) { 337 if (DidPrimaryOrSecondaryAppFailedToInstall(success, extension_id)) {
291 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); 338 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
292 return; 339 return;
293 } 340 }
294 341
295 if (GetPrimaryAppExtension()) { 342 if (GetPrimaryAppExtension()) {
296 if (!secondary_apps_updated_) 343 if (!secondary_apps_installed_)
297 MaybeInstallSecondaryApps(); 344 MaybeInstallSecondaryApps();
298 else 345 else
299 MaybeLaunchApp(); 346 MaybeCheckExtensionUpdate();
300 } 347 }
301 } 348 }
302 349
303 void StartupAppLauncher::OnKioskExtensionLoadedInCache( 350 void StartupAppLauncher::OnKioskExtensionLoadedInCache(
304 const std::string& app_id) { 351 const std::string& app_id) {
305 OnKioskAppDataLoadStatusChanged(app_id); 352 OnKioskAppDataLoadStatusChanged(app_id);
306 } 353 }
307 354
308 void StartupAppLauncher::OnKioskExtensionDownloadFailed( 355 void StartupAppLauncher::OnKioskExtensionDownloadFailed(
309 const std::string& app_id) { 356 const std::string& app_id) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); 505 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
459 } 506 }
460 } 507 }
461 508
462 void StartupAppLauncher::MaybeInstallSecondaryApps() { 509 void StartupAppLauncher::MaybeInstallSecondaryApps() {
463 if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) { 510 if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) {
464 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); 511 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
465 return; 512 return;
466 } 513 }
467 514
468 secondary_apps_updated_ = true; 515 secondary_apps_installed_ = true;
469 extensions::KioskModeInfo* info = 516 extensions::KioskModeInfo* info =
470 extensions::KioskModeInfo::Get(GetPrimaryAppExtension()); 517 extensions::KioskModeInfo::Get(GetPrimaryAppExtension());
471 KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids); 518 KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids);
472 if (IsAnySecondaryAppPending()) { 519 if (IsAnySecondaryAppPending()) {
473 delegate_->OnInstallingApp(); 520 delegate_->OnInstallingApp();
474 // Observe the crx installation events. 521 // Observe the crx installation events.
475 extensions::InstallTracker* tracker = 522 extensions::InstallTracker* tracker =
476 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); 523 extensions::InstallTrackerFactory::GetForBrowserContext(profile_);
477 tracker->AddObserver(this); 524 tracker->AddObserver(this);
478 return; 525 return;
479 } 526 }
480 527
481 if (AreSecondaryAppsInstalled()) { 528 if (AreSecondaryAppsInstalled()) {
482 // Launch the primary app. 529 // Check extension update before launching the primary kiosk app.
483 MaybeLaunchApp(); 530 MaybeCheckExtensionUpdate();
484 } else { 531 } else {
485 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); 532 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
486 } 533 }
487 } 534 }
488 535
489 void StartupAppLauncher::OnReadyToLaunch() { 536 void StartupAppLauncher::OnReadyToLaunch() {
490 ready_to_launch_ = true; 537 ready_to_launch_ = true;
491 UpdateAppData(); 538 UpdateAppData();
492 delegate_->OnReadyToLaunch(); 539 delegate_->OnReadyToLaunch();
493 } 540 }
494 541
495 void StartupAppLauncher::UpdateAppData() { 542 void StartupAppLauncher::UpdateAppData() {
496 KioskAppManager::Get()->ClearAppData(app_id_); 543 KioskAppManager::Get()->ClearAppData(app_id_);
497 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL); 544 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL);
498 } 545 }
499 546
500 } // namespace chromeos 547 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698