1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/message_port_message_filter.h"
7 #include "content/browser/message_port_service.h"
8 #include "content/common/message_port_messages.h"
12 MessagePortMessageFilter::MessagePortMessageFilter(
13 const NextRoutingIDCallback& callback)
14 : next_routing_id_(callback) {
17 MessagePortMessageFilter::~MessagePortMessageFilter() {
20 void MessagePortMessageFilter::OnChannelClosing() {
21 MessagePortService::GetInstance()->OnMessagePortMessageFilterClosing(this);
24 bool MessagePortMessageFilter::OnMessageReceived(const IPC::Message& message,
25 bool* message_was_ok) {
27 IPC_BEGIN_MESSAGE_MAP_EX(MessagePortMessageFilter, message, *message_was_ok)
28 IPC_MESSAGE_HANDLER(MessagePortHostMsg_CreateMessagePort,
30 IPC_MESSAGE_FORWARD(MessagePortHostMsg_DestroyMessagePort,
31 MessagePortService::GetInstance(),
32 MessagePortService::Destroy)
33 IPC_MESSAGE_FORWARD(MessagePortHostMsg_Entangle,
34 MessagePortService::GetInstance(),
35 MessagePortService::Entangle)
36 IPC_MESSAGE_FORWARD(MessagePortHostMsg_PostMessage,
37 MessagePortService::GetInstance(),
38 MessagePortService::PostMessage)
39 IPC_MESSAGE_FORWARD(MessagePortHostMsg_QueueMessages,
40 MessagePortService::GetInstance(),
41 MessagePortService::QueueMessages)
42 IPC_MESSAGE_FORWARD(MessagePortHostMsg_SendQueuedMessages,
43 MessagePortService::GetInstance(),
44 MessagePortService::SendQueuedMessages)
45 IPC_MESSAGE_UNHANDLED(handled = false)
46 IPC_END_MESSAGE_MAP_EX()
51 void MessagePortMessageFilter::OnDestruct() const {
52 BrowserThread::DeleteOnIOThread::Destruct(this);
55 int MessagePortMessageFilter::GetNextRoutingID() {
56 return next_routing_id_.Run();
59 void MessagePortMessageFilter::OnCreateMessagePort(int *route_id,
60 int* message_port_id) {
61 *route_id = next_routing_id_.Run();
62 MessagePortService::GetInstance()->Create(*route_id, this, message_port_id);
65 } // namespace content