Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/message_port_message_filter.h" | 5 #include "content/browser/message_port_message_filter.h" |
| 6 | 6 |
| 7 #include "content/browser/message_port_service.h" | 7 #include "content/browser/message_port_service.h" |
| 8 #include "content/common/message_port_messages.h" | 8 #include "content/common/message_port_messages.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 MessagePortMessageFilter::MessagePortMessageFilter( | 12 MessagePortMessageFilter::MessagePortMessageFilter( |
| 13 const NextRoutingIDCallback& callback) | 13 const NextRoutingIDCallback& callback) |
| 14 : BrowserMessageFilter(MessagePortMsgStart), | 14 : BrowserMessageFilter(MessagePortMsgStart), |
| 15 next_routing_id_(callback) { | 15 next_routing_id_(callback) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 MessagePortMessageFilter::~MessagePortMessageFilter() { | 18 MessagePortMessageFilter::~MessagePortMessageFilter() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 void MessagePortMessageFilter::OnChannelClosing() { | 21 void MessagePortMessageFilter::OnChannelClosing() { |
| 22 MessagePortService::GetInstance()->OnMessagePortMessageFilterClosing(this); | 22 MessagePortService::GetInstance()->OnMessagePortDelegateClosing(this); |
| 23 } | 23 } |
| 24 | 24 |
| 25 bool MessagePortMessageFilter::OnMessageReceived(const IPC::Message& message) { | 25 bool MessagePortMessageFilter::OnMessageReceived(const IPC::Message& message) { |
| 26 bool handled = true; | 26 bool handled = true; |
| 27 IPC_BEGIN_MESSAGE_MAP(MessagePortMessageFilter, message) | 27 IPC_BEGIN_MESSAGE_MAP(MessagePortMessageFilter, message) |
| 28 IPC_MESSAGE_HANDLER(MessagePortHostMsg_CreateMessagePort, | 28 IPC_MESSAGE_HANDLER(MessagePortHostMsg_CreateMessagePort, |
| 29 OnCreateMessagePort) | 29 OnCreateMessagePort) |
| 30 IPC_MESSAGE_FORWARD(MessagePortHostMsg_DestroyMessagePort, | 30 IPC_MESSAGE_FORWARD(MessagePortHostMsg_DestroyMessagePort, |
| 31 MessagePortService::GetInstance(), | 31 MessagePortService::GetInstance(), |
| 32 MessagePortService::Destroy) | 32 MessagePortService::Destroy) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 52 } | 52 } |
| 53 | 53 |
| 54 void MessagePortMessageFilter::OnDestruct() const { | 54 void MessagePortMessageFilter::OnDestruct() const { |
| 55 BrowserThread::DeleteOnIOThread::Destruct(this); | 55 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 56 } | 56 } |
| 57 | 57 |
| 58 int MessagePortMessageFilter::GetNextRoutingID() { | 58 int MessagePortMessageFilter::GetNextRoutingID() { |
| 59 return next_routing_id_.Run(); | 59 return next_routing_id_.Run(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void MessagePortMessageFilter::SendMessage( | |
| 63 int route_id, | |
| 64 const base::string16& message, | |
| 65 const std::vector<int>& sent_message_port_ids) { | |
| 66 // If a message port was sent around, the new location will need a routing | |
|
scheib
2014/12/18 00:24:10
This code block is more indirect now that a nestin
Marijn Kruisselbrink
2014/12/19 00:09:21
Okay, slightly rephrased the comment.
| |
| 67 // id. Instead of having the created port send us a sync message to get it, | |
| 68 // send along with the message. | |
| 69 std::vector<int> new_routing_ids; | |
| 70 UpdateMessagePortsWithNewRoutes(sent_message_port_ids, &new_routing_ids); | |
| 71 Send(new MessagePortMsg_Message(route_id, message, sent_message_port_ids, | |
| 72 new_routing_ids)); | |
| 73 } | |
| 74 | |
| 75 void MessagePortMessageFilter::SendMessagesAreQueued(int route_id) { | |
| 76 Send(new MessagePortMsg_MessagesQueued(route_id)); | |
| 77 } | |
| 78 | |
| 62 void MessagePortMessageFilter::UpdateMessagePortsWithNewRoutes( | 79 void MessagePortMessageFilter::UpdateMessagePortsWithNewRoutes( |
| 63 const std::vector<int>& message_port_ids, | 80 const std::vector<int>& message_port_ids, |
| 64 std::vector<int>* new_routing_ids) { | 81 std::vector<int>* new_routing_ids) { |
| 65 DCHECK(new_routing_ids); | 82 DCHECK(new_routing_ids); |
| 66 new_routing_ids->clear(); | 83 new_routing_ids->clear(); |
| 67 new_routing_ids->resize(message_port_ids.size()); | 84 new_routing_ids->resize(message_port_ids.size()); |
| 68 | 85 |
| 69 for (size_t i = 0; i < message_port_ids.size(); ++i) { | 86 for (size_t i = 0; i < message_port_ids.size(); ++i) { |
| 70 (*new_routing_ids)[i] = GetNextRoutingID(); | 87 (*new_routing_ids)[i] = GetNextRoutingID(); |
| 71 MessagePortService::GetInstance()->UpdateMessagePort( | 88 MessagePortService::GetInstance()->UpdateMessagePort( |
| 72 message_port_ids[i], | 89 message_port_ids[i], |
| 73 this, | 90 this, |
| 74 (*new_routing_ids)[i]); | 91 (*new_routing_ids)[i]); |
| 75 } | 92 } |
| 76 } | 93 } |
| 77 | 94 |
| 78 void MessagePortMessageFilter::OnCreateMessagePort(int *route_id, | 95 void MessagePortMessageFilter::OnCreateMessagePort(int *route_id, |
| 79 int* message_port_id) { | 96 int* message_port_id) { |
| 80 *route_id = next_routing_id_.Run(); | 97 *route_id = next_routing_id_.Run(); |
| 81 MessagePortService::GetInstance()->Create(*route_id, this, message_port_id); | 98 MessagePortService::GetInstance()->Create(*route_id, this, message_port_id); |
| 82 } | 99 } |
| 83 | 100 |
| 84 } // namespace content | 101 } // namespace content |
| OLD | NEW |