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

Unified 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: add ExtensionRegistry observer (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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service.cc
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index b9c734071674fc1a52e7e0df6d7d737803cc8c26..51226d8bc498624c582d2a94dbf2df553f800c94 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -83,6 +83,7 @@
#include "extensions/browser/pref_names.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/process_map.h"
+#include "extensions/browser/runtime_data.h"
#include "extensions/browser/update_observer.h"
#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
@@ -189,15 +190,6 @@ class SharedModuleProvider : public extensions::ManagementPolicy::Provider {
} // namespace
-ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
- : background_page_ready(false),
- being_upgraded(false),
- has_used_webrequest(false) {
-}
-
-ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
-}
-
// ExtensionService.
void ExtensionService::CheckExternalUninstall(const std::string& id) {
@@ -740,7 +732,7 @@ void ExtensionService::ReloadExtension(const std::string extension_id) {
path = current_extension->path();
// BeingUpgraded is set back to false when the extension is added.
- SetBeingUpgraded(current_extension, true);
+ system_->runtime_data()->SetBeingUpgraded(current_extension, true);
DisableExtension(extension_id, Extension::DISABLE_RELOAD);
reloading_extensions_.insert(extension_id);
} else {
@@ -937,8 +929,7 @@ void ExtensionService::EnableExtension(const std::string& extension_id) {
}
// Move it over to the enabled list.
- registry_->AddEnabled(make_scoped_refptr(extension));
- registry_->RemoveDisabled(extension->id());
+ registry_->EnableExtension(make_scoped_refptr(extension));
NotifyExtensionLoaded(extension);
@@ -979,19 +970,12 @@ void ExtensionService::DisableExtension(
if (!extension)
return;
- // Reset the background_page_ready flag
- if (extensions::BackgroundInfo::HasBackgroundPage(extension))
- extension_runtime_data_[extension->id()].background_page_ready = false;
-
// Move it over to the disabled list. Don't send a second unload notification
// for terminated extensions being disabled.
- registry_->AddDisabled(make_scoped_refptr(extension));
- if (registry_->enabled_extensions().Contains(extension->id())) {
- registry_->RemoveEnabled(extension->id());
+ bool was_enabled = registry_->enabled_extensions().Contains(extension->id());
+ registry_->DisableExtension(make_scoped_refptr(extension));
+ if (was_enabled)
NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
- } else {
- registry_->RemoveTerminated(extension->id());
- }
if (extension_sync_service_)
extension_sync_service_->SyncDisableExtension(*extension);
@@ -1590,18 +1574,16 @@ void ExtensionService::UnloadExtension(
// Clean up if the extension is meant to be enabled after a reload.
reloading_extensions_.erase(extension->id());
- // Clean up runtime data.
- extension_runtime_data_.erase(extension_id);
-
- if (registry_->disabled_extensions().Contains(extension->id())) {
- registry_->RemoveDisabled(extension->id());
+ bool was_disabled =
+ registry_->disabled_extensions().Contains(extension->id());
+ // Take the extension out of the registry (and notify observers).
+ registry_->UnloadExtension(extension);
+ if (was_disabled) {
// Make sure the profile cleans up its RequestContexts when an already
// disabled extension is unloaded (since they are also tracking the disabled
// extensions).
system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
} else {
- // Remove the extension from the enabled list.
- registry_->RemoveEnabled(extension->id());
NotifyExtensionUnloaded(extension.get(), reason);
}
@@ -1721,7 +1703,7 @@ void ExtensionService::AddExtension(const Extension* extension) {
if (!Manifest::IsUnpackedLocation(extension->location()))
CHECK_GE(version_compare_result, 0);
}
- SetBeingUpgraded(extension, is_extension_upgrade);
+ system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade);
// The extension is now loaded, remove its data from unloaded extension map.
unloaded_extension_paths_.erase(extension->id());
@@ -1784,7 +1766,7 @@ void ExtensionService::AddExtension(const Extension* extension) {
extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
NotifyExtensionLoaded(extension);
}
- SetBeingUpgraded(extension, false);
+ system_->runtime_data()->SetBeingUpgraded(extension, false);
}
void ExtensionService::AddComponentExtension(const Extension* extension) {
@@ -2619,32 +2601,6 @@ ExtensionIdSet ExtensionService::GetAppIds() const {
return result;
}
-bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const {
- if (!extensions::BackgroundInfo::HasPersistentBackgroundPage(extension))
- return true;
- ExtensionRuntimeDataMap::const_iterator it =
- extension_runtime_data_.find(extension->id());
- return it == extension_runtime_data_.end() ? false :
- it->second.background_page_ready;
-}
-
-void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
- DCHECK(extensions::BackgroundInfo::HasBackgroundPage(extension));
- extension_runtime_data_[extension->id()].background_page_ready = true;
-}
-
-bool ExtensionService::IsBeingUpgraded(const Extension* extension) const {
- ExtensionRuntimeDataMap::const_iterator it =
- extension_runtime_data_.find(extension->id());
- return it == extension_runtime_data_.end() ? false :
- it->second.being_upgraded;
-}
-
-void ExtensionService::SetBeingUpgraded(const Extension* extension,
- bool value) {
- extension_runtime_data_[extension->id()].being_upgraded = value;
-}
-
bool ExtensionService::IsBeingReloaded(
const std::string& extension_id) const {
return ContainsKey(extensions_being_reloaded_, extension_id);
@@ -2658,18 +2614,6 @@ void ExtensionService::SetBeingReloaded(const std::string& extension_id,
extensions_being_reloaded_.erase(extension_id);
}
-bool ExtensionService::HasUsedWebRequest(const Extension* extension) const {
- ExtensionRuntimeDataMap::const_iterator it =
- extension_runtime_data_.find(extension->id());
- return it == extension_runtime_data_.end() ? false :
- it->second.has_used_webrequest;
-}
-
-void ExtensionService::SetHasUsedWebRequest(const Extension* extension,
- bool value) {
- extension_runtime_data_[extension->id()].has_used_webrequest = value;
-}
-
bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
// Extensions installed by policy can't be disabled. So even if a previous
// installation disabled the extension, make sure it is now enabled.
@@ -2822,7 +2766,7 @@ void ExtensionService::UnloadAllExtensionsInternal() {
profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
registry_->ClearAll();
- extension_runtime_data_.clear();
+ system_->runtime_data()->ClearAll();
// TODO(erikkay) should there be a notification for this? We can't use
// EXTENSION_UNLOADED since that implies that the extension has been disabled

Powered by Google App Engine
This is Rietveld 408576698