summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/webmessageportchannel_impl.cc77
-rw-r--r--chrome/common/webmessageportchannel_impl.h11
-rw-r--r--chrome/common/worker_messages.h3
-rw-r--r--chrome/common/worker_messages_internal.h11
4 files changed, 64 insertions, 38 deletions
diff --git a/chrome/common/webmessageportchannel_impl.cc b/chrome/common/webmessageportchannel_impl.cc
index 6e1b4e1..f585355 100644
--- a/chrome/common/webmessageportchannel_impl.cc
+++ b/chrome/common/webmessageportchannel_impl.cc
@@ -11,6 +11,7 @@
#include "webkit/api/public/WebMessagePortChannelClient.h"
using WebKit::WebMessagePortChannel;
+using WebKit::WebMessagePortChannelArray;
using WebKit::WebMessagePortChannelClient;
using WebKit::WebString;
@@ -33,6 +34,16 @@ WebMessagePortChannelImpl::WebMessagePortChannelImpl(
}
WebMessagePortChannelImpl::~WebMessagePortChannelImpl() {
+ // If we have any queued messages with attached ports, manually destroy them.
+ while (!message_queue_.empty()) {
+ const std::vector<WebMessagePortChannelImpl*>& channel_array =
+ message_queue_.front().ports;
+ for (size_t i = 0; i < channel_array.size(); i++) {
+ channel_array[i]->destroy();
+ }
+ message_queue_.pop();
+ }
+
if (message_port_id_ != MSG_ROUTING_NONE)
Send(new WorkerProcessHostMsg_DestroyMessagePort(message_port_id_));
@@ -65,39 +76,46 @@ void WebMessagePortChannelImpl::entangle(WebMessagePortChannel* channel) {
void WebMessagePortChannelImpl::postMessage(
const WebString& message,
- WebMessagePortChannel* channel) {
+ WebMessagePortChannelArray* channels) {
if (MessageLoop::current() != ChildThread::current()->message_loop()) {
ChildThread::current()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(this, &WebMessagePortChannelImpl::postMessage,
- message, channel));
+ message, channels));
return;
}
- WebMessagePortChannelImpl* webchannel =
- static_cast<WebMessagePortChannelImpl*>(channel);
-
- int message_port_id = MSG_ROUTING_NONE;
- if (webchannel) {
- message_port_id = webchannel->message_port_id();
- webchannel->QueueMessages();
- DCHECK(message_port_id != MSG_ROUTING_NONE);
+ std::vector<int> message_port_ids(channels ? channels->size() : 0);
+ if (channels) {
+ for (size_t i = 0; i < channels->size(); ++i) {
+ WebMessagePortChannelImpl* webchannel =
+ static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
+ message_port_ids[i] = webchannel->message_port_id();
+ webchannel->QueueMessages();
+ DCHECK(message_port_ids[i] != MSG_ROUTING_NONE);
+ }
}
IPC::Message* msg = new WorkerProcessHostMsg_PostMessage(
- message_port_id_, message, message_port_id);
-
+ message_port_id_, message, message_port_ids);
Send(msg);
}
bool WebMessagePortChannelImpl::tryGetMessage(
WebString* message,
- WebMessagePortChannel** channel) {
+ WebMessagePortChannelArray& channels) {
AutoLock auto_lock(lock_);
if (message_queue_.empty())
return false;
*message = message_queue_.front().message;
- *channel = message_queue_.front().port.release();
+ const std::vector<WebMessagePortChannelImpl*>& channel_array =
+ message_queue_.front().ports;
+ WebMessagePortChannelArray result_ports(channel_array.size());
+ for (size_t i = 0; i < channel_array.size(); i++) {
+ result_ports[i] = channel_array[i];
+ }
+
+ channels.swap(result_ports);
message_queue_.pop();
return true;
}
@@ -162,16 +180,19 @@ void WebMessagePortChannelImpl::OnMessageReceived(const IPC::Message& message) {
IPC_END_MESSAGE_MAP()
}
-void WebMessagePortChannelImpl::OnMessage(const string16& message,
- int sent_message_port_id,
- int new_routing_id) {
+void WebMessagePortChannelImpl::OnMessage(
+ const string16& message,
+ const std::vector<int>& sent_message_port_ids,
+ const std::vector<int>& new_routing_ids) {
AutoLock auto_lock(lock_);
Message msg;
msg.message = message;
- msg.port = NULL;
- if (sent_message_port_id != MSG_ROUTING_NONE) {
- msg.port = new WebMessagePortChannelImpl(
- new_routing_id, sent_message_port_id);
+ if (!sent_message_port_ids.empty()) {
+ msg.ports.resize(sent_message_port_ids.size());
+ for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
+ msg.ports[i] = new WebMessagePortChannelImpl(
+ new_routing_ids[i], sent_message_port_ids[i]);
+ }
}
bool was_empty = message_queue_.empty();
@@ -181,18 +202,20 @@ void WebMessagePortChannelImpl::OnMessage(const string16& message,
}
void WebMessagePortChannelImpl::OnMessagedQueued() {
- std::vector<std::pair<string16, int> > queued_messages;
+ std::vector<QueuedMessage> queued_messages;
{
AutoLock auto_lock(lock_);
queued_messages.reserve(message_queue_.size());
while (!message_queue_.empty()) {
string16 message = message_queue_.front().message;
- int port = MSG_ROUTING_NONE;
- if (message_queue_.front().port)
- port = message_queue_.front().port->message_port_id();
-
- queued_messages.push_back(std::make_pair(message, port));
+ const std::vector<WebMessagePortChannelImpl*>& channel_array =
+ message_queue_.front().ports;
+ std::vector<int> port_ids(channel_array.size());
+ for (size_t i = 0; i < channel_array.size(); ++i) {
+ port_ids[i] = channel_array[i]->message_port_id();
+ }
+ queued_messages.push_back(std::make_pair(message, port_ids));
message_queue_.pop();
}
}
diff --git a/chrome/common/webmessageportchannel_impl.h b/chrome/common/webmessageportchannel_impl.h
index ee26e66..89a36b0 100644
--- a/chrome/common/webmessageportchannel_impl.h
+++ b/chrome/common/webmessageportchannel_impl.h
@@ -6,6 +6,7 @@
#define CHROME_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_
#include <queue>
+#include <vector>
#include "base/basictypes.h"
#include "base/lock.h"
@@ -37,9 +38,9 @@ class WebMessagePortChannelImpl
virtual void destroy();
virtual void entangle(WebKit::WebMessagePortChannel* channel);
virtual void postMessage(const WebKit::WebString& message,
- WebKit::WebMessagePortChannel* channel);
+ WebKit::WebMessagePortChannelArray* channels);
virtual bool tryGetMessage(WebKit::WebString* message,
- WebKit::WebMessagePortChannel** channel);
+ WebKit::WebMessagePortChannelArray& channels);
void Init();
void Entangle(scoped_refptr<WebMessagePortChannelImpl> channel);
@@ -49,13 +50,13 @@ class WebMessagePortChannelImpl
virtual void OnMessageReceived(const IPC::Message& message);
void OnMessage(const string16& message,
- int sent_message_port_id,
- int new_routing_id);
+ const std::vector<int>& sent_message_port_ids,
+ const std::vector<int>& new_routing_ids);
void OnMessagedQueued();
struct Message {
string16 message;
- scoped_refptr<WebMessagePortChannelImpl> port;
+ std::vector<WebMessagePortChannelImpl*> ports;
};
typedef std::queue<Message> MessageQueue;
diff --git a/chrome/common/worker_messages.h b/chrome/common/worker_messages.h
index b929d2c..4af15c4 100644
--- a/chrome/common/worker_messages.h
+++ b/chrome/common/worker_messages.h
@@ -9,12 +9,13 @@
#define CHROME_COMMON_WORKER_MESSAGES_H_
#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "chrome/common/common_param_traits.h"
#include "ipc/ipc_message_utils.h"
-typedef std::pair<string16, int> QueuedMessage;
+typedef std::pair<string16, std::vector<int> > QueuedMessage;
// Parameters structure for WorkerHostMsg_PostConsoleMessageToWorkerObject,
// which has too many data parameters to be reasonably put in a predefined
diff --git a/chrome/common/worker_messages_internal.h b/chrome/common/worker_messages_internal.h
index 16dab5d..9b1cac2 100644
--- a/chrome/common/worker_messages_internal.h
+++ b/chrome/common/worker_messages_internal.h
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <utility>
+#include <vector>
#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message_macros.h"
@@ -21,8 +22,8 @@ IPC_BEGIN_MESSAGES(WorkerProcess)
// like common_messages_internal.h
IPC_MESSAGE_ROUTED3(WorkerProcessMsg_Message,
string16 /* message */,
- int /* sent_message_port_id */,
- int /* new_routing_id */)
+ std::vector<int> /* sent_message_port_ids */,
+ std::vector<int> /* new_routing_ids */)
// Tells the Message Port Channel object that there are no more in-flight
// messages arriving.
@@ -55,7 +56,7 @@ IPC_BEGIN_MESSAGES(WorkerProcessHost)
IPC_MESSAGE_CONTROL3(WorkerProcessHostMsg_PostMessage,
int /* sender_message_port_id */,
string16 /* message */,
- int /* sent_message_port_id */)
+ std::vector<int> /* sent_message_port_ids */)
// Causes messages sent to the remote port to be delivered to this local port.
IPC_MESSAGE_CONTROL2(WorkerProcessHostMsg_Entangle,
@@ -90,8 +91,8 @@ IPC_BEGIN_MESSAGES(Worker)
IPC_MESSAGE_ROUTED3(WorkerMsg_PostMessage,
string16 /* message */,
- int /* sent_message_port_id */,
- int /* new_routing_id */)
+ std::vector<int> /* sent_message_port_ids */,
+ std::vector<int> /* new_routing_ids */)
IPC_MESSAGE_ROUTED0(WorkerMsg_WorkerObjectDestroyed)
IPC_END_MESSAGES(Worker)