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

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: rename, bitmask (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 // Reset the background_page_ready flag.
983 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) 975 if (extensions::BackgroundInfo::HasBackgroundPage(extension))
984 extension_runtime_data_[extension->id()].background_page_ready = false; 976 system_->runtime_data()->SetBackgroundPageReady(extension, false);
985 977
986 // Move it over to the disabled list. Don't send a second unload notification 978 // Move it over to the disabled list. Don't send a second unload notification
987 // for terminated extensions being disabled. 979 // for terminated extensions being disabled.
988 registry_->AddDisabled(make_scoped_refptr(extension)); 980 registry_->AddDisabled(make_scoped_refptr(extension));
989 if (registry_->enabled_extensions().Contains(extension->id())) { 981 if (registry_->enabled_extensions().Contains(extension->id())) {
990 registry_->RemoveEnabled(extension->id()); 982 registry_->RemoveEnabled(extension->id());
991 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); 983 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
992 } else { 984 } else {
993 registry_->RemoveTerminated(extension->id()); 985 registry_->RemoveTerminated(extension->id());
994 } 986 }
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 } 1576 }
1585 1577
1586 // Keep information about the extension so that we can reload it later 1578 // Keep information about the extension so that we can reload it later
1587 // even if it's not permanently installed. 1579 // even if it's not permanently installed.
1588 unloaded_extension_paths_[extension->id()] = extension->path(); 1580 unloaded_extension_paths_[extension->id()] = extension->path();
1589 1581
1590 // Clean up if the extension is meant to be enabled after a reload. 1582 // Clean up if the extension is meant to be enabled after a reload.
1591 reloading_extensions_.erase(extension->id()); 1583 reloading_extensions_.erase(extension->id());
1592 1584
1593 // Clean up runtime data. 1585 // Clean up runtime data.
1594 extension_runtime_data_.erase(extension_id); 1586 system_->runtime_data()->Erase(extension);
1595 1587
1596 if (registry_->disabled_extensions().Contains(extension->id())) { 1588 if (registry_->disabled_extensions().Contains(extension->id())) {
1597 registry_->RemoveDisabled(extension->id()); 1589 registry_->RemoveDisabled(extension->id());
1598 // Make sure the profile cleans up its RequestContexts when an already 1590 // Make sure the profile cleans up its RequestContexts when an already
1599 // disabled extension is unloaded (since they are also tracking the disabled 1591 // disabled extension is unloaded (since they are also tracking the disabled
1600 // extensions). 1592 // extensions).
1601 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); 1593 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
1602 } else { 1594 } else {
1603 // Remove the extension from the enabled list. 1595 // Remove the extension from the enabled list.
1604 registry_->RemoveEnabled(extension->id()); 1596 registry_->RemoveEnabled(extension->id());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 if (old) { 1706 if (old) {
1715 is_extension_installed = true; 1707 is_extension_installed = true;
1716 int version_compare_result = 1708 int version_compare_result =
1717 extension->version()->CompareTo(*(old->version())); 1709 extension->version()->CompareTo(*(old->version()));
1718 is_extension_upgrade = version_compare_result > 0; 1710 is_extension_upgrade = version_compare_result > 0;
1719 // Other than for unpacked extensions, CrxInstaller should have guaranteed 1711 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1720 // that we aren't downgrading. 1712 // that we aren't downgrading.
1721 if (!Manifest::IsUnpackedLocation(extension->location())) 1713 if (!Manifest::IsUnpackedLocation(extension->location()))
1722 CHECK_GE(version_compare_result, 0); 1714 CHECK_GE(version_compare_result, 0);
1723 } 1715 }
1724 SetBeingUpgraded(extension, is_extension_upgrade); 1716 system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade);
1725 1717
1726 // The extension is now loaded, remove its data from unloaded extension map. 1718 // The extension is now loaded, remove its data from unloaded extension map.
1727 unloaded_extension_paths_.erase(extension->id()); 1719 unloaded_extension_paths_.erase(extension->id());
1728 1720
1729 // If a terminated extension is loaded, remove it from the terminated list. 1721 // If a terminated extension is loaded, remove it from the terminated list.
1730 UntrackTerminatedExtension(extension->id()); 1722 UntrackTerminatedExtension(extension->id());
1731 1723
1732 // If the extension was disabled for a reload, then enable it. 1724 // If the extension was disabled for a reload, then enable it.
1733 bool reloading = reloading_extensions_.erase(extension->id()) > 0; 1725 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
1734 1726
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 } 1769 }
1778 extension_prefs_->app_sorting()->EnsureValidOrdinals( 1770 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1779 extension->id(), syncer::StringOrdinal()); 1771 extension->id(), syncer::StringOrdinal());
1780 } 1772 }
1781 1773
1782 registry_->AddEnabled(extension); 1774 registry_->AddEnabled(extension);
1783 if (extension_sync_service_) 1775 if (extension_sync_service_)
1784 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); 1776 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
1785 NotifyExtensionLoaded(extension); 1777 NotifyExtensionLoaded(extension);
1786 } 1778 }
1787 SetBeingUpgraded(extension, false); 1779 system_->runtime_data()->SetBeingUpgraded(extension, false);
1788 } 1780 }
1789 1781
1790 void ExtensionService::AddComponentExtension(const Extension* extension) { 1782 void ExtensionService::AddComponentExtension(const Extension* extension) {
1791 const std::string old_version_string( 1783 const std::string old_version_string(
1792 extension_prefs_->GetVersionString(extension->id())); 1784 extension_prefs_->GetVersionString(extension->id()));
1793 const Version old_version(old_version_string); 1785 const Version old_version(old_version_string);
1794 1786
1795 VLOG(1) << "AddComponentExtension " << extension->name(); 1787 VLOG(1) << "AddComponentExtension " << extension->name();
1796 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { 1788 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1797 VLOG(1) << "Component extension " << extension->name() << " (" 1789 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(); 2604 const ExtensionSet& extensions = registry_->enabled_extensions();
2613 for (ExtensionSet::const_iterator it = extensions.begin(); 2605 for (ExtensionSet::const_iterator it = extensions.begin();
2614 it != extensions.end(); ++it) { 2606 it != extensions.end(); ++it) {
2615 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT) 2607 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT)
2616 result.insert((*it)->id()); 2608 result.insert((*it)->id());
2617 } 2609 }
2618 2610
2619 return result; 2611 return result;
2620 } 2612 }
2621 2613
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( 2614 bool ExtensionService::IsBeingReloaded(
2649 const std::string& extension_id) const { 2615 const std::string& extension_id) const {
2650 return ContainsKey(extensions_being_reloaded_, extension_id); 2616 return ContainsKey(extensions_being_reloaded_, extension_id);
2651 } 2617 }
2652 2618
2653 void ExtensionService::SetBeingReloaded(const std::string& extension_id, 2619 void ExtensionService::SetBeingReloaded(const std::string& extension_id,
2654 bool isBeingReloaded) { 2620 bool isBeingReloaded) {
2655 if (isBeingReloaded) 2621 if (isBeingReloaded)
2656 extensions_being_reloaded_.insert(extension_id); 2622 extensions_being_reloaded_.insert(extension_id);
2657 else 2623 else
2658 extensions_being_reloaded_.erase(extension_id); 2624 extensions_being_reloaded_.erase(extension_id);
2659 } 2625 }
2660 2626
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) { 2627 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2674 // Extensions installed by policy can't be disabled. So even if a previous 2628 // Extensions installed by policy can't be disabled. So even if a previous
2675 // installation disabled the extension, make sure it is now enabled. 2629 // installation disabled the extension, make sure it is now enabled.
2676 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) 2630 if (system_->management_policy()->MustRemainEnabled(extension, NULL))
2677 return true; 2631 return true;
2678 2632
2679 if (extension_prefs_->IsExtensionDisabled(extension->id())) 2633 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2680 return false; 2634 return false;
2681 2635
2682 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { 2636 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 void ExtensionService::RemoveUpdateObserver( 2769 void ExtensionService::RemoveUpdateObserver(
2816 extensions::UpdateObserver* observer) { 2770 extensions::UpdateObserver* observer) {
2817 update_observers_.RemoveObserver(observer); 2771 update_observers_.RemoveObserver(observer);
2818 } 2772 }
2819 2773
2820 // Used only by test code. 2774 // Used only by test code.
2821 void ExtensionService::UnloadAllExtensionsInternal() { 2775 void ExtensionService::UnloadAllExtensionsInternal() {
2822 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2776 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2823 2777
2824 registry_->ClearAll(); 2778 registry_->ClearAll();
2825 extension_runtime_data_.clear(); 2779 system_->runtime_data()->ClearAll();
2826 2780
2827 // TODO(erikkay) should there be a notification for this? We can't use 2781 // 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 2782 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2829 // or uninstalled. 2783 // or uninstalled.
2830 } 2784 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698