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

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

Issue 131743021: app_shell: Extract extension runtime data from ExtensionService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TriggerOnUnloaded (runtime_data) Created 6 years, 11 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 | Annotate | Revision Log
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
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #include "extensions/browser/app_sorting.h" 76 #include "extensions/browser/app_sorting.h"
77 #include "extensions/browser/event_router.h" 77 #include "extensions/browser/event_router.h"
78 #include "extensions/browser/extension_registry.h" 78 #include "extensions/browser/extension_registry.h"
79 #include "extensions/browser/extensions_browser_client.h" 79 #include "extensions/browser/extensions_browser_client.h"
80 #include "extensions/browser/external_provider_interface.h" 80 #include "extensions/browser/external_provider_interface.h"
81 #include "extensions/browser/management_policy.h" 81 #include "extensions/browser/management_policy.h"
82 #include "extensions/browser/pending_extension_manager.h" 82 #include "extensions/browser/pending_extension_manager.h"
83 #include "extensions/browser/pref_names.h" 83 #include "extensions/browser/pref_names.h"
84 #include "extensions/browser/process_manager.h" 84 #include "extensions/browser/process_manager.h"
85 #include "extensions/browser/process_map.h" 85 #include "extensions/browser/process_map.h"
86 #include "extensions/browser/runtime_data.h"
86 #include "extensions/browser/update_observer.h" 87 #include "extensions/browser/update_observer.h"
87 #include "extensions/common/constants.h" 88 #include "extensions/common/constants.h"
88 #include "extensions/common/error_utils.h" 89 #include "extensions/common/error_utils.h"
89 #include "extensions/common/extension.h" 90 #include "extensions/common/extension.h"
90 #include "extensions/common/extensions_client.h" 91 #include "extensions/common/extensions_client.h"
91 #include "extensions/common/feature_switch.h" 92 #include "extensions/common/feature_switch.h"
92 #include "extensions/common/manifest.h" 93 #include "extensions/common/manifest.h"
93 #include "extensions/common/manifest_constants.h" 94 #include "extensions/common/manifest_constants.h"
94 #include "extensions/common/manifest_handlers/background_info.h" 95 #include "extensions/common/manifest_handlers/background_info.h"
95 #include "extensions/common/manifest_handlers/incognito_info.h" 96 #include "extensions/common/manifest_handlers/incognito_info.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return IsCWSSharedModule(extension); 183 return IsCWSSharedModule(extension);
183 } 184 }
184 185
185 private: 186 private:
186 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); 187 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider);
187 }; 188 };
188 189
189 190
190 } // namespace 191 } // namespace
191 192
192 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
193 : background_page_ready(false),
194 being_upgraded(false),
195 has_used_webrequest(false) {
196 }
197
198 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
199 }
200
201 // ExtensionService. 193 // ExtensionService.
202 194
203 void ExtensionService::CheckExternalUninstall(const std::string& id) { 195 void ExtensionService::CheckExternalUninstall(const std::string& id) {
204 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 196 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205 197
206 // Check if the providers know about this extension. 198 // Check if the providers know about this extension.
207 extensions::ProviderCollection::const_iterator i; 199 extensions::ProviderCollection::const_iterator i;
208 for (i = external_extension_providers_.begin(); 200 for (i = external_extension_providers_.begin();
209 i != external_extension_providers_.end(); ++i) { 201 i != external_extension_providers_.end(); ++i) {
210 DCHECK(i->get()->IsReady()); 202 DCHECK(i->get()->IsReady());
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { 725 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) {
734 // Look for an open inspector for the background page. 726 // Look for an open inspector for the background page.
735 scoped_refptr<DevToolsAgentHost> agent_host = 727 scoped_refptr<DevToolsAgentHost> agent_host =
736 DevToolsAgentHost::GetOrCreateFor(host->render_view_host()); 728 DevToolsAgentHost::GetOrCreateFor(host->render_view_host());
737 agent_host->DisconnectRenderViewHost(); 729 agent_host->DisconnectRenderViewHost();
738 orphaned_dev_tools_[extension_id] = agent_host; 730 orphaned_dev_tools_[extension_id] = agent_host;
739 } 731 }
740 732
741 path = current_extension->path(); 733 path = current_extension->path();
742 // BeingUpgraded is set back to false when the extension is added. 734 // BeingUpgraded is set back to false when the extension is added.
743 SetBeingUpgraded(current_extension, true); 735 system_->runtime_data()->SetBeingUpgraded(current_extension, true);
744 DisableExtension(extension_id, Extension::DISABLE_RELOAD); 736 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
745 reloading_extensions_.insert(extension_id); 737 reloading_extensions_.insert(extension_id);
746 } else { 738 } else {
747 path = unloaded_extension_paths_[extension_id]; 739 path = unloaded_extension_paths_[extension_id];
748 } 740 }
749 741
750 if (delayed_installs_.Contains(extension_id)) { 742 if (delayed_installs_.Contains(extension_id)) {
751 FinishDelayedInstallation(extension_id); 743 FinishDelayedInstallation(extension_id);
752 return; 744 return;
753 } 745 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 964
973 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); 965 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
974 extension_prefs_->AddDisableReason(extension_id, disable_reason); 966 extension_prefs_->AddDisableReason(extension_id, disable_reason);
975 967
976 int include_mask = 968 int include_mask =
977 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; 969 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
978 extension = registry_->GetExtensionById(extension_id, include_mask); 970 extension = registry_->GetExtensionById(extension_id, include_mask);
979 if (!extension) 971 if (!extension)
980 return; 972 return;
981 973
982 // Reset the background_page_ready flag 974 bool was_enabled = registry_->enabled_extensions().Contains(extension->id());
983 if (extensions::BackgroundInfo::HasBackgroundPage(extension))
984 extension_runtime_data_[extension->id()].background_page_ready = false;
985 975
986 // Move it over to the disabled list. Don't send a second unload notification 976 // Move it over to the disabled list.
987 // for terminated extensions being disabled.
988 registry_->AddDisabled(make_scoped_refptr(extension)); 977 registry_->AddDisabled(make_scoped_refptr(extension));
989 if (registry_->enabled_extensions().Contains(extension->id())) { 978 if (was_enabled)
990 registry_->RemoveEnabled(extension->id()); 979 registry_->RemoveEnabled(extension->id());
980 else
981 registry_->RemoveTerminated(extension->id());
982 registry_->TriggerOnDisabled(extension);
983
984 // Only send the unload notification for enabled extensions to avoid sending
985 // a second notification for terminated extensions.
986 if (was_enabled)
991 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); 987 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
992 } else {
993 registry_->RemoveTerminated(extension->id());
994 }
995 988
996 if (extension_sync_service_) 989 if (extension_sync_service_)
997 extension_sync_service_->SyncDisableExtension(*extension); 990 extension_sync_service_->SyncDisableExtension(*extension);
998 } 991 }
999 992
1000 void ExtensionService::DisableUserExtensions( 993 void ExtensionService::DisableUserExtensions(
1001 const std::vector<std::string>& except_ids) { 994 const std::vector<std::string>& except_ids) {
1002 extensions::ManagementPolicy* management_policy = 995 extensions::ManagementPolicy* management_policy =
1003 system_->management_policy(); 996 system_->management_policy();
1004 extensions::ExtensionList to_disable; 997 extensions::ExtensionList to_disable;
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 return; 1576 return;
1584 } 1577 }
1585 1578
1586 // Keep information about the extension so that we can reload it later 1579 // Keep information about the extension so that we can reload it later
1587 // even if it's not permanently installed. 1580 // even if it's not permanently installed.
1588 unloaded_extension_paths_[extension->id()] = extension->path(); 1581 unloaded_extension_paths_[extension->id()] = extension->path();
1589 1582
1590 // Clean up if the extension is meant to be enabled after a reload. 1583 // Clean up if the extension is meant to be enabled after a reload.
1591 reloading_extensions_.erase(extension->id()); 1584 reloading_extensions_.erase(extension->id());
1592 1585
1593 // Clean up runtime data. 1586 bool was_disabled =
1594 extension_runtime_data_.erase(extension_id); 1587 registry_->disabled_extensions().Contains(extension->id());
1595 1588
1596 if (registry_->disabled_extensions().Contains(extension->id())) { 1589 // Remove the extension from the registry.
1590 if (was_disabled)
1597 registry_->RemoveDisabled(extension->id()); 1591 registry_->RemoveDisabled(extension->id());
1592 else
1593 registry_->RemoveEnabled(extension->id());
1594 registry_->TriggerOnUnloaded(extension);
not at google - send to devlin 2014/01/22 16:17:43 Should this go in NotifyExtensionUnloaded? That wo
James Cook 2014/01/22 17:41:52 The code I wrote has identical behavior to the old
not at google - send to devlin 2014/01/22 17:49:07 Yeah I'm questioning whether the old code is corre
1595
1596 // Notify other subsystems that the extension is gone.
1597 if (was_disabled) {
1598 // Make sure the profile cleans up its RequestContexts when an already 1598 // Make sure the profile cleans up its RequestContexts when an already
1599 // disabled extension is unloaded (since they are also tracking the disabled 1599 // disabled extension is unloaded (since they are also tracking the disabled
1600 // extensions). 1600 // extensions).
1601 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); 1601 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
1602 } else { 1602 } else {
1603 // Remove the extension from the enabled list.
1604 registry_->RemoveEnabled(extension->id());
1605 NotifyExtensionUnloaded(extension.get(), reason); 1603 NotifyExtensionUnloaded(extension.get(), reason);
1606 } 1604 }
1607 1605
1608 content::NotificationService::current()->Notify( 1606 content::NotificationService::current()->Notify(
1609 chrome::NOTIFICATION_EXTENSION_REMOVED, 1607 chrome::NOTIFICATION_EXTENSION_REMOVED,
1610 content::Source<Profile>(profile_), 1608 content::Source<Profile>(profile_),
1611 content::Details<const Extension>(extension.get())); 1609 content::Details<const Extension>(extension.get()));
1612 } 1610 }
1613 1611
1614 void ExtensionService::RemoveComponentExtension( 1612 void ExtensionService::RemoveComponentExtension(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 if (old) { 1712 if (old) {
1715 is_extension_installed = true; 1713 is_extension_installed = true;
1716 int version_compare_result = 1714 int version_compare_result =
1717 extension->version()->CompareTo(*(old->version())); 1715 extension->version()->CompareTo(*(old->version()));
1718 is_extension_upgrade = version_compare_result > 0; 1716 is_extension_upgrade = version_compare_result > 0;
1719 // Other than for unpacked extensions, CrxInstaller should have guaranteed 1717 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1720 // that we aren't downgrading. 1718 // that we aren't downgrading.
1721 if (!Manifest::IsUnpackedLocation(extension->location())) 1719 if (!Manifest::IsUnpackedLocation(extension->location()))
1722 CHECK_GE(version_compare_result, 0); 1720 CHECK_GE(version_compare_result, 0);
1723 } 1721 }
1724 SetBeingUpgraded(extension, is_extension_upgrade); 1722 system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade);
1725 1723
1726 // The extension is now loaded, remove its data from unloaded extension map. 1724 // The extension is now loaded, remove its data from unloaded extension map.
1727 unloaded_extension_paths_.erase(extension->id()); 1725 unloaded_extension_paths_.erase(extension->id());
1728 1726
1729 // If a terminated extension is loaded, remove it from the terminated list. 1727 // If a terminated extension is loaded, remove it from the terminated list.
1730 UntrackTerminatedExtension(extension->id()); 1728 UntrackTerminatedExtension(extension->id());
1731 1729
1732 // If the extension was disabled for a reload, then enable it. 1730 // If the extension was disabled for a reload, then enable it.
1733 bool reloading = reloading_extensions_.erase(extension->id()) > 0; 1731 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
1734 1732
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 } 1775 }
1778 extension_prefs_->app_sorting()->EnsureValidOrdinals( 1776 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1779 extension->id(), syncer::StringOrdinal()); 1777 extension->id(), syncer::StringOrdinal());
1780 } 1778 }
1781 1779
1782 registry_->AddEnabled(extension); 1780 registry_->AddEnabled(extension);
1783 if (extension_sync_service_) 1781 if (extension_sync_service_)
1784 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); 1782 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
1785 NotifyExtensionLoaded(extension); 1783 NotifyExtensionLoaded(extension);
1786 } 1784 }
1787 SetBeingUpgraded(extension, false); 1785 system_->runtime_data()->SetBeingUpgraded(extension, false);
1788 } 1786 }
1789 1787
1790 void ExtensionService::AddComponentExtension(const Extension* extension) { 1788 void ExtensionService::AddComponentExtension(const Extension* extension) {
1791 const std::string old_version_string( 1789 const std::string old_version_string(
1792 extension_prefs_->GetVersionString(extension->id())); 1790 extension_prefs_->GetVersionString(extension->id()));
1793 const Version old_version(old_version_string); 1791 const Version old_version(old_version_string);
1794 1792
1795 VLOG(1) << "AddComponentExtension " << extension->name(); 1793 VLOG(1) << "AddComponentExtension " << extension->name();
1796 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { 1794 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1797 VLOG(1) << "Component extension " << extension->name() << " (" 1795 VLOG(1) << "Component extension " << extension->name() << " ("
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
2612 const ExtensionSet& extensions = registry_->enabled_extensions(); 2610 const ExtensionSet& extensions = registry_->enabled_extensions();
2613 for (ExtensionSet::const_iterator it = extensions.begin(); 2611 for (ExtensionSet::const_iterator it = extensions.begin();
2614 it != extensions.end(); ++it) { 2612 it != extensions.end(); ++it) {
2615 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT) 2613 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT)
2616 result.insert((*it)->id()); 2614 result.insert((*it)->id());
2617 } 2615 }
2618 2616
2619 return result; 2617 return result;
2620 } 2618 }
2621 2619
2622 bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const {
2623 if (!extensions::BackgroundInfo::HasPersistentBackgroundPage(extension))
2624 return true;
2625 ExtensionRuntimeDataMap::const_iterator it =
2626 extension_runtime_data_.find(extension->id());
2627 return it == extension_runtime_data_.end() ? false :
2628 it->second.background_page_ready;
2629 }
2630
2631 void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
2632 DCHECK(extensions::BackgroundInfo::HasBackgroundPage(extension));
2633 extension_runtime_data_[extension->id()].background_page_ready = true;
2634 }
2635
2636 bool ExtensionService::IsBeingUpgraded(const Extension* extension) const {
2637 ExtensionRuntimeDataMap::const_iterator it =
2638 extension_runtime_data_.find(extension->id());
2639 return it == extension_runtime_data_.end() ? false :
2640 it->second.being_upgraded;
2641 }
2642
2643 void ExtensionService::SetBeingUpgraded(const Extension* extension,
2644 bool value) {
2645 extension_runtime_data_[extension->id()].being_upgraded = value;
2646 }
2647
2648 bool ExtensionService::IsBeingReloaded( 2620 bool ExtensionService::IsBeingReloaded(
2649 const std::string& extension_id) const { 2621 const std::string& extension_id) const {
2650 return ContainsKey(extensions_being_reloaded_, extension_id); 2622 return ContainsKey(extensions_being_reloaded_, extension_id);
2651 } 2623 }
2652 2624
2653 void ExtensionService::SetBeingReloaded(const std::string& extension_id, 2625 void ExtensionService::SetBeingReloaded(const std::string& extension_id,
2654 bool isBeingReloaded) { 2626 bool isBeingReloaded) {
2655 if (isBeingReloaded) 2627 if (isBeingReloaded)
2656 extensions_being_reloaded_.insert(extension_id); 2628 extensions_being_reloaded_.insert(extension_id);
2657 else 2629 else
2658 extensions_being_reloaded_.erase(extension_id); 2630 extensions_being_reloaded_.erase(extension_id);
2659 } 2631 }
2660 2632
2661 bool ExtensionService::HasUsedWebRequest(const Extension* extension) const {
2662 ExtensionRuntimeDataMap::const_iterator it =
2663 extension_runtime_data_.find(extension->id());
2664 return it == extension_runtime_data_.end() ? false :
2665 it->second.has_used_webrequest;
2666 }
2667
2668 void ExtensionService::SetHasUsedWebRequest(const Extension* extension,
2669 bool value) {
2670 extension_runtime_data_[extension->id()].has_used_webrequest = value;
2671 }
2672
2673 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { 2633 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2674 // Extensions installed by policy can't be disabled. So even if a previous 2634 // Extensions installed by policy can't be disabled. So even if a previous
2675 // installation disabled the extension, make sure it is now enabled. 2635 // installation disabled the extension, make sure it is now enabled.
2676 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) 2636 if (system_->management_policy()->MustRemainEnabled(extension, NULL))
2677 return true; 2637 return true;
2678 2638
2679 if (extension_prefs_->IsExtensionDisabled(extension->id())) 2639 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2680 return false; 2640 return false;
2681 2641
2682 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { 2642 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 void ExtensionService::RemoveUpdateObserver( 2775 void ExtensionService::RemoveUpdateObserver(
2816 extensions::UpdateObserver* observer) { 2776 extensions::UpdateObserver* observer) {
2817 update_observers_.RemoveObserver(observer); 2777 update_observers_.RemoveObserver(observer);
2818 } 2778 }
2819 2779
2820 // Used only by test code. 2780 // Used only by test code.
2821 void ExtensionService::UnloadAllExtensionsInternal() { 2781 void ExtensionService::UnloadAllExtensionsInternal() {
2822 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2782 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2823 2783
2824 registry_->ClearAll(); 2784 registry_->ClearAll();
2825 extension_runtime_data_.clear(); 2785 system_->runtime_data()->ClearAll();
2826 2786
2827 // TODO(erikkay) should there be a notification for this? We can't use 2787 // TODO(erikkay) should there be a notification for this? We can't use
2828 // EXTENSION_UNLOADED since that implies that the extension has been disabled 2788 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2829 // or uninstalled. 2789 // or uninstalled.
2830 } 2790 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698