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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 282103003: Moved IS_EPHEMERAL flag to extension prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 (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
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/threading/sequenced_worker_pool.h" 16 #include "base/threading/sequenced_worker_pool.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 21 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
22 #include "chrome/browser/extensions/component_loader.h" 22 #include "chrome/browser/extensions/component_loader.h"
23 #include "chrome/browser/extensions/crx_installer.h" 23 #include "chrome/browser/extensions/crx_installer.h"
24 #include "chrome/browser/extensions/data_deleter.h" 24 #include "chrome/browser/extensions/data_deleter.h"
25 #include "chrome/browser/extensions/extension_disabled_ui.h" 25 #include "chrome/browser/extensions/extension_disabled_ui.h"
26 #include "chrome/browser/extensions/extension_error_controller.h" 26 #include "chrome/browser/extensions/extension_error_controller.h"
27 #include "chrome/browser/extensions/extension_install_ui.h" 27 #include "chrome/browser/extensions/extension_install_ui.h"
28 #include "chrome/browser/extensions/extension_special_storage_policy.h" 28 #include "chrome/browser/extensions/extension_special_storage_policy.h"
29 #include "chrome/browser/extensions/extension_sync_service.h" 29 #include "chrome/browser/extensions/extension_sync_service.h"
30 #include "chrome/browser/extensions/extension_ui_util.h"
30 #include "chrome/browser/extensions/extension_util.h" 31 #include "chrome/browser/extensions/extension_util.h"
31 #include "chrome/browser/extensions/external_install_ui.h" 32 #include "chrome/browser/extensions/external_install_ui.h"
32 #include "chrome/browser/extensions/external_provider_impl.h" 33 #include "chrome/browser/extensions/external_provider_impl.h"
33 #include "chrome/browser/extensions/install_verifier.h" 34 #include "chrome/browser/extensions/install_verifier.h"
34 #include "chrome/browser/extensions/installed_loader.h" 35 #include "chrome/browser/extensions/installed_loader.h"
35 #include "chrome/browser/extensions/pending_extension_manager.h" 36 #include "chrome/browser/extensions/pending_extension_manager.h"
36 #include "chrome/browser/extensions/permissions_updater.h" 37 #include "chrome/browser/extensions/permissions_updater.h"
37 #include "chrome/browser/extensions/shared_module_service.h" 38 #include "chrome/browser/extensions/shared_module_service.h"
38 #include "chrome/browser/extensions/unpacked_installer.h" 39 #include "chrome/browser/extensions/unpacked_installer.h"
39 #include "chrome/browser/extensions/updater/extension_cache.h" 40 #include "chrome/browser/extensions/updater/extension_cache.h"
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 // details. 569 // details.
569 if (extension && extension->from_bookmark()) 570 if (extension && extension->from_bookmark())
570 creation_flags |= Extension::FROM_BOOKMARK; 571 creation_flags |= Extension::FROM_BOOKMARK;
571 572
572 if (extension && extension->was_installed_by_default()) 573 if (extension && extension->was_installed_by_default())
573 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; 574 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
574 575
575 if (extension && extension->was_installed_by_oem()) 576 if (extension && extension->was_installed_by_oem())
576 creation_flags |= Extension::WAS_INSTALLED_BY_OEM; 577 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
577 578
578 if (extension && extension->is_ephemeral())
579 creation_flags |= Extension::IS_EPHEMERAL;
580
581 installer->set_creation_flags(creation_flags); 579 installer->set_creation_flags(creation_flags);
580 installer->set_is_ephemeral(
581 extension_prefs_->IsEphemeralApp(extension->id()));
582 582
583 installer->set_delete_source(file_ownership_passed); 583 installer->set_delete_source(file_ownership_passed);
584 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); 584 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
585 installer->InstallCrx(extension_path); 585 installer->InstallCrx(extension_path);
586 586
587 if (out_crx_installer) 587 if (out_crx_installer)
588 *out_crx_installer = installer.get(); 588 *out_crx_installer = installer.get();
589 589
590 return true; 590 return true;
591 } 591 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 if (!GetFileTaskRunner()->PostTask( 726 if (!GetFileTaskRunner()->PostTask(
727 FROM_HERE, 727 FROM_HERE,
728 base::Bind(&extensions::file_util::UninstallExtension, 728 base::Bind(&extensions::file_util::UninstallExtension,
729 install_directory_, 729 install_directory_,
730 extension_id))) 730 extension_id)))
731 NOTREACHED(); 731 NOTREACHED();
732 } 732 }
733 733
734 // Do not remove the data of ephemeral apps. They will be garbage collected by 734 // Do not remove the data of ephemeral apps. They will be garbage collected by
735 // EphemeralAppService. 735 // EphemeralAppService.
736 if (!extension->is_ephemeral()) 736 if (!extension_prefs_->IsEphemeralApp(extension_id))
737 extensions::DataDeleter::StartDeleting(profile_, extension.get()); 737 extensions::DataDeleter::StartDeleting(profile_, extension.get());
738 738
739 UntrackTerminatedExtension(extension_id); 739 UntrackTerminatedExtension(extension_id);
740 740
741 // Notify interested parties that we've uninstalled this extension. 741 // Notify interested parties that we've uninstalled this extension.
742 content::NotificationService::current()->Notify( 742 content::NotificationService::current()->Notify(
743 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 743 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
744 content::Source<Profile>(profile_), 744 content::Source<Profile>(profile_),
745 content::Details<const Extension>(extension.get())); 745 content::Details<const Extension>(extension.get()));
746 746
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 extensions::AddExtensionDisabledError(this, extension); 1499 extensions::AddExtensionDisabledError(this, extension);
1500 } 1500 }
1501 } else if (reloading) { 1501 } else if (reloading) {
1502 // Replace the old extension with the new version. 1502 // Replace the old extension with the new version.
1503 CHECK(!registry_->AddDisabled(extension)); 1503 CHECK(!registry_->AddDisabled(extension));
1504 EnableExtension(extension->id()); 1504 EnableExtension(extension->id());
1505 } else { 1505 } else {
1506 // All apps that are displayed in the launcher are ordered by their ordinals 1506 // All apps that are displayed in the launcher are ordered by their ordinals
1507 // so we must ensure they have valid ordinals. 1507 // so we must ensure they have valid ordinals.
1508 if (extension->RequiresSortOrdinal()) { 1508 if (extension->RequiresSortOrdinal()) {
1509 if (!extension->ShouldDisplayInNewTabPage()) { 1509 if (!extensions::ui_util::ShouldDisplayInNewTabPage(
1510 extension, profile_)) {
1510 extension_prefs_->app_sorting()->MarkExtensionAsHidden(extension->id()); 1511 extension_prefs_->app_sorting()->MarkExtensionAsHidden(extension->id());
1511 } 1512 }
1512 extension_prefs_->app_sorting()->EnsureValidOrdinals( 1513 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1513 extension->id(), syncer::StringOrdinal()); 1514 extension->id(), syncer::StringOrdinal());
1514 } 1515 }
1515 1516
1516 registry_->AddEnabled(extension); 1517 registry_->AddEnabled(extension);
1517 if (extension_sync_service_) 1518 if (extension_sync_service_)
1518 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); 1519 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
1519 NotifyExtensionLoaded(extension); 1520 NotifyExtensionLoaded(extension);
1520 } 1521 }
1521 system_->runtime_data()->SetBeingUpgraded(extension, false); 1522 system_->runtime_data()->SetBeingUpgraded(extension, false);
1522 } 1523 }
1523 1524
1524 void ExtensionService::AddComponentExtension(const Extension* extension) { 1525 void ExtensionService::AddComponentExtension(const Extension* extension) {
1525 const std::string old_version_string( 1526 const std::string old_version_string(
1526 extension_prefs_->GetVersionString(extension->id())); 1527 extension_prefs_->GetVersionString(extension->id()));
1527 const Version old_version(old_version_string); 1528 const Version old_version(old_version_string);
1528 1529
1529 VLOG(1) << "AddComponentExtension " << extension->name(); 1530 VLOG(1) << "AddComponentExtension " << extension->name();
1530 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { 1531 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1531 VLOG(1) << "Component extension " << extension->name() << " (" 1532 VLOG(1) << "Component extension " << extension->name() << " ("
1532 << extension->id() << ") installing/upgrading from '" 1533 << extension->id() << ") installing/upgrading from '"
1533 << old_version_string << "' to " << extension->version()->GetString(); 1534 << old_version_string << "' to " << extension->version()->GetString();
1534 1535
1535 AddNewOrUpdatedExtension(extension, 1536 AddNewOrUpdatedExtension(extension,
1536 Extension::ENABLED_COMPONENT, 1537 Extension::ENABLED_COMPONENT,
1537 extensions::NOT_BLACKLISTED, 1538 extensions::NOT_BLACKLISTED,
1539 false,
1538 syncer::StringOrdinal(), 1540 syncer::StringOrdinal(),
1539 std::string()); 1541 std::string());
1540 return; 1542 return;
1541 } 1543 }
1542 1544
1543 AddExtension(extension); 1545 AddExtension(extension);
1544 } 1546 }
1545 1547
1546 void ExtensionService::UpdateActivePermissions(const Extension* extension) { 1548 void ExtensionService::UpdateActivePermissions(const Extension* extension) {
1547 // If the extension has used the optional permissions API, it will have a 1549 // If the extension has used the optional permissions API, it will have a
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 // crash_keys::SetActiveExtensions is per-process. See 1691 // crash_keys::SetActiveExtensions is per-process. See
1690 // http://crbug.com/355029. 1692 // http://crbug.com/355029.
1691 crash_keys::SetActiveExtensions(extension_ids); 1693 crash_keys::SetActiveExtensions(extension_ids);
1692 } 1694 }
1693 1695
1694 void ExtensionService::OnExtensionInstalled( 1696 void ExtensionService::OnExtensionInstalled(
1695 const Extension* extension, 1697 const Extension* extension,
1696 const syncer::StringOrdinal& page_ordinal, 1698 const syncer::StringOrdinal& page_ordinal,
1697 bool has_requirement_errors, 1699 bool has_requirement_errors,
1698 extensions::BlacklistState blacklist_state, 1700 extensions::BlacklistState blacklist_state,
1701 bool is_ephemeral,
1699 bool wait_for_idle) { 1702 bool wait_for_idle) {
1700 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1703 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1701 1704
1702 const std::string& id = extension->id(); 1705 const std::string& id = extension->id();
1703 bool initial_enable = ShouldEnableOnInstall(extension); 1706 bool initial_enable = ShouldEnableOnInstall(extension);
1704 std::string install_parameter; 1707 std::string install_parameter;
1705 const extensions::PendingExtensionInfo* pending_extension_info = NULL; 1708 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
1706 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { 1709 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
1707 if (!pending_extension_info->ShouldAllowInstall(extension)) { 1710 if (!pending_extension_info->ShouldAllowInstall(extension)) {
1708 pending_extension_manager()->Remove(id); 1711 pending_extension_manager()->Remove(id);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 AcknowledgeExternalExtension(extension->id()); 1786 AcknowledgeExternalExtension(extension->id());
1784 const Extension::State initial_state = 1787 const Extension::State initial_state =
1785 initial_enable ? Extension::ENABLED : Extension::DISABLED; 1788 initial_enable ? Extension::ENABLED : Extension::DISABLED;
1786 const bool blacklisted_for_malware = 1789 const bool blacklisted_for_malware =
1787 blacklist_state == extensions::BLACKLISTED_MALWARE; 1790 blacklist_state == extensions::BLACKLISTED_MALWARE;
1788 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) { 1791 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) {
1789 extension_prefs_->SetDelayedInstallInfo( 1792 extension_prefs_->SetDelayedInstallInfo(
1790 extension, 1793 extension,
1791 initial_state, 1794 initial_state,
1792 blacklisted_for_malware, 1795 blacklisted_for_malware,
1796 is_ephemeral,
1793 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, 1797 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
1794 page_ordinal, 1798 page_ordinal,
1795 install_parameter); 1799 install_parameter);
1796 1800
1797 // Transfer ownership of |extension|. 1801 // Transfer ownership of |extension|.
1798 delayed_installs_.Insert(extension); 1802 delayed_installs_.Insert(extension);
1799 1803
1800 // Notify observers that app update is available. 1804 // Notify observers that app update is available.
1801 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, 1805 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
1802 OnAppUpdateAvailable(extension)); 1806 OnAppUpdateAvailable(extension));
1803 return; 1807 return;
1804 } 1808 }
1805 1809
1806 extensions::SharedModuleService::ImportStatus status = 1810 extensions::SharedModuleService::ImportStatus status =
1807 shared_module_service_->SatisfyImports(extension); 1811 shared_module_service_->SatisfyImports(extension);
1808 if (installs_delayed_for_gc_) { 1812 if (installs_delayed_for_gc_) {
1809 extension_prefs_->SetDelayedInstallInfo( 1813 extension_prefs_->SetDelayedInstallInfo(
1810 extension, 1814 extension,
1811 initial_state, 1815 initial_state,
1812 blacklisted_for_malware, 1816 blacklisted_for_malware,
1817 is_ephemeral,
1813 extensions::ExtensionPrefs::DELAY_REASON_GC, 1818 extensions::ExtensionPrefs::DELAY_REASON_GC,
1814 page_ordinal, 1819 page_ordinal,
1815 install_parameter); 1820 install_parameter);
1816 delayed_installs_.Insert(extension); 1821 delayed_installs_.Insert(extension);
1817 } else if (status != SharedModuleService::IMPORT_STATUS_OK) { 1822 } else if (status != SharedModuleService::IMPORT_STATUS_OK) {
1818 if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) { 1823 if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) {
1819 extension_prefs_->SetDelayedInstallInfo( 1824 extension_prefs_->SetDelayedInstallInfo(
1820 extension, 1825 extension,
1821 initial_state, 1826 initial_state,
1822 blacklisted_for_malware, 1827 blacklisted_for_malware,
1828 is_ephemeral,
1823 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, 1829 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
1824 page_ordinal, 1830 page_ordinal,
1825 install_parameter); 1831 install_parameter);
1826 delayed_installs_.Insert(extension); 1832 delayed_installs_.Insert(extension);
1827 } 1833 }
1828 } else { 1834 } else {
1829 AddNewOrUpdatedExtension(extension, 1835 AddNewOrUpdatedExtension(extension,
1830 initial_state, 1836 initial_state,
1831 blacklist_state, 1837 blacklist_state,
1838 is_ephemeral,
1832 page_ordinal, 1839 page_ordinal,
1833 install_parameter); 1840 install_parameter);
1834 } 1841 }
1835 } 1842 }
1836 1843
1837 void ExtensionService::AddNewOrUpdatedExtension( 1844 void ExtensionService::AddNewOrUpdatedExtension(
1838 const Extension* extension, 1845 const Extension* extension,
1839 Extension::State initial_state, 1846 Extension::State initial_state,
1840 extensions::BlacklistState blacklist_state, 1847 extensions::BlacklistState blacklist_state,
1848 bool is_ephemeral,
1841 const syncer::StringOrdinal& page_ordinal, 1849 const syncer::StringOrdinal& page_ordinal,
1842 const std::string& install_parameter) { 1850 const std::string& install_parameter) {
1843 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1851 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1844 const bool blacklisted_for_malware = 1852 const bool blacklisted_for_malware =
1845 blacklist_state == extensions::BLACKLISTED_MALWARE; 1853 blacklist_state == extensions::BLACKLISTED_MALWARE;
1846 extension_prefs_->OnExtensionInstalled(extension, 1854 extension_prefs_->OnExtensionInstalled(extension,
1847 initial_state, 1855 initial_state,
1848 blacklisted_for_malware, 1856 blacklisted_for_malware,
1857 is_ephemeral,
1849 page_ordinal, 1858 page_ordinal,
1850 install_parameter); 1859 install_parameter);
1851 delayed_installs_.Remove(extension->id()); 1860 delayed_installs_.Remove(extension->id());
1852 if (InstallVerifier::NeedsVerification(*extension)) 1861 if (InstallVerifier::NeedsVerification(*extension))
1853 system_->install_verifier()->VerifyExtension(extension->id()); 1862 system_->install_verifier()->VerifyExtension(extension->id());
1854 FinishInstallation(extension); 1863 FinishInstallation(extension);
1855 } 1864 }
1856 1865
1857 void ExtensionService::MaybeFinishDelayedInstallation( 1866 void ExtensionService::MaybeFinishDelayedInstallation(
1858 const std::string& extension_id) { 1867 const std::string& extension_id) {
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
2408 void ExtensionService::UnloadAllExtensionsInternal() { 2417 void ExtensionService::UnloadAllExtensionsInternal() {
2409 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2418 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2410 2419
2411 registry_->ClearAll(); 2420 registry_->ClearAll();
2412 system_->runtime_data()->ClearAll(); 2421 system_->runtime_data()->ClearAll();
2413 2422
2414 // TODO(erikkay) should there be a notification for this? We can't use 2423 // TODO(erikkay) should there be a notification for this? We can't use
2415 // EXTENSION_UNLOADED since that implies that the extension has been disabled 2424 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2416 // or uninstalled. 2425 // or uninstalled.
2417 } 2426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698