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/kiosk_app_manager.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/barrier_closure.h" | 10 #include "base/barrier_closure.h" |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 observers_.AddObserver(observer); | 458 observers_.AddObserver(observer); |
459 } | 459 } |
460 | 460 |
461 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { | 461 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
462 observers_.RemoveObserver(observer); | 462 observers_.RemoveObserver(observer); |
463 } | 463 } |
464 | 464 |
465 extensions::ExternalLoader* KioskAppManager::CreateExternalLoader() { | 465 extensions::ExternalLoader* KioskAppManager::CreateExternalLoader() { |
466 if (external_loader_created_) { | 466 if (external_loader_created_) { |
467 NOTREACHED(); | 467 NOTREACHED(); |
468 return NULL; | 468 return nullptr; |
469 } | 469 } |
470 external_loader_created_ = true; | 470 external_loader_created_ = true; |
471 KioskAppExternalLoader* loader = new KioskAppExternalLoader(); | 471 KioskAppExternalLoader* loader = new KioskAppExternalLoader(); |
472 external_loader_ = loader->AsWeakPtr(); | 472 external_loader_ = loader->AsWeakPtr(); |
473 | 473 |
474 return loader; | 474 return loader; |
475 } | 475 } |
476 | 476 |
| 477 extensions::ExternalLoader* |
| 478 KioskAppManager::CreateSecondaryAppExternalLoader() { |
| 479 if (secondary_app_external_loader_created_) { |
| 480 NOTREACHED(); |
| 481 return nullptr; |
| 482 } |
| 483 secondary_app_external_loader_created_ = true; |
| 484 KioskAppExternalLoader* secondary_loader = new KioskAppExternalLoader(); |
| 485 secondary_app_external_loader_ = secondary_loader->AsWeakPtr(); |
| 486 |
| 487 return secondary_loader; |
| 488 } |
| 489 |
477 void KioskAppManager::InstallFromCache(const std::string& id) { | 490 void KioskAppManager::InstallFromCache(const std::string& id) { |
478 const base::DictionaryValue* extension = NULL; | 491 const base::DictionaryValue* extension = NULL; |
479 if (external_cache_->cached_extensions()->GetDictionary(id, &extension)) { | 492 if (external_cache_->cached_extensions()->GetDictionary(id, &extension)) { |
480 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 493 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
481 base::DictionaryValue* extension_copy = extension->DeepCopy(); | 494 base::DictionaryValue* extension_copy = extension->DeepCopy(); |
482 prefs->Set(id, extension_copy); | 495 prefs->Set(id, extension_copy); |
483 external_loader_->SetCurrentAppExtensions(prefs.Pass()); | 496 external_loader_->SetCurrentAppExtensions(prefs.Pass()); |
484 } else { | 497 } else { |
485 LOG(ERROR) << "Can't find app in the cached externsions" | 498 LOG(ERROR) << "Can't find app in the cached externsions" |
486 << " id = " << id; | 499 << " id = " << id; |
487 } | 500 } |
488 } | 501 } |
489 | 502 |
| 503 void KioskAppManager::InstallSecondaryApps( |
| 504 const std::vector<std::string>& ids) { |
| 505 if (ids.empty()) |
| 506 return; |
| 507 |
| 508 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 509 for (const std::string& id : ids) { |
| 510 scoped_ptr<base::DictionaryValue> extension_entry( |
| 511 new base::DictionaryValue); |
| 512 extension_entry->SetStringWithoutPathExpansion( |
| 513 extensions::ExternalProviderImpl::kExternalUpdateUrl, |
| 514 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 515 extension_entry->SetBoolean( |
| 516 extensions::ExternalProviderImpl::kIsFromWebstore, true); |
| 517 prefs->Set(id, extension_entry.Pass()); |
| 518 } |
| 519 secondary_app_external_loader_->SetCurrentAppExtensions(prefs.Pass()); |
| 520 } |
| 521 |
490 void KioskAppManager::UpdateExternalCache() { | 522 void KioskAppManager::UpdateExternalCache() { |
491 UpdateAppData(); | 523 UpdateAppData(); |
492 } | 524 } |
493 | 525 |
494 void KioskAppManager::OnKioskAppCacheUpdated(const std::string& app_id) { | 526 void KioskAppManager::OnKioskAppCacheUpdated(const std::string& app_id) { |
495 FOR_EACH_OBSERVER( | 527 FOR_EACH_OBSERVER( |
496 KioskAppManagerObserver, observers_, OnKioskAppCacheUpdated(app_id)); | 528 KioskAppManagerObserver, observers_, OnKioskAppCacheUpdated(app_id)); |
497 } | 529 } |
498 | 530 |
499 void KioskAppManager::OnKioskAppExternalUpdateComplete(bool success) { | 531 void KioskAppManager::OnKioskAppExternalUpdateComplete(bool success) { |
500 FOR_EACH_OBSERVER(KioskAppManagerObserver, | 532 FOR_EACH_OBSERVER(KioskAppManagerObserver, |
501 observers_, | 533 observers_, |
502 OnKioskAppExternalUpdateComplete(success)); | 534 OnKioskAppExternalUpdateComplete(success)); |
503 } | 535 } |
504 | 536 |
505 void KioskAppManager::PutValidatedExternalExtension( | 537 void KioskAppManager::PutValidatedExternalExtension( |
506 const std::string& app_id, | 538 const std::string& app_id, |
507 const base::FilePath& crx_path, | 539 const base::FilePath& crx_path, |
508 const std::string& version, | 540 const std::string& version, |
509 const ExternalCache::PutExternalExtensionCallback& callback) { | 541 const ExternalCache::PutExternalExtensionCallback& callback) { |
510 external_cache_->PutExternalExtension(app_id, crx_path, version, callback); | 542 external_cache_->PutExternalExtension(app_id, crx_path, version, callback); |
511 } | 543 } |
512 | 544 |
513 KioskAppManager::KioskAppManager() | 545 KioskAppManager::KioskAppManager() |
514 : ownership_established_(false), external_loader_created_(false) { | 546 : ownership_established_(false), |
| 547 external_loader_created_(false), |
| 548 secondary_app_external_loader_created_(false) { |
515 base::FilePath cache_dir; | 549 base::FilePath cache_dir; |
516 GetCrxCacheDir(&cache_dir); | 550 GetCrxCacheDir(&cache_dir); |
517 external_cache_.reset( | 551 external_cache_.reset( |
518 new ExternalCache(cache_dir, | 552 new ExternalCache(cache_dir, |
519 g_browser_process->system_request_context(), | 553 g_browser_process->system_request_context(), |
520 GetBackgroundTaskRunner(), | 554 GetBackgroundTaskRunner(), |
521 this, | 555 this, |
522 true /* always_check_updates */, | 556 true /* always_check_updates */, |
523 false /* wait_for_cache_initialization */)); | 557 false /* wait_for_cache_initialization */)); |
524 UpdateAppData(); | 558 UpdateAppData(); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); | 768 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); |
735 } | 769 } |
736 | 770 |
737 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) { | 771 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) { |
738 base::FilePath temp_dir; | 772 base::FilePath temp_dir; |
739 base::GetTempDir(&temp_dir); | 773 base::GetTempDir(&temp_dir); |
740 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir); | 774 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir); |
741 } | 775 } |
742 | 776 |
743 } // namespace chromeos | 777 } // namespace chromeos |
OLD | NEW |