summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_message_service.cc
diff options
context:
space:
mode:
authormpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-09 19:33:20 +0000
committermpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-09 19:33:20 +0000
commit45904e20797f8cd28a776ed0e40ba94dc4eef97e (patch)
tree00b15cd6207f993e9553313202801702b3f7b250 /chrome/browser/extensions/extension_message_service.cc
parent1cb5fbed08b85c459288c98d63cf7c3158f519a2 (diff)
downloadchromium_src-45904e20797f8cd28a776ed0e40ba94dc4eef97e.zip
chromium_src-45904e20797f8cd28a776ed0e40ba94dc4eef97e.tar.gz
chromium_src-45904e20797f8cd28a776ed0e40ba94dc4eef97e.tar.bz2
Introducing ExtensionProcessManager. This manages the ExtensionViews to
ensure there is only 1 process per extension. I also changed ExtensionMessageService from singleton to one instance per Profile. This means messages can only be passed to extensions and scripts within the same profile. Review URL: http://codereview.chromium.org/62132 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13447 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_message_service.cc')
-rwxr-xr-xchrome/browser/extensions/extension_message_service.cc35
1 files changed, 29 insertions, 6 deletions
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc
index 87469f9..ef2530a 100755
--- a/chrome/browser/extensions/extension_message_service.cc
+++ b/chrome/browser/extensions/extension_message_service.cc
@@ -12,19 +12,41 @@
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "chrome/common/render_messages.h"
+#include "chrome/common/stl_util-inl.h"
// Since we have 2 ports for every channel, we just index channels by half the
// port ID.
-#define GET_CHANNEL_ID(port_id) (port_id / 2)
+#define GET_CHANNEL_ID(port_id) ((port_id) / 2)
// Port1 is always even, port2 is always odd.
-#define IS_PORT1_ID(port_id) ((port_id & 1) == 0)
+#define IS_PORT1_ID(port_id) (((port_id) & 1) == 0)
// Change even to odd and vice versa, to get the other side of a given channel.
-#define GET_OPPOSITE_PORT_ID(source_port_id) (source_port_id ^ 1)
+#define GET_OPPOSITE_PORT_ID(source_port_id) ((source_port_id) ^ 1)
-ExtensionMessageService* ExtensionMessageService::GetInstance() {
- return Singleton<ExtensionMessageService>::get();
+namespace {
+typedef std::map<URLRequestContext*, ExtensionMessageService*> InstanceMap;
+struct SingletonData {
+ ~SingletonData() {
+ STLDeleteContainerPairSecondPointers(map.begin(), map.end());
+ }
+ Lock lock;
+ InstanceMap map;
+};
+} // namespace
+
+// static
+ExtensionMessageService* ExtensionMessageService::GetInstance(
+ URLRequestContext* context) {
+ SingletonData* data = Singleton<SingletonData>::get();
+ AutoLock lock(data->lock);
+
+ ExtensionMessageService* instance = data->map[context];
+ if (!instance) {
+ instance = new ExtensionMessageService();
+ data->map[context] = instance;
+ }
+ return instance;
}
ExtensionMessageService::ExtensionMessageService()
@@ -37,7 +59,8 @@ void ExtensionMessageService::RegisterExtension(
// TODO(mpcomplete): We need to ensure an extension always ends up in a single
// process. I think this means having an ExtensionProcessManager which holds
// a BrowsingContext for each extension.
- //DCHECK(process_ids_.find(extension_id) == process_ids_.end());
+ DCHECK(process_ids_.find(extension_id) == process_ids_.end() ||
+ process_ids_[extension_id] == render_process_id);
process_ids_[extension_id] = render_process_id;
}