summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-14 15:07:04 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-14 15:07:04 +0000
commitda5f6a8c64d48c97ed538bf5e28fb1e6d029c38c (patch)
tree328ec84fc18150d46a0782e48c27d15bba87a15a /chrome/browser/extensions
parenta088edb47abbc807aff5dd05734fed0c1e39043e (diff)
downloadchromium_src-da5f6a8c64d48c97ed538bf5e28fb1e6d029c38c.zip
chromium_src-da5f6a8c64d48c97ed538bf5e28fb1e6d029c38c.tar.gz
chromium_src-da5f6a8c64d48c97ed538bf5e28fb1e6d029c38c.tar.bz2
Prevent an extension from double observing a message filter.
Fixes Vista ui_test debug failures. Patch by Paul Godavari Review: http://codereview.chromium.org/67120 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13660 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rwxr-xr-xchrome/browser/extensions/extension_message_service.cc32
-rwxr-xr-xchrome/browser/extensions/extension_message_service.h6
2 files changed, 25 insertions, 13 deletions
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc
index f200c5b..74e2757 100755
--- a/chrome/browser/extensions/extension_message_service.cc
+++ b/chrome/browser/extensions/extension_message_service.cc
@@ -129,15 +129,19 @@ void ExtensionMessageService::PostMessageFromRenderer(
dest->Send(new ViewMsg_ExtensionHandleMessage(message, source_port_id));
}
-void ExtensionMessageService::RendererReady(ResourceMessageFilter* renderer) {
+void ExtensionMessageService::RendererReady(ResourceMessageFilter* filter) {
AutoLock lock(renderers_lock_);
- DCHECK(renderers_.find(renderer->GetProcessId()) == renderers_.end());
- renderers_[renderer->GetProcessId()] = renderer;
-
- NotificationService::current()->AddObserver(
- this,
- NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN,
- Source<ResourceMessageFilter>(renderer));
+ DCHECK(renderers_.find(filter->GetProcessId()) == renderers_.end());
+ renderers_[filter->GetProcessId()] = filter;
+
+ // Only observe this filter if we haven't seen it before.
+ if (filters_.find(filter) == filters_.end()) {
+ filters_.insert(filter);
+ NotificationService::current()->AddObserver(
+ this,
+ NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN,
+ Source<ResourceMessageFilter>(filter));
+ }
}
void ExtensionMessageService::Observe(NotificationType type,
@@ -161,9 +165,13 @@ void ExtensionMessageService::Observe(NotificationType type,
channels_.erase(current);
}
- NotificationService::current()->RemoveObserver(
- this,
- NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN,
- Source<ResourceMessageFilter>(filter));
+ std::set<ResourceMessageFilter*>::iterator fit = filters_.find(filter);
+ if (fit != filters_.end()) {
+ filters_.erase(fit);
+ NotificationService::current()->RemoveObserver(
+ this,
+ NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN,
+ source);
+ }
}
diff --git a/chrome/browser/extensions/extension_message_service.h b/chrome/browser/extensions/extension_message_service.h
index 1fc3c51..1238338 100755
--- a/chrome/browser/extensions/extension_message_service.h
+++ b/chrome/browser/extensions/extension_message_service.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_
#include <map>
+#include <set>
#include <string>
#include "base/lock.h"
@@ -53,7 +54,7 @@ class ExtensionMessageService : public NotificationObserver {
// --- UI or IO thread:
// Called to let us know that a renderer has been started.
- void RendererReady(ResourceMessageFilter* port);
+ void RendererReady(ResourceMessageFilter* filter);
// NotificationObserver interface.
void Observe(NotificationType type,
@@ -89,6 +90,9 @@ class ExtensionMessageService : public NotificationObserver {
// For generating unique channel IDs.
int next_port_id_;
+
+ // For tracking the ResourceMessageFilters we are observing.
+ std::set<ResourceMessageFilter*> filters_;
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_