summaryrefslogtreecommitdiffstats
path: root/chrome/browser/worker_host
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-26 21:38:03 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-26 21:38:03 +0000
commitc36a24cbfdc6cb945f104d65174ef2aaa59e5dd3 (patch)
tree6f77d943b793b1f6968660c2ce3fb32f432369ed /chrome/browser/worker_host
parentc28a6aac0d9687b43781bb21fdef3b6849c0d398 (diff)
downloadchromium_src-c36a24cbfdc6cb945f104d65174ef2aaa59e5dd3.zip
chromium_src-c36a24cbfdc6cb945f104d65174ef2aaa59e5dd3.tar.gz
chromium_src-c36a24cbfdc6cb945f104d65174ef2aaa59e5dd3.tar.bz2
First half of updating Worker.postMessage(), DOMWindow.postMessage(), and
MessagePort.postMessage() to accept multiple MessagePorts. Original review: http://codereview.chromium.org/173193 TBR=atwilson TEST=None (new functionality not yet exposed via bindings, so existing tests suffice) BUG=19948 Review URL: http://codereview.chromium.org/174566 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24536 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/worker_host')
-rw-r--r--chrome/browser/worker_host/message_port_dispatcher.cc50
-rw-r--r--chrome/browser/worker_host/message_port_dispatcher.h6
-rw-r--r--chrome/browser/worker_host/worker_process_host.cc16
3 files changed, 40 insertions, 32 deletions
diff --git a/chrome/browser/worker_host/message_port_dispatcher.cc b/chrome/browser/worker_host/message_port_dispatcher.cc
index 4d371de..41ebc37 100644
--- a/chrome/browser/worker_host/message_port_dispatcher.cc
+++ b/chrome/browser/worker_host/message_port_dispatcher.cc
@@ -117,9 +117,10 @@ void MessagePortDispatcher::OnEntangle(int local_message_port_id,
local_message_port_id;
}
-void MessagePortDispatcher::OnPostMessage(int sender_message_port_id,
- const string16& message,
- int sent_message_port_id) {
+void MessagePortDispatcher::OnPostMessage(
+ int sender_message_port_id,
+ const string16& message,
+ const std::vector<int>& sent_message_port_ids) {
if (!message_ports_.count(sender_message_port_id)) {
NOTREACHED();
return;
@@ -135,47 +136,52 @@ void MessagePortDispatcher::OnPostMessage(int sender_message_port_id,
return;
}
- PostMessageTo(entangled_message_port_id, message, sent_message_port_id);
+ PostMessageTo(entangled_message_port_id, message, sent_message_port_ids);
}
-void MessagePortDispatcher::PostMessageTo(int message_port_id,
- const string16& message,
- int sent_message_port_id) {
- if (!message_ports_.count(message_port_id) ||
- (sent_message_port_id != MSG_ROUTING_NONE &&
- !message_ports_.count(sent_message_port_id))) {
+void MessagePortDispatcher::PostMessageTo(
+ int message_port_id,
+ const string16& message,
+ const std::vector<int>& sent_message_port_ids) {
+ if (!message_ports_.count(message_port_id)) {
NOTREACHED();
return;
}
+ for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
+ if (!message_ports_.count(sent_message_port_ids[i])) {
+ NOTREACHED();
+ return;
+ }
+ }
MessagePort& entangled_port = message_ports_[message_port_id];
- MessagePort* sent_port = NULL;
- if (sent_message_port_id != MSG_ROUTING_NONE) {
- sent_port = &message_ports_[sent_message_port_id];
- sent_port->queue_messages = true;
+ std::vector<MessagePort*> sent_ports(sent_message_port_ids.size());
+ for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
+ sent_ports[i] = &message_ports_[sent_message_port_ids[i]];
+ sent_ports[i]->queue_messages = true;
}
if (entangled_port.queue_messages) {
entangled_port.queued_messages.push_back(
- std::make_pair(message, sent_message_port_id));
+ std::make_pair(message, sent_message_port_ids));
} else {
// If a message port was sent around, the new location will need a routing
// id. Instead of having the created port send us a sync message to get it,
// send along with the message.
- int new_routing_id = MSG_ROUTING_NONE;
- if (sent_message_port_id != MSG_ROUTING_NONE) {
- new_routing_id = entangled_port.next_routing_id->Run();
- sent_port->sender = entangled_port.sender;
+ std::vector<int> new_routing_ids(sent_message_port_ids.size());
+ for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
+ new_routing_ids[i] = entangled_port.next_routing_id->Run();
+ sent_ports[i]->sender = entangled_port.sender;
// Update the entry for the sent port as it can be in a different process.
- sent_port->route_id = new_routing_id;
+ sent_ports[i]->route_id = new_routing_ids[i];
}
// Now send the message to the entangled port.
IPC::Message* ipc_msg = new WorkerProcessMsg_Message(
- entangled_port.route_id, message, sent_message_port_id,
- new_routing_id);
+ entangled_port.route_id, message, sent_message_port_ids,
+ new_routing_ids);
entangled_port.sender->Send(ipc_msg);
}
}
diff --git a/chrome/browser/worker_host/message_port_dispatcher.h b/chrome/browser/worker_host/message_port_dispatcher.h
index ae2536b..c728f38 100644
--- a/chrome/browser/worker_host/message_port_dispatcher.h
+++ b/chrome/browser/worker_host/message_port_dispatcher.h
@@ -18,7 +18,7 @@
class MessagePortDispatcher : public NotificationObserver {
public:
- typedef std::vector<std::pair<string16, int> > QueuedMessages;
+ typedef std::vector<std::pair<string16, std::vector<int> > > QueuedMessages;
// Returns the MessagePortDispatcher singleton.
static MessagePortDispatcher* GetInstance();
@@ -48,14 +48,14 @@ class MessagePortDispatcher : public NotificationObserver {
void OnEntangle(int local_message_port_id, int remote_message_port_id);
void OnPostMessage(int sender_message_port_id,
const string16& message,
- int sent_message_port_id);
+ const std::vector<int>& sent_message_port_ids);
void OnQueueMessages(int message_port_id);
void OnSendQueuedMessages(int message_port_id,
const QueuedMessages& queued_messages);
void PostMessageTo(int message_port_id,
const string16& message,
- int sent_message_port_id);
+ const std::vector<int>& sent_message_port_ids);
// NotificationObserver interface.
void Observe(NotificationType type,
diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc
index 3de362cf..69d3a96 100644
--- a/chrome/browser/worker_host/worker_process_host.cc
+++ b/chrome/browser/worker_host/worker_process_host.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/worker_host/worker_process_host.h"
#include <set>
+#include <vector>
#include "base/command_line.h"
#include "base/debug_util.h"
@@ -232,21 +233,22 @@ void WorkerProcessHost::RelayMessage(
// We want to send the receiver a routing id for the new channel, so
// crack the message first.
string16 msg;
- int sent_message_port_id = MSG_ROUTING_NONE;
- int new_routing_id = MSG_ROUTING_NONE;
+ std::vector<int> sent_message_port_ids;
+ std::vector<int> new_routing_ids;
if (!WorkerMsg_PostMessage::Read(
- &message, &msg, &sent_message_port_id, &new_routing_id)) {
+ &message, &msg, &sent_message_port_ids, &new_routing_ids)) {
return;
}
+ DCHECK(sent_message_port_ids.size() == new_routing_ids.size());
- if (sent_message_port_id != MSG_ROUTING_NONE) {
- new_routing_id = next_route_id->Run();
+ for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
+ new_routing_ids[i] = next_route_id->Run();
MessagePortDispatcher::GetInstance()->UpdateMessagePort(
- sent_message_port_id, sender, new_routing_id, next_route_id);
+ sent_message_port_ids[i], sender, new_routing_ids[i], next_route_id);
}
new_message = new WorkerMsg_PostMessage(
- route_id, msg, sent_message_port_id, new_routing_id);
+ route_id, msg, sent_message_port_ids, new_routing_ids);
} else {
new_message = new IPC::Message(message);
new_message->set_routing_id(route_id);