summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-14 13:07:55 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-14 13:07:55 +0000
commit1ef98de512072aef57b96ad1a61d37cdf703c370 (patch)
treed6ae5bb2b6a85ce906186352c446a5541ec7b579
parent26a2ca5593e43255868d4147e0db836a17c2562c (diff)
downloadchromium_src-1ef98de512072aef57b96ad1a61d37cdf703c370.zip
chromium_src-1ef98de512072aef57b96ad1a61d37cdf703c370.tar.gz
chromium_src-1ef98de512072aef57b96ad1a61d37cdf703c370.tar.bz2
Refactoring: Move MessagePort-related IPCs and handling them away from Worker-related classes.
MessagePorts can also be used by non-workers. This is part of a series of changes to fix cross-process MessagePorts. This CL contains no functional changes. BUG=278336 Review URL: https://codereview.chromium.org/25299002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228448 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/message_port_message_filter.cc62
-rw-r--r--content/browser/message_port_message_filter.h44
-rw-r--r--content/browser/message_port_service.cc (renamed from content/browser/worker_host/message_port_service.cc)24
-rw-r--r--content/browser/message_port_service.h (renamed from content/browser/worker_host/message_port_service.h)18
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc11
-rw-r--r--content/browser/renderer_host/render_process_host_impl.h4
-rw-r--r--content/browser/worker_host/worker_message_filter.cc37
-rw-r--r--content/browser/worker_host/worker_message_filter.h16
-rw-r--r--content/browser/worker_host/worker_process_host.cc20
-rw-r--r--content/child/webmessageportchannel_impl.cc18
-rw-r--r--content/common/content_message_generator.h1
-rw-r--r--content/common/message_port_messages.h85
-rw-r--r--content/common/worker_messages.h62
-rw-r--r--content/content_browser.gypi6
-rw-r--r--content/content_common.gypi1
-rw-r--r--ipc/ipc_message_start.h1
16 files changed, 269 insertions, 141 deletions
diff --git a/content/browser/message_port_message_filter.cc b/content/browser/message_port_message_filter.cc
new file mode 100644
index 0000000..1c08497
--- /dev/null
+++ b/content/browser/message_port_message_filter.cc
@@ -0,0 +1,62 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/message_port_message_filter.h"
+
+#include "content/browser/message_port_service.h"
+#include "content/common/message_port_messages.h"
+
+namespace content {
+
+MessagePortMessageFilter::MessagePortMessageFilter(
+ const NextRoutingIDCallback& callback)
+ : next_routing_id_(callback) {
+}
+
+MessagePortMessageFilter::~MessagePortMessageFilter() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+}
+
+void MessagePortMessageFilter::OnChannelClosing() {
+ MessagePortService::GetInstance()->OnMessagePortMessageFilterClosing(this);
+}
+
+bool MessagePortMessageFilter::OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(MessagePortMessageFilter, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER(MessagePortHostMsg_CreateMessagePort,
+ OnCreateMessagePort)
+ IPC_MESSAGE_FORWARD(MessagePortHostMsg_DestroyMessagePort,
+ MessagePortService::GetInstance(),
+ MessagePortService::Destroy)
+ IPC_MESSAGE_FORWARD(MessagePortHostMsg_Entangle,
+ MessagePortService::GetInstance(),
+ MessagePortService::Entangle)
+ IPC_MESSAGE_FORWARD(MessagePortHostMsg_PostMessage,
+ MessagePortService::GetInstance(),
+ MessagePortService::PostMessage)
+ IPC_MESSAGE_FORWARD(MessagePortHostMsg_QueueMessages,
+ MessagePortService::GetInstance(),
+ MessagePortService::QueueMessages)
+ IPC_MESSAGE_FORWARD(MessagePortHostMsg_SendQueuedMessages,
+ MessagePortService::GetInstance(),
+ MessagePortService::SendQueuedMessages)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP_EX()
+
+ return handled;
+}
+
+int MessagePortMessageFilter::GetNextRoutingID() {
+ return next_routing_id_.Run();
+}
+
+void MessagePortMessageFilter::OnCreateMessagePort(int *route_id,
+ int* message_port_id) {
+ *route_id = next_routing_id_.Run();
+ MessagePortService::GetInstance()->Create(*route_id, this, message_port_id);
+}
+
+} // namespace content
diff --git a/content/browser/message_port_message_filter.h b/content/browser/message_port_message_filter.h
new file mode 100644
index 0000000..592eba6
--- /dev/null
+++ b/content/browser/message_port_message_filter.h
@@ -0,0 +1,44 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_MESSAGE_PORT_MESSAGE_FILTER_H_
+#define CONTENT_BROWSER_MESSAGE_PORT_MESSAGE_FILTER_H_
+
+#include "base/callback.h"
+#include "content/public/browser/browser_message_filter.h"
+
+namespace content {
+
+// Filter for MessagePort related IPC messages (creating and destroying a
+// MessagePort, sending a message via a MessagePort etc).
+class MessagePortMessageFilter : public BrowserMessageFilter {
+ public:
+ typedef base::Callback<int(void)> NextRoutingIDCallback;
+
+ // |next_routing_id| is owned by this object. It can be used up until
+ // OnChannelClosing.
+ explicit MessagePortMessageFilter(const NextRoutingIDCallback& callback);
+
+ // BrowserMessageFilter implementation.
+ virtual void OnChannelClosing() OVERRIDE;
+ virtual bool OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) OVERRIDE;
+ int GetNextRoutingID();
+
+ private:
+ virtual ~MessagePortMessageFilter();
+
+ // Message handlers.
+ void OnCreateMessagePort(int* route_id, int* message_port_id);
+
+ // This is guaranteed to be valid until OnChannelClosing is invoked, and it's
+ // not used after.
+ NextRoutingIDCallback next_routing_id_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortMessageFilter);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_WORKER_MESSAGE_FILTER_H_
diff --git a/content/browser/worker_host/message_port_service.cc b/content/browser/message_port_service.cc
index 3bc8f5a..bc2a1ac 100644
--- a/content/browser/worker_host/message_port_service.cc
+++ b/content/browser/message_port_service.cc
@@ -1,11 +1,11 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/worker_host/message_port_service.h"
+#include "content/browser/message_port_service.h"
-#include "content/browser/worker_host/worker_message_filter.h"
-#include "content/common/worker_messages.h"
+#include "content/browser/message_port_message_filter.h"
+#include "content/common/message_port_messages.h"
namespace content {
@@ -13,7 +13,7 @@ struct MessagePortService::MessagePort {
// |filter| and |route_id| are what we need to send messages to the port.
// |filter| is just a weak pointer since we get notified when its process has
// gone away and remove it.
- WorkerMessageFilter* filter;
+ MessagePortMessageFilter* filter;
int route_id;
// A globally unique id for this message port.
int message_port_id;
@@ -26,7 +26,7 @@ struct MessagePortService::MessagePort {
// in-flight. This flag ensures that the latter type get flushed through the
// system.
// This flag should only be set to true in response to
- // WorkerProcessHostMsg_QueueMessages.
+ // MessagePortHostMsg_QueueMessages.
bool queue_messages;
QueuedMessages queued_messages;
};
@@ -44,7 +44,7 @@ MessagePortService::~MessagePortService() {
void MessagePortService::UpdateMessagePort(
int message_port_id,
- WorkerMessageFilter* filter,
+ MessagePortMessageFilter* filter,
int routing_id) {
if (!message_ports_.count(message_port_id)) {
NOTREACHED();
@@ -56,8 +56,8 @@ void MessagePortService::UpdateMessagePort(
port.route_id = routing_id;
}
-void MessagePortService::OnWorkerMessageFilterClosing(
- WorkerMessageFilter* filter) {
+void MessagePortService::OnMessagePortMessageFilterClosing(
+ MessagePortMessageFilter* filter) {
// Check if the (possibly) crashed process had any message ports.
for (MessagePorts::iterator iter = message_ports_.begin();
iter != message_ports_.end();) {
@@ -69,7 +69,7 @@ void MessagePortService::OnWorkerMessageFilterClosing(
}
void MessagePortService::Create(int route_id,
- WorkerMessageFilter* filter,
+ MessagePortMessageFilter* filter,
int* message_port_id) {
*message_port_id = ++next_message_port_id_;
@@ -173,7 +173,7 @@ void MessagePortService::PostMessageTo(
}
// Now send the message to the entangled port.
- entangled_port.filter->Send(new WorkerProcessMsg_Message(
+ entangled_port.filter->Send(new MessagePortMsg_Message(
entangled_port.route_id, message, sent_message_port_ids,
new_routing_ids));
}
@@ -186,7 +186,7 @@ void MessagePortService::QueueMessages(int message_port_id) {
MessagePort& port = message_ports_[message_port_id];
if (port.filter) {
- port.filter->Send(new WorkerProcessMsg_MessagesQueued(port.route_id));
+ port.filter->Send(new MessagePortMsg_MessagesQueued(port.route_id));
port.queue_messages = true;
port.filter = NULL;
}
diff --git a/content/browser/worker_host/message_port_service.h b/content/browser/message_port_service.h
index b85e76b..55e536c 100644
--- a/content/browser/worker_host/message_port_service.h
+++ b/content/browser/message_port_service.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_BROWSER_WORKER_HOST_MESSAGE_PORT_SERVICE_H_
-#define CONTENT_BROWSER_WORKER_HOST_MESSAGE_PORT_SERVICE_H_
+#ifndef CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_
+#define CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_
#include <map>
#include <utility>
@@ -15,7 +15,7 @@
#include "ipc/ipc_message.h"
namespace content {
-class WorkerMessageFilter;
+class MessagePortMessageFilter;
class MessagePortService {
public:
@@ -25,7 +25,9 @@ class MessagePortService {
static MessagePortService* GetInstance();
// These methods correspond to the message port related IPCs.
- void Create(int route_id, WorkerMessageFilter* filter, int* message_port_id);
+ void Create(int route_id,
+ MessagePortMessageFilter* filter,
+ int* message_port_id);
void Destroy(int message_port_id);
void Entangle(int local_message_port_id, int remote_message_port_id);
void PostMessage(int sender_message_port_id,
@@ -39,10 +41,10 @@ class MessagePortService {
// (possibly different) process.
void UpdateMessagePort(
int message_port_id,
- WorkerMessageFilter* filter,
+ MessagePortMessageFilter* filter,
int routing_id);
- void OnWorkerMessageFilterClosing(WorkerMessageFilter* filter);
+ void OnMessagePortMessageFilterClosing(MessagePortMessageFilter* filter);
// Attempts to send the queued messages for a message port.
void SendQueuedMessagesIfPossible(int message_port_id);
@@ -73,4 +75,4 @@ class MessagePortService {
} // namespace content
-#endif // CONTENT_BROWSER_WORKER_HOST_MESSAGE_PORT_SERVICE_H_
+#endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 49ed5df..f6e3ed0 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -63,6 +63,7 @@
#include "content/browser/loader/resource_scheduler_filter.h"
#include "content/browser/media/android/browser_demuxer_android.h"
#include "content/browser/media/media_internals.h"
+#include "content/browser/message_port_message_filter.h"
#include "content/browser/mime_registry_message_filter.h"
#include "content/browser/plugin_service_impl.h"
#include "content/browser/profiler_message_filter.h"
@@ -673,6 +674,11 @@ void RenderProcessHostImpl::CreateMessageFilters() {
GetID(), request_context_callback, resource_context);
AddFilter(socket_stream_dispatcher_host);
+ message_port_message_filter_ = new MessagePortMessageFilter(
+ base::Bind(&RenderWidgetHelper::GetNextRoutingID,
+ base::Unretained(widget_helper_.get())));
+ AddFilter(message_port_message_filter_);
+
AddFilter(new WorkerMessageFilter(
GetID(),
resource_context,
@@ -684,8 +690,7 @@ void RenderProcessHostImpl::CreateMessageFilters() {
storage_partition_impl_->GetFileSystemContext(),
storage_partition_impl_->GetDatabaseTracker(),
storage_partition_impl_->GetIndexedDBContext()),
- base::Bind(&RenderWidgetHelper::GetNextRoutingID,
- base::Unretained(widget_helper_.get()))));
+ message_port_message_filter_));
#if defined(ENABLE_WEBRTC)
AddFilter(new P2PSocketDispatcherHost(
@@ -1340,6 +1345,7 @@ void RenderProcessHostImpl::Cleanup() {
// OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread.
channel_.reset();
gpu_message_filter_ = NULL;
+ message_port_message_filter_ = NULL;
// Remove ourself from the list of renderer processes so that we can't be
// reused in between now and when the Delete task runs.
@@ -1638,6 +1644,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) {
child_process_launcher_.reset();
channel_.reset();
gpu_message_filter_ = NULL;
+ message_port_message_filter_ = NULL;
IDMap<IPC::Listener>::iterator iter(&listeners_);
while (!iter.IsAtEnd()) {
diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h
index 567b629b..1287b2e 100644
--- a/content/browser/renderer_host/render_process_host_impl.h
+++ b/content/browser/renderer_host/render_process_host_impl.h
@@ -35,6 +35,7 @@ class Size;
namespace content {
class BrowserDemuxerAndroid;
class GpuMessageFilter;
+class MessagePortMessageFilter;
class PeerConnectionTrackerHost;
class RendererMainThread;
class RenderWidgetHelper;
@@ -260,6 +261,9 @@ class CONTENT_EXPORT RenderProcessHostImpl
// it's valid if non-NULL.
GpuMessageFilter* gpu_message_filter_;
+ // The filter for MessagePort messages coming from the renderer.
+ scoped_refptr<MessagePortMessageFilter> message_port_message_filter_;
+
// A map of transport DIB ids to cached TransportDIBs
std::map<TransportDIB::Id, TransportDIB*> cached_dibs_;
diff --git a/content/browser/worker_host/worker_message_filter.cc b/content/browser/worker_host/worker_message_filter.cc
index 6631de3..49fe7f6 100644
--- a/content/browser/worker_host/worker_message_filter.cc
+++ b/content/browser/worker_host/worker_message_filter.cc
@@ -4,7 +4,7 @@
#include "content/browser/worker_host/worker_message_filter.h"
-#include "content/browser/worker_host/message_port_service.h"
+#include "content/browser/message_port_message_filter.h"
#include "content/browser/worker_host/worker_service_impl.h"
#include "content/common/view_messages.h"
#include "content/common/worker_messages.h"
@@ -16,11 +16,11 @@ WorkerMessageFilter::WorkerMessageFilter(
int render_process_id,
ResourceContext* resource_context,
const WorkerStoragePartition& partition,
- const NextRoutingIDCallback& callback)
+ MessagePortMessageFilter* message_port_message_filter)
: render_process_id_(render_process_id),
resource_context_(resource_context),
partition_(partition),
- next_routing_id_(callback) {
+ message_port_message_filter_(message_port_message_filter) {
// Note: This constructor is called on both IO or UI thread.
DCHECK(resource_context);
}
@@ -30,7 +30,6 @@ WorkerMessageFilter::~WorkerMessageFilter() {
}
void WorkerMessageFilter::OnChannelClosing() {
- MessagePortService::GetInstance()->OnWorkerMessageFilterClosing(this);
WorkerServiceImpl::GetInstance()->OnWorkerMessageFilterClosing(this);
}
@@ -46,24 +45,6 @@ bool WorkerMessageFilter::OnMessageReceived(const IPC::Message& message,
IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardToWorker, OnForwardToWorker)
// Only sent from renderer.
IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentDetached, OnDocumentDetached)
- // Message Port related messages.
- IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_CreateMessagePort,
- OnCreateMessagePort)
- IPC_MESSAGE_FORWARD(WorkerProcessHostMsg_DestroyMessagePort,
- MessagePortService::GetInstance(),
- MessagePortService::Destroy)
- IPC_MESSAGE_FORWARD(WorkerProcessHostMsg_Entangle,
- MessagePortService::GetInstance(),
- MessagePortService::Entangle)
- IPC_MESSAGE_FORWARD(WorkerProcessHostMsg_PostMessage,
- MessagePortService::GetInstance(),
- MessagePortService::PostMessage)
- IPC_MESSAGE_FORWARD(WorkerProcessHostMsg_QueueMessages,
- MessagePortService::GetInstance(),
- MessagePortService::QueueMessages)
- IPC_MESSAGE_FORWARD(WorkerProcessHostMsg_SendQueuedMessages,
- MessagePortService::GetInstance(),
- MessagePortService::SendQueuedMessages)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
@@ -71,14 +52,14 @@ bool WorkerMessageFilter::OnMessageReceived(const IPC::Message& message,
}
int WorkerMessageFilter::GetNextRoutingID() {
- return next_routing_id_.Run();
+ return message_port_message_filter_->GetNextRoutingID();
}
void WorkerMessageFilter::OnCreateWorker(
const ViewHostMsg_CreateWorker_Params& params,
int* route_id) {
*route_id = params.route_id != MSG_ROUTING_NONE ?
- params.route_id : next_routing_id_.Run();
+ params.route_id : GetNextRoutingID();
WorkerServiceImpl::GetInstance()->CreateWorker(
params, *route_id, this, resource_context_, partition_);
}
@@ -88,7 +69,7 @@ void WorkerMessageFilter::OnLookupSharedWorker(
bool* exists,
int* route_id,
bool* url_error) {
- *route_id = next_routing_id_.Run();
+ *route_id = GetNextRoutingID();
WorkerServiceImpl::GetInstance()->LookupSharedWorker(
params, *route_id, this, resource_context_, partition_, exists,
@@ -103,10 +84,4 @@ void WorkerMessageFilter::OnDocumentDetached(unsigned long long document_id) {
WorkerServiceImpl::GetInstance()->DocumentDetached(document_id, this);
}
-void WorkerMessageFilter::OnCreateMessagePort(int *route_id,
- int* message_port_id) {
- *route_id = next_routing_id_.Run();
- MessagePortService::GetInstance()->Create(*route_id, this, message_port_id);
-}
-
} // namespace content
diff --git a/content/browser/worker_host/worker_message_filter.h b/content/browser/worker_host/worker_message_filter.h
index 47f96ef..0d495fa 100644
--- a/content/browser/worker_host/worker_message_filter.h
+++ b/content/browser/worker_host/worker_message_filter.h
@@ -13,18 +13,15 @@ class ResourceDispatcherHost;
struct ViewHostMsg_CreateWorker_Params;
namespace content {
+class MessagePortMessageFilter;
class ResourceContext;
class WorkerMessageFilter : public BrowserMessageFilter {
public:
- typedef base::Callback<int(void)> NextRoutingIDCallback;
-
- // |next_routing_id| is owned by this object. It can be used up until
- // OnChannelClosing.
WorkerMessageFilter(int render_process_id,
ResourceContext* resource_context,
const WorkerStoragePartition& partition,
- const NextRoutingIDCallback& callback);
+ MessagePortMessageFilter* message_port_filter);
// BrowserMessageFilter implementation.
virtual void OnChannelClosing() OVERRIDE;
@@ -34,6 +31,10 @@ class WorkerMessageFilter : public BrowserMessageFilter {
int GetNextRoutingID();
int render_process_id() const { return render_process_id_; }
+ MessagePortMessageFilter* message_port_message_filter() const {
+ return message_port_message_filter_;
+ }
+
private:
virtual ~WorkerMessageFilter();
@@ -52,10 +53,7 @@ class WorkerMessageFilter : public BrowserMessageFilter {
ResourceContext* const resource_context_;
WorkerStoragePartition partition_;
- // This is guaranteed to be valid until OnChannelClosing is closed, and it's
- // not used after.
- NextRoutingIDCallback next_routing_id_;
-
+ MessagePortMessageFilter* message_port_message_filter_;
DISALLOW_IMPLICIT_CONSTRUCTORS(WorkerMessageFilter);
};
diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc
index f0324d7..b132767 100644
--- a/content/browser/worker_host/worker_process_host.cc
+++ b/content/browser/worker_host/worker_process_host.cc
@@ -25,6 +25,8 @@
#include "content/browser/fileapi/fileapi_message_filter.h"
#include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
#include "content/browser/loader/resource_message_filter.h"
+#include "content/browser/message_port_message_filter.h"
+#include "content/browser/message_port_service.h"
#include "content/browser/mime_registry_message_filter.h"
#include "content/browser/quota_dispatcher_host.h"
#include "content/browser/renderer_host/database_message_filter.h"
@@ -33,7 +35,6 @@
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/socket_stream_dispatcher_host.h"
#include "content/browser/resource_context_impl.h"
-#include "content/browser/worker_host/message_port_service.h"
#include "content/browser/worker_host/worker_message_filter.h"
#include "content/browser/worker_host/worker_service_impl.h"
#include "content/common/child_process_host_impl.h"
@@ -223,10 +224,15 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) {
get_contexts_callback);
process_->AddFilter(resource_message_filter);
- worker_message_filter_ = new WorkerMessageFilter(
- render_process_id, resource_context_, partition_,
- base::Bind(&WorkerServiceImpl::next_worker_route_id,
- base::Unretained(WorkerServiceImpl::GetInstance())));
+ MessagePortMessageFilter* message_port_message_filter =
+ new MessagePortMessageFilter(
+ base::Bind(&WorkerServiceImpl::next_worker_route_id,
+ base::Unretained(WorkerServiceImpl::GetInstance())));
+ process_->AddFilter(message_port_message_filter);
+ worker_message_filter_ = new WorkerMessageFilter(render_process_id,
+ resource_context_,
+ partition_,
+ message_port_message_filter);
process_->AddFilter(worker_message_filter_.get());
process_->AddFilter(new AppCacheDispatcherHost(
partition_.appcache_service(), process_->GetData().id));
@@ -400,7 +406,9 @@ void WorkerProcessHost::RelayMessage(
}
new_routing_id = filter->GetNextRoutingID();
MessagePortService::GetInstance()->UpdateMessagePort(
- sent_message_port_id, filter, new_routing_id);
+ sent_message_port_id,
+ filter->message_port_message_filter(),
+ new_routing_id);
// Resend the message with the new routing id.
filter->Send(new WorkerMsg_Connect(
diff --git a/content/child/webmessageportchannel_impl.cc b/content/child/webmessageportchannel_impl.cc
index ed621ad..de8866f 100644
--- a/content/child/webmessageportchannel_impl.cc
+++ b/content/child/webmessageportchannel_impl.cc
@@ -8,7 +8,7 @@
#include "base/message_loop/message_loop_proxy.h"
#include "content/child/child_process.h"
#include "content/child/child_thread.h"
-#include "content/common/worker_messages.h"
+#include "content/common/message_port_messages.h"
#include "third_party/WebKit/public/platform/WebMessagePortChannelClient.h"
#include "third_party/WebKit/public/platform/WebString.h"
@@ -53,7 +53,7 @@ WebMessagePortChannelImpl::~WebMessagePortChannelImpl() {
}
if (message_port_id_ != MSG_ROUTING_NONE)
- Send(new WorkerProcessHostMsg_DestroyMessagePort(message_port_id_));
+ Send(new MessagePortHostMsg_DestroyMessagePort(message_port_id_));
if (route_id_ != MSG_ROUTING_NONE)
ChildThread::current()->RemoveRoute(route_id_);
@@ -106,7 +106,7 @@ void WebMessagePortChannelImpl::postMessage(
delete channels;
}
- IPC::Message* msg = new WorkerProcessHostMsg_PostMessage(
+ IPC::Message* msg = new MessagePortHostMsg_PostMessage(
message_port_id_, message, message_port_ids);
Send(msg);
}
@@ -140,7 +140,7 @@ void WebMessagePortChannelImpl::Init() {
if (route_id_ == MSG_ROUTING_NONE) {
DCHECK(message_port_id_ == MSG_ROUTING_NONE);
- Send(new WorkerProcessHostMsg_CreateMessagePort(
+ Send(new MessagePortHostMsg_CreateMessagePort(
&route_id_, &message_port_id_));
}
@@ -156,7 +156,7 @@ void WebMessagePortChannelImpl::Entangle(
return;
}
- Send(new WorkerProcessHostMsg_Entangle(
+ Send(new MessagePortHostMsg_Entangle(
message_port_id_, channel->message_port_id()));
}
@@ -172,7 +172,7 @@ void WebMessagePortChannelImpl::QueueMessages() {
// sends us an ack, whose receipt we know means that no more messages are
// in-flight. We then send the queued messages to the browser, which prepends
// them to the ones it queued and it sends them to the new endpoint.
- Send(new WorkerProcessHostMsg_QueueMessages(message_port_id_));
+ Send(new MessagePortHostMsg_QueueMessages(message_port_id_));
// The process could potentially go away while we're still waiting for
// in-flight messages. Ensure it stays alive.
@@ -194,8 +194,8 @@ void WebMessagePortChannelImpl::Send(IPC::Message* message) {
bool WebMessagePortChannelImpl::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WebMessagePortChannelImpl, message)
- IPC_MESSAGE_HANDLER(WorkerProcessMsg_Message, OnMessage)
- IPC_MESSAGE_HANDLER(WorkerProcessMsg_MessagesQueued, OnMessagesQueued)
+ IPC_MESSAGE_HANDLER(MessagePortMsg_Message, OnMessage)
+ IPC_MESSAGE_HANDLER(MessagePortMsg_MessagesQueued, OnMessagesQueued)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -243,7 +243,7 @@ void WebMessagePortChannelImpl::OnMessagesQueued() {
}
}
- Send(new WorkerProcessHostMsg_SendQueuedMessages(
+ Send(new MessagePortHostMsg_SendQueuedMessages(
message_port_id_, queued_messages));
message_port_id_ = MSG_ROUTING_NONE;
diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h
index d85d4eb..78e7c53 100644
--- a/content/common/content_message_generator.h
+++ b/content/common/content_message_generator.h
@@ -40,6 +40,7 @@
#include "content/common/media/video_capture_messages.h"
#include "content/common/media/webrtc_identity_messages.h"
#include "content/common/memory_benchmark_messages.h"
+#include "content/common/message_port_messages.h"
#include "content/common/mime_registry_messages.h"
#include "content/common/p2p_messages.h"
#include "content/common/pepper_messages.h"
diff --git a/content/common/message_port_messages.h b/content/common/message_port_messages.h
new file mode 100644
index 0000000..67b729d
--- /dev/null
+++ b/content/common/message_port_messages.h
@@ -0,0 +1,85 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Defines messages between the browser and worker process, as well as between
+// the renderer and worker process.
+
+// Multiply-included message file, hence no include guard.
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/strings/string16.h"
+#include "content/common/content_export.h"
+#include "ipc/ipc_message_macros.h"
+#include "ipc/ipc_message_utils.h"
+
+#undef IPC_MESSAGE_EXPORT
+#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
+#define IPC_MESSAGE_START MessagePortMsgStart
+
+// Singly-included section, not converted.
+#ifndef CONTENT_COMMON_MESSAGE_PORT_MESSAGES_H_
+#define CONTENT_COMMON_MESSAGE_PORT_MESSAGES_H_
+
+typedef std::pair<string16, std::vector<int> > QueuedMessage;
+
+#endif // CONTENT_COMMON_MESSAGE_PORT_MESSAGES_H_
+
+//-----------------------------------------------------------------------------
+// MessagePort messages
+// These are messages sent from the browser to child processes.
+
+// Sends a message to a message port.
+IPC_MESSAGE_ROUTED3(MessagePortMsg_Message,
+ string16 /* message */,
+ 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.
+IPC_MESSAGE_ROUTED0(MessagePortMsg_MessagesQueued)
+
+//-----------------------------------------------------------------------------
+// MessagePortHost messages
+// These are messages sent from child processes to the browser.
+
+// Creates a new Message Port Channel object. The first paramaeter is the
+// message port channel's routing id in this process. The second parameter
+// is the process-wide-unique identifier for that port.
+IPC_SYNC_MESSAGE_CONTROL0_2(MessagePortHostMsg_CreateMessagePort,
+ int /* route_id */,
+ int /* message_port_id */)
+
+// Sent when a Message Port Channel object is destroyed.
+IPC_MESSAGE_CONTROL1(MessagePortHostMsg_DestroyMessagePort,
+ int /* message_port_id */)
+
+// Sends a message to a message port. Optionally sends a message port as
+// as well if sent_message_port_id != MSG_ROUTING_NONE.
+IPC_MESSAGE_CONTROL3(MessagePortHostMsg_PostMessage,
+ int /* sender_message_port_id */,
+ string16 /* message */,
+ std::vector<int> /* sent_message_port_ids */)
+
+// Causes messages sent to the remote port to be delivered to this local port.
+IPC_MESSAGE_CONTROL2(MessagePortHostMsg_Entangle,
+ int /* local_message_port_id */,
+ int /* remote_message_port_id */)
+
+// Causes the browser to queue messages sent to this port until the the port
+// has made sure that all in-flight messages were routed to the new
+// destination.
+IPC_MESSAGE_CONTROL1(MessagePortHostMsg_QueueMessages,
+ int /* message_port_id */)
+
+// Sends the browser all the queued messages that arrived at this message port
+// after it was sent in a postMessage call.
+// NOTE: MSVS can't compile the macro if std::vector<std::pair<string16, int> >
+// is used, so we typedef it in worker_messages.h.
+IPC_MESSAGE_CONTROL2(MessagePortHostMsg_SendQueuedMessages,
+ int /* message_port_id */,
+ std::vector<QueuedMessage> /* queued_messages */)
diff --git a/content/common/worker_messages.h b/content/common/worker_messages.h
index 3f32862..d66e456 100644
--- a/content/common/worker_messages.h
+++ b/content/common/worker_messages.h
@@ -19,14 +19,6 @@
#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
#include "url/gurl.h"
-// Singly-included section, not converted.
-#ifndef CONTENT_COMMON_WORKER_MESSAGES_H_
-#define CONTENT_COMMON_WORKER_MESSAGES_H_
-
-typedef std::pair<string16, std::vector<int> > QueuedMessage;
-
-#endif // CONTENT_COMMON_WORKER_MESSAGES_H_
-
#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
#define IPC_MESSAGE_START WorkerMsgStart
@@ -61,64 +53,10 @@ IPC_ENUM_TRAITS(WebKit::WebContentSecurityPolicyType)
IPC_MESSAGE_CONTROL1(WorkerProcessMsg_CreateWorker,
WorkerProcessMsg_CreateWorker_Params)
-// Note: these Message Port related messages can also be sent to the
-// renderer process. Putting them here since we don't have a shared place
-// like common_messages_internal.h
-IPC_MESSAGE_ROUTED3(WorkerProcessMsg_Message,
- string16 /* message */,
- 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.
-IPC_MESSAGE_ROUTED0(WorkerProcessMsg_MessagesQueued)
-
-
//-----------------------------------------------------------------------------
// WorkerProcessHost messages
// These are messages sent from the worker process to the browser process.
-// Note: these Message Port related messages can also be sent out from the
-// renderer process. Putting them here since we don't have a shared place
-// like common_messages_internal.h
-
-// Creates a new Message Port Channel object. The first paramaeter is the
-// message port channel's routing id in this process. The second parameter
-// is the process-wide-unique identifier for that port.
-IPC_SYNC_MESSAGE_CONTROL0_2(WorkerProcessHostMsg_CreateMessagePort,
- int /* route_id */,
- int /* message_port_id */)
-
-// Sent when a Message Port Channel object is destroyed.
-IPC_MESSAGE_CONTROL1(WorkerProcessHostMsg_DestroyMessagePort,
- int /* message_port_id */)
-
-// Sends a message to a message port. Optionally sends a message port as
-// as well if sent_message_port_id != MSG_ROUTING_NONE.
-IPC_MESSAGE_CONTROL3(WorkerProcessHostMsg_PostMessage,
- int /* sender_message_port_id */,
- string16 /* message */,
- 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,
- int /* local_message_port_id */,
- int /* remote_message_port_id */)
-
-// Causes the browser to queue messages sent to this port until the the port
-// has made sure that all in-flight messages were routed to the new
-// destination.
-IPC_MESSAGE_CONTROL1(WorkerProcessHostMsg_QueueMessages,
- int /* message_port_id */)
-
-// Sends the browser all the queued messages that arrived at this message port
-// after it was sent in a postMessage call.
-// NOTE: MSVS can't compile the macro if std::vector<std::pair<string16, int> >
-// is used, so we typedef it in worker_messages.h.
-IPC_MESSAGE_CONTROL2(WorkerProcessHostMsg_SendQueuedMessages,
- int /* message_port_id */,
- std::vector<QueuedMessage> /* queued_messages */)
-
// Sent by the worker process to check whether access to web databases is
// allowed.
IPC_SYNC_MESSAGE_CONTROL5_1(WorkerProcessHostMsg_AllowDatabase,
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 38e92d6..dffcb74 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -721,6 +721,10 @@
'browser/media/webrtc_internals_ui.h',
'browser/media/webrtc_internals_ui_observer.h',
'browser/media_devices_monitor.cc',
+ 'browser/message_port_message_filter.cc',
+ 'browser/message_port_message_filter.h',
+ 'browser/message_port_service.cc',
+ 'browser/message_port_service.h',
'browser/mime_registry_message_filter.cc',
'browser/mime_registry_message_filter.h',
'browser/service_worker/service_worker_dispatcher_host.h',
@@ -1209,8 +1213,6 @@
'browser/webui/web_ui_impl.cc',
'browser/webui/web_ui_impl.h',
'browser/webui/web_ui_message_handler.cc',
- 'browser/worker_host/message_port_service.cc',
- 'browser/worker_host/message_port_service.h',
'browser/worker_host/worker_document_set.cc',
'browser/worker_host/worker_document_set.h',
'browser/worker_host/worker_message_filter.cc',
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 9c70800..cb3b2c5 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -295,6 +295,7 @@
'common/media/video_capture_messages.h',
'common/media/webrtc_identity_messages.h',
'common/memory_benchmark_messages.h',
+ 'common/message_port_messages.h',
'common/message_router.cc',
'common/message_router.h',
'common/mime_registry_messages.h',
diff --git a/ipc/ipc_message_start.h b/ipc/ipc_message_start.h
index e71755f..7ce2bdd 100644
--- a/ipc/ipc_message_start.h
+++ b/ipc/ipc_message_start.h
@@ -91,6 +91,7 @@ enum IPCMessageStart {
PowerMonitorMsgStart,
EncryptedMediaMsgStart,
ServiceWorkerMsgStart,
+ MessagePortMsgStart,
LastIPCMsgStart // Must come last.
};