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 : BrowserMessageFilter(MessagePortMsgStart
),
15 next_routing_id_(callback
) {
18 MessagePortMessageFilter::~MessagePortMessageFilter() {
21 void MessagePortMessageFilter::OnChannelClosing() {
22 MessagePortService::GetInstance()->OnMessagePortMessageFilterClosing(this);
25 bool MessagePortMessageFilter::OnMessageReceived(const IPC::Message
& message
) {
27 IPC_BEGIN_MESSAGE_MAP(MessagePortMessageFilter
, message
)
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)
51 void MessagePortMessageFilter::OnDestruct() const {
52 BrowserThread::DeleteOnIOThread::Destruct(this);
55 int MessagePortMessageFilter::GetNextRoutingID() {
56 return next_routing_id_
.Run();
59 void MessagePortMessageFilter::UpdateMessagePortsWithNewRoutes(
60 const std::vector
<int>& message_port_ids
,
61 std::vector
<int>* new_routing_ids
) {
62 DCHECK(new_routing_ids
);
63 new_routing_ids
->clear();
64 new_routing_ids
->resize(message_port_ids
.size());
66 for (size_t i
= 0; i
< message_port_ids
.size(); ++i
) {
67 (*new_routing_ids
)[i
] = GetNextRoutingID();
68 MessagePortService::GetInstance()->UpdateMessagePort(
71 (*new_routing_ids
)[i
]);
75 void MessagePortMessageFilter::OnCreateMessagePort(int *route_id
,
76 int* message_port_id
) {
77 *route_id
= next_routing_id_
.Run();
78 MessagePortService::GetInstance()->Create(*route_id
, this, message_port_id
);
81 } // namespace content