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

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

Issue 1301323005: Implement kiosk multiple apps feature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove the special case for disabling external cache for kiosk mode. Created 5 years, 3 months 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 LOG(WARNING) << "Installer still running"; 171 LOG(WARNING) << "Installer still running";
172 return; 172 return;
173 } 173 }
174 174
175 MaybeInitializeNetwork(); 175 MaybeInitializeNetwork();
176 } 176 }
177 177
178 void StartupAppLauncher::MaybeInitializeNetwork() { 178 void StartupAppLauncher::MaybeInitializeNetwork() {
179 network_ready_handled_ = false; 179 network_ready_handled_ = false;
180 180
181 const Extension* extension = extensions::ExtensionSystem::Get(profile_)-> 181 const Extension* extension = GetPrimaryAppExtension();
182 extension_service()->GetInstalledExtension(app_id_);
183 bool crx_cached = KioskAppManager::Get()->HasCachedCrx(app_id_); 182 bool crx_cached = KioskAppManager::Get()->HasCachedCrx(app_id_);
184 const bool requires_network = 183 const bool requires_network =
185 (!extension && !crx_cached) || 184 (!extension && !crx_cached) ||
186 (extension && 185 (extension &&
187 !extensions::OfflineEnabledInfo::IsOfflineEnabled(extension)); 186 !extensions::OfflineEnabledInfo::IsOfflineEnabled(extension));
188 187
189 if (requires_network) { 188 if (requires_network) {
190 delegate_->InitializeNetwork(); 189 delegate_->InitializeNetwork();
191 return; 190 return;
192 } 191 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 239 }
241 240
242 void StartupAppLauncher::OnRefreshTokensLoaded() { 241 void StartupAppLauncher::OnRefreshTokensLoaded() {
243 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) 242 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
244 ->RemoveObserver(this); 243 ->RemoveObserver(this);
245 MaybeInitializeNetwork(); 244 MaybeInitializeNetwork();
246 } 245 }
247 246
248 void StartupAppLauncher::MaybeLaunchApp() { 247 void StartupAppLauncher::MaybeLaunchApp() {
249 // Check if the app is offline enabled. 248 // Check if the app is offline enabled.
250 const Extension* extension = extensions::ExtensionSystem::Get(profile_) 249 const Extension* extension = GetPrimaryAppExtension();
251 ->extension_service()
252 ->GetInstalledExtension(app_id_);
253 DCHECK(extension); 250 DCHECK(extension);
254 const bool offline_enabled = 251 const bool offline_enabled =
255 extensions::OfflineEnabledInfo::IsOfflineEnabled(extension); 252 extensions::OfflineEnabledInfo::IsOfflineEnabled(extension);
256 if (offline_enabled || delegate_->IsNetworkReady()) { 253 if (offline_enabled || delegate_->IsNetworkReady()) {
257 BrowserThread::PostTask( 254 BrowserThread::PostTask(
258 BrowserThread::UI, 255 BrowserThread::UI,
259 FROM_HERE, 256 FROM_HERE,
260 base::Bind(&StartupAppLauncher::OnReadyToLaunch, AsWeakPtr())); 257 base::Bind(&StartupAppLauncher::OnReadyToLaunch, AsWeakPtr()));
261 } else { 258 } else {
262 ++launch_attempt_; 259 ++launch_attempt_;
(...skipping 19 matching lines...) Expand all
282 } 279 }
283 280
284 extensions::InstallTracker* tracker = 281 extensions::InstallTracker* tracker =
285 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); 282 extensions::InstallTrackerFactory::GetForBrowserContext(profile_);
286 tracker->RemoveObserver(this); 283 tracker->RemoveObserver(this);
287 if (delegate_->IsShowingNetworkConfigScreen()) { 284 if (delegate_->IsShowingNetworkConfigScreen()) {
288 LOG(WARNING) << "Showing network config screen"; 285 LOG(WARNING) << "Showing network config screen";
289 return; 286 return;
290 } 287 }
291 288
292 if (success) { 289 if (extension_id == app_id_) {
293 MaybeLaunchApp(); 290 if (success) {
291 MaybeInstallSecondaryApps();
292 } else {
293 LOG(ERROR) << "Failed to install the kiosk application app_id: "
294 << extension_id;
295 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
296 }
294 return; 297 return;
295 } 298 }
296 299
297 LOG(ERROR) << "Failed to install the kiosk application app_id: " 300 if (AreSecondaryAppsInstalled()) {
298 << extension_id; 301 MaybeLaunchApp();
299 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); 302 } else {
303 LOG(ERROR) << "Failed to install one or more secondary apps.";
304 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
305 }
300 } 306 }
301 307
302 void StartupAppLauncher::OnKioskExtensionLoadedInCache( 308 void StartupAppLauncher::OnKioskExtensionLoadedInCache(
303 const std::string& app_id) { 309 const std::string& app_id) {
304 OnKioskAppDataLoadStatusChanged(app_id); 310 OnKioskAppDataLoadStatusChanged(app_id);
305 } 311 }
306 312
307 void StartupAppLauncher::OnKioskExtensionDownloadFailed( 313 void StartupAppLauncher::OnKioskExtensionDownloadFailed(
308 const std::string& app_id) { 314 const std::string& app_id) {
309 OnKioskAppDataLoadStatusChanged(app_id); 315 OnKioskAppDataLoadStatusChanged(app_id);
310 } 316 }
311 317
312 void StartupAppLauncher::OnKioskAppDataLoadStatusChanged( 318 void StartupAppLauncher::OnKioskAppDataLoadStatusChanged(
313 const std::string& app_id) { 319 const std::string& app_id) {
314 if (app_id != app_id_ || !wait_for_crx_update_) 320 if (app_id != app_id_ || !wait_for_crx_update_)
315 return; 321 return;
316 322
317 wait_for_crx_update_ = false; 323 wait_for_crx_update_ = false;
318 if (KioskAppManager::Get()->HasCachedCrx(app_id_)) 324 if (KioskAppManager::Get()->HasCachedCrx(app_id_))
319 BeginInstall(); 325 BeginInstall();
320 else 326 else
321 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_DOWNLOAD); 327 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_DOWNLOAD);
322 } 328 }
323 329
330 bool StartupAppLauncher::IsAnySecondaryAppPending() const {
331 DCHECK(HasSecondaryApps());
332 const extensions::Extension* extension = GetPrimaryAppExtension();
333 DCHECK(extension);
334 extensions::KioskModeInfo* info = extensions::KioskModeInfo::Get(extension);
335 for (const auto& id : info->secondary_app_ids) {
336 if (extensions::ExtensionSystem::Get(profile_)
337 ->extension_service()
338 ->pending_extension_manager()
339 ->IsIdPending(id)) {
340 return true;
341 }
342 }
343 return false;
344 }
345
346 bool StartupAppLauncher::AreSecondaryAppsInstalled() const {
347 DCHECK(HasSecondaryApps());
348 const extensions::Extension* extension = GetPrimaryAppExtension();
349 DCHECK(extension);
350 extensions::KioskModeInfo* info = extensions::KioskModeInfo::Get(extension);
351 for (const auto& id : info->secondary_app_ids) {
352 if (!extensions::ExtensionSystem::Get(profile_)
353 ->extension_service()
354 ->GetInstalledExtension(id)) {
355 return false;
356 }
357 }
358 return true;
359 }
360
361 bool StartupAppLauncher::HasSecondaryApps() const {
362 const extensions::Extension* extension = GetPrimaryAppExtension();
363 DCHECK(extension);
364 return extensions::KioskModeInfo::HasSecondaryApps(extension);
365 }
366
367 const extensions::Extension* StartupAppLauncher::GetPrimaryAppExtension()
368 const {
369 return extensions::ExtensionSystem::Get(profile_)
370 ->extension_service()
371 ->GetInstalledExtension(app_id_);
372 }
373
324 void StartupAppLauncher::LaunchApp() { 374 void StartupAppLauncher::LaunchApp() {
325 if (!ready_to_launch_) { 375 if (!ready_to_launch_) {
326 NOTREACHED(); 376 NOTREACHED();
327 LOG(ERROR) << "LaunchApp() called but launcher is not initialized."; 377 LOG(ERROR) << "LaunchApp() called but launcher is not initialized.";
328 } 378 }
329 379
330 const Extension* extension = extensions::ExtensionSystem::Get(profile_)-> 380 const Extension* extension = GetPrimaryAppExtension();
331 extension_service()->GetInstalledExtension(app_id_);
332 CHECK(extension); 381 CHECK(extension);
333 382
334 if (!extensions::KioskModeInfo::IsKioskEnabled(extension)) { 383 if (!extensions::KioskModeInfo::IsKioskEnabled(extension)) {
335 OnLaunchFailure(KioskAppLaunchError::NOT_KIOSK_ENABLED); 384 OnLaunchFailure(KioskAppLaunchError::NOT_KIOSK_ENABLED);
336 return; 385 return;
337 } 386 }
338 387
339 // Always open the app in a window. 388 // Always open the app in a window.
340 OpenApplication(AppLaunchParams(profile_, extension, 389 OpenApplication(AppLaunchParams(profile_, extension,
341 extensions::LAUNCH_CONTAINER_WINDOW, 390 extensions::LAUNCH_CONTAINER_WINDOW,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 ->pending_extension_manager() 422 ->pending_extension_manager()
374 ->IsIdPending(app_id_)) { 423 ->IsIdPending(app_id_)) {
375 delegate_->OnInstallingApp(); 424 delegate_->OnInstallingApp();
376 // Observe the crx installation events. 425 // Observe the crx installation events.
377 extensions::InstallTracker* tracker = 426 extensions::InstallTracker* tracker =
378 extensions::InstallTrackerFactory::GetForBrowserContext(profile_); 427 extensions::InstallTrackerFactory::GetForBrowserContext(profile_);
379 tracker->AddObserver(this); 428 tracker->AddObserver(this);
380 return; 429 return;
381 } 430 }
382 431
383 if (extensions::ExtensionSystem::Get(profile_) 432 if (GetPrimaryAppExtension()) {
384 ->extension_service() 433 // Install secondary apps.
385 ->GetInstalledExtension(app_id_)) { 434 MaybeInstallSecondaryApps();
386 // Launch the app.
387 OnReadyToLaunch();
388 } else { 435 } else {
389 // The extension is skipped for installation due to some error. 436 // The extension is skipped for installation due to some error.
390 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL); 437 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
391 } 438 }
392 } 439 }
393 440
441 void StartupAppLauncher::MaybeInstallSecondaryApps() {
442 if (!HasSecondaryApps()) {
443 // Launch the primary app.
444 MaybeLaunchApp();
445 return;
446 }
447
448 if (!AreSecondaryAppsInstalled() && !delegate_->IsNetworkReady()) {
449 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
450 return;
451 }
452
453 extensions::KioskModeInfo* info =
454 extensions::KioskModeInfo::Get(GetPrimaryAppExtension());
455 KioskAppManager::Get()->InstallSecondaryApps(info->secondary_app_ids);
456 if (IsAnySecondaryAppPending()) {
457 delegate_->OnInstallingApp();
458 // Observe the crx installation events.
459 extensions::InstallTracker* tracker =
460 extensions::InstallTrackerFactory::GetForBrowserContext(profile_);
461 tracker->AddObserver(this);
462 return;
463 }
464
465 if (AreSecondaryAppsInstalled()) {
466 // Launch the primary app.
467 MaybeLaunchApp();
468 } else {
469 OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
470 }
471 }
472
394 void StartupAppLauncher::OnReadyToLaunch() { 473 void StartupAppLauncher::OnReadyToLaunch() {
395 ready_to_launch_ = true; 474 ready_to_launch_ = true;
396 UpdateAppData(); 475 UpdateAppData();
397 delegate_->OnReadyToLaunch(); 476 delegate_->OnReadyToLaunch();
398 } 477 }
399 478
400 void StartupAppLauncher::UpdateAppData() { 479 void StartupAppLauncher::UpdateAppData() {
401 KioskAppManager::Get()->ClearAppData(app_id_); 480 KioskAppManager::Get()->ClearAppData(app_id_);
402 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL); 481 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL);
403 } 482 }
404 483
405 } // namespace chromeos 484 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698