summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-03 21:57:49 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-03 21:57:49 +0000
commitd7e9a8609d36bee7a8510dc95eec201ed44d37e0 (patch)
tree0a8536eaff24d0de0cf4a7e9d7e68dc409c98ff3 /chrome/browser
parent230d2fd2e1cafaab5cd5e4d2a9f64b4ae272550a (diff)
downloadchromium_src-d7e9a8609d36bee7a8510dc95eec201ed44d37e0.zip
chromium_src-d7e9a8609d36bee7a8510dc95eec201ed44d37e0.tar.gz
chromium_src-d7e9a8609d36bee7a8510dc95eec201ed44d37e0.tar.bz2
Kill Extension::RuntimeData and move its guts to ExtensionsService.
ImageCache remains on Extension, on the expectation that it will eventually be loaded at startup. BUG=56558 TEST=no functional change Review URL: http://codereview.chromium.org/4132005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64973 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_host.cc8
-rw-r--r--chrome/browser/extensions/extensions_service.cc42
-rw-r--r--chrome/browser/extensions/extensions_service.h31
-rw-r--r--chrome/browser/views/browser_actions_container.cc5
4 files changed, 77 insertions, 9 deletions
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 0453880..09d30b7 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -238,7 +238,8 @@ void ExtensionHost::NavigateToURL(const GURL& url) {
url_ = url;
- if (!is_background_page() && !extension_->GetBackgroundPageReady()) {
+ if (!is_background_page() &&
+ !profile_->GetExtensionsService()->IsBackgroundPageReady(extension_)) {
// Make sure the background page loads before any others.
registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY,
Source<Extension>(extension_));
@@ -253,7 +254,8 @@ void ExtensionHost::Observe(NotificationType type,
const NotificationDetails& details) {
switch (type.value) {
case NotificationType::EXTENSION_BACKGROUND_PAGE_READY:
- DCHECK(extension_->GetBackgroundPageReady());
+ DCHECK(profile_->GetExtensionsService()->
+ IsBackgroundPageReady(extension_));
NavigateToURL(url_);
break;
case NotificationType::RENDERER_PROCESS_CREATED:
@@ -397,7 +399,7 @@ void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) {
document_element_available_ = true;
if (is_background_page()) {
- extension_->SetBackgroundPageReady();
+ profile_->GetExtensionsService()->SetBackgroundPageReady(extension_);
} else {
switch (extension_host_type_) {
case ViewType::EXTENSION_INFOBAR:
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 734bdef..ea025fb 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -150,6 +150,15 @@ PendingExtensionInfo::PendingExtensionInfo()
enable_incognito_on_install(false),
install_source(Extension::INVALID) {}
+
+ExtensionsService::ExtensionRuntimeData::ExtensionRuntimeData()
+ : background_page_ready(false),
+ being_upgraded(false) {
+}
+
+ExtensionsService::ExtensionRuntimeData::~ExtensionRuntimeData() {
+}
+
// ExtensionsService.
const char* ExtensionsService::kInstallDirectoryName = "Extensions";
@@ -1386,6 +1395,9 @@ void ExtensionsService::UnloadExtension(const std::string& extension_id) {
// Clean up if the extension is meant to be enabled after a reload.
disabled_extension_paths_.erase(extension->id());
+ // Clean up runtime data.
+ extension_runtime_data_.erase(extension_id);
+
ExtensionDOMUI::UnregisterChromeURLOverrides(profile_,
extension->GetChromeURLOverrides());
@@ -1413,6 +1425,7 @@ void ExtensionsService::UnloadExtension(const std::string& extension_id) {
void ExtensionsService::UnloadAllExtensions() {
extensions_.clear();
disabled_extensions_.clear();
+ extension_runtime_data_.clear();
// TODO(erikkay) should there be a notification for this? We can't use
// EXTENSION_UNLOADED since that implies that the extension has been disabled
@@ -1485,8 +1498,8 @@ void ExtensionsService::OnExtensionLoaded(const Extension* extension,
// Extensions get upgraded if silent upgrades are allowed, otherwise
// they get disabled.
if (allow_silent_upgrade) {
- old->set_being_upgraded(true);
- extension->set_being_upgraded(true);
+ SetBeingUpgraded(old, true);
+ SetBeingUpgraded(extension, true);
}
// To upgrade an extension in place, unload the old one and
@@ -1524,7 +1537,7 @@ void ExtensionsService::OnExtensionLoaded(const Extension* extension,
}
}
- extension->set_being_upgraded(false);
+ SetBeingUpgraded(extension, false);
UpdateActiveExtensionsInCrashReporter();
@@ -1904,3 +1917,26 @@ ExtensionIdSet ExtensionsService::GetAppIds() const {
return result;
}
+
+bool ExtensionsService::IsBackgroundPageReady(const Extension* extension) {
+ return (extension->background_url().is_empty() ||
+ extension_runtime_data_[extension->id()].background_page_ready);
+}
+
+void ExtensionsService::SetBackgroundPageReady(const Extension* extension) {
+ DCHECK(!extension->background_url().is_empty());
+ extension_runtime_data_[extension->id()].background_page_ready = true;
+ NotificationService::current()->Notify(
+ NotificationType::EXTENSION_BACKGROUND_PAGE_READY,
+ Source<const Extension>(extension),
+ NotificationService::NoDetails());
+}
+
+bool ExtensionsService::IsBeingUpgraded(const Extension* extension) {
+ return extension_runtime_data_[extension->id()].being_upgraded;
+}
+
+void ExtensionsService::SetBeingUpgraded(const Extension* extension,
+ bool value) {
+ extension_runtime_data_[extension->id()].being_upgraded = value;
+}
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index 7cc2c9d..f5e541c 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -189,6 +189,17 @@ class ExtensionsService
bool AllowFileAccess(const Extension* extension);
void SetAllowFileAccess(const Extension* extension, bool allow);
+ // Whether the background page, if any, is ready. We don't load other
+ // components until then. If there is no background page, we consider it to
+ // be ready.
+ bool IsBackgroundPageReady(const Extension* extension);
+ void SetBackgroundPageReady(const Extension* extension);
+
+ // Getter and setter for the flag that specifies whether the extension is
+ // being upgraded.
+ bool IsBeingUpgraded(const Extension* extension);
+ void SetBeingUpgraded(const Extension* extension, bool value);
+
// Initialize and start all installed extensions.
void Init();
@@ -408,10 +419,25 @@ class ExtensionsService
ExtensionIdSet GetAppIds() const;
private:
- virtual ~ExtensionsService();
friend class BrowserThread;
friend class DeleteTask<ExtensionsService>;
+ // Contains Extension data that can change during the life of the process,
+ // but does not persist across restarts.
+ struct ExtensionRuntimeData {
+ // True if the background page is ready.
+ bool background_page_ready;
+
+ // True while the extension is being upgraded.
+ bool being_upgraded;
+
+ ExtensionRuntimeData();
+ ~ExtensionRuntimeData();
+ };
+ typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap;
+
+ virtual ~ExtensionsService();
+
// Clear all persistent data that may have been stored by the extension.
void ClearExtensionData(const GURL& extension_url);
@@ -463,6 +489,9 @@ class ExtensionsService
// The set of pending extensions.
PendingExtensionMap pending_extensions_;
+ // The map of extension IDs to their runtime data.
+ ExtensionRuntimeDataMap extension_runtime_data_;
+
// The full path to the directory where extensions are installed.
FilePath install_directory_;
diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc
index fb50270..b630806 100644
--- a/chrome/browser/views/browser_actions_container.cc
+++ b/chrome/browser/views/browser_actions_container.cc
@@ -915,7 +915,8 @@ void BrowserActionsContainer::BrowserActionAdded(const Extension* extension,
// Enlarge the container if it was already at maximum size and we're not in
// the middle of upgrading.
- if ((model_->GetVisibleIconCount() < 0) && !extension->being_upgraded()) {
+ if ((model_->GetVisibleIconCount() < 0) &&
+ !profile_->GetExtensionsService()->IsBeingUpgraded(extension)) {
suppress_chevron_ = true;
SaveDesiredSizeAndAnimate(Tween::LINEAR, visible_actions + 1);
} else {
@@ -940,7 +941,7 @@ void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) {
// If the extension is being upgraded we don't want the bar to shrink
// because the icon is just going to get re-added to the same location.
- if (extension->being_upgraded())
+ if (profile_->GetExtensionsService()->IsBeingUpgraded(extension))
return;
if (browser_action_views_.size() > visible_actions) {