| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 extension_prefs_->GetAllDelayedInstallInfo()); | 566 extension_prefs_->GetAllDelayedInstallInfo()); |
| 567 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", | 567 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", |
| 568 delayed_info2->size() - delayed_info->size()); | 568 delayed_info2->size() - delayed_info->size()); |
| 569 | 569 |
| 570 SetReadyAndNotifyListeners(); | 570 SetReadyAndNotifyListeners(); |
| 571 | 571 |
| 572 // TODO(erikkay) this should probably be deferred to a future point | 572 // TODO(erikkay) this should probably be deferred to a future point |
| 573 // rather than running immediately at startup. | 573 // rather than running immediately at startup. |
| 574 CheckForExternalUpdates(); | 574 CheckForExternalUpdates(); |
| 575 | 575 |
| 576 InstallVerifier* verifier = |
| 577 extensions::ExtensionSystem::Get(profile_)->install_verifier(); |
| 578 if (verifier->NeedsBootstrap()) |
| 579 VerifyAllExtensions(); |
| 580 |
| 576 base::MessageLoop::current()->PostDelayedTask( | 581 base::MessageLoop::current()->PostDelayedTask( |
| 577 FROM_HERE, | 582 FROM_HERE, |
| 578 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), | 583 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), |
| 579 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); | 584 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); |
| 580 | 585 |
| 581 if (extension_prefs_->NeedsStorageGarbageCollection()) { | 586 if (extension_prefs_->NeedsStorageGarbageCollection()) { |
| 582 GarbageCollectIsolatedStorage(); | 587 GarbageCollectIsolatedStorage(); |
| 583 extension_prefs_->SetNeedsStorageGarbageCollection(false); | 588 extension_prefs_->SetNeedsStorageGarbageCollection(false); |
| 584 } | 589 } |
| 585 system_->management_policy()->RegisterProvider( | 590 system_->management_policy()->RegisterProvider( |
| 586 shared_module_policy_provider_.get()); | 591 shared_module_policy_provider_.get()); |
| 587 } | 592 } |
| 588 | 593 |
| 589 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", | 594 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", |
| 590 base::Time::Now() - begin_time); | 595 base::Time::Now() - begin_time); |
| 591 } | 596 } |
| 592 | 597 |
| 598 void ExtensionService::VerifyAllExtensions() { |
| 599 ExtensionIdSet to_add; |
| 600 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet(); |
| 601 |
| 602 for (ExtensionSet::const_iterator i = all_extensions->begin(); |
| 603 i != all_extensions->end(); ++i) { |
| 604 const Extension& extension = **i; |
| 605 |
| 606 if (extensions::ManifestURL::UpdatesFromGallery(&extension) && |
| 607 extension.is_extension()) |
| 608 to_add.insert(extension.id()); |
| 609 } |
| 610 extensions::ExtensionSystem::Get(profile_)->install_verifier()->AddMany( |
| 611 to_add, base::Bind(&ExtensionService::FinishVerifyAllExtensions, |
| 612 AsWeakPtr())); |
| 613 } |
| 614 |
| 615 void ExtensionService::FinishVerifyAllExtensions(bool success) { |
| 616 if (success) { |
| 617 // Check to see if any currently unverified extensions became verified. |
| 618 InstallVerifier* verifier = |
| 619 extensions::ExtensionSystem::Get(profile_)->install_verifier(); |
| 620 for (ExtensionSet::const_iterator i = disabled_extensions_.begin(); |
| 621 i != disabled_extensions_.end(); ++i) { |
| 622 const Extension& extension = **i; |
| 623 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id()); |
| 624 if (disable_reasons & Extension::DISABLE_NOT_VERIFIED && |
| 625 !verifier->MustRemainDisabled(&extension, NULL, NULL)) { |
| 626 extension_prefs_->RemoveDisableReason(extension.id(), |
| 627 Extension::DISABLE_NOT_VERIFIED); |
| 628 // Notify interested observers (eg the extensions settings page) by |
| 629 // sending an UNLOADED notification. |
| 630 // |
| 631 // TODO(asargent) - this is a slight hack because it's already |
| 632 // disabled; the right solution might be to add a separate listener |
| 633 // interface for DisableReason's changing. http://crbug.com/328916 |
| 634 UnloadedExtensionInfo details(&extension, |
| 635 UnloadedExtensionInfo::REASON_DISABLE); |
| 636 content::NotificationService::current()->Notify( |
| 637 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 638 content::Source<Profile>(profile_), |
| 639 content::Details<UnloadedExtensionInfo>(&details)); |
| 640 } |
| 641 } |
| 642 // Might disable some extensions. |
| 643 CheckManagementPolicy(); |
| 644 } |
| 645 } |
| 646 |
| 593 bool ExtensionService::UpdateExtension(const std::string& id, | 647 bool ExtensionService::UpdateExtension(const std::string& id, |
| 594 const base::FilePath& extension_path, | 648 const base::FilePath& extension_path, |
| 595 const GURL& download_url, | 649 const GURL& download_url, |
| 596 CrxInstaller** out_crx_installer) { | 650 CrxInstaller** out_crx_installer) { |
| 597 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 651 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 598 if (browser_terminating_) { | 652 if (browser_terminating_) { |
| 599 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown"; | 653 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown"; |
| 600 // Leak the temp file at extension_path. We don't want to add to the disk | 654 // Leak the temp file at extension_path. We don't want to add to the disk |
| 601 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and | 655 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and |
| 602 // the file is in the OS temp directory which should be cleaned up for us. | 656 // the file is in the OS temp directory which should be cleaned up for us. |
| (...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2794 } | 2848 } |
| 2795 | 2849 |
| 2796 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 2850 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
| 2797 update_observers_.AddObserver(observer); | 2851 update_observers_.AddObserver(observer); |
| 2798 } | 2852 } |
| 2799 | 2853 |
| 2800 void ExtensionService::RemoveUpdateObserver( | 2854 void ExtensionService::RemoveUpdateObserver( |
| 2801 extensions::UpdateObserver* observer) { | 2855 extensions::UpdateObserver* observer) { |
| 2802 update_observers_.RemoveObserver(observer); | 2856 update_observers_.RemoveObserver(observer); |
| 2803 } | 2857 } |
| OLD | NEW |