Chromium Code Reviews| Index: content/child/webmessageportchannel_impl.cc |
| diff --git a/content/child/webmessageportchannel_impl.cc b/content/child/webmessageportchannel_impl.cc |
| index cf439cc0742851de8270d70f228bf20b1e86f20c..dc5a50120de0e76a360c64caecd59f24acc8c941 100644 |
| --- a/content/child/webmessageportchannel_impl.cc |
| +++ b/content/child/webmessageportchannel_impl.cc |
| @@ -59,6 +59,25 @@ WebMessagePortChannelImpl::~WebMessagePortChannelImpl() { |
| ChildThread::current()->GetRouter()->RemoveRoute(route_id_); |
| } |
| +// static |
| +void WebMessagePortChannelImpl::ExtractMessagePortIDs( |
| + WebMessagePortChannelArray* channels, |
| + std::vector<int>* message_port_ids) { |
| + DCHECK(message_port_ids->empty()); |
| + if (channels) { |
|
marja
2014/03/17 09:15:02
The same code is here and in WebMessagePortChannel
jsbell
2014/03/17 16:49:06
Uh... isn't that what I did by having WebMessagePo
marja
2014/03/17 17:04:06
Oops, sorry, missed that. (Wut, it's in the same f
|
| + message_port_ids->resize(channels->size()); |
| + // Extract the port IDs from the source array, then free it. |
| + 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); |
| + } |
| + delete channels; |
| + } |
| +} |
| + |
| void WebMessagePortChannelImpl::setClient(WebMessagePortChannelClient* client) { |
| // Must lock here since client_ is called on the main thread. |
| base::AutoLock auto_lock(lock_); |
| @@ -98,19 +117,8 @@ void WebMessagePortChannelImpl::postMessage( |
| void WebMessagePortChannelImpl::PostMessage( |
| const base::string16& message, |
| WebMessagePortChannelArray* channels) { |
| - std::vector<int> message_port_ids(channels ? channels->size() : 0); |
| - if (channels) { |
| - // Extract the port IDs from the source array, then free it. |
| - 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); |
| - } |
| - delete channels; |
| - } |
| - |
| + std::vector<int> message_port_ids; |
| + ExtractMessagePortIDs(channels, &message_port_ids); |
| IPC::Message* msg = new MessagePortHostMsg_PostMessage( |
| message_port_id_, message, message_port_ids); |
| Send(msg); |