Chromium Code Reviews| Index: content/child/webmessageportchannel_impl.cc |
| diff --git a/content/child/webmessageportchannel_impl.cc b/content/child/webmessageportchannel_impl.cc |
| index 86e80fb09dbc78f651657feffcd5e74bca50ad8e..c1f8deb5af95f53f005766e205ec12d827b82131 100644 |
| --- a/content/child/webmessageportchannel_impl.cc |
| +++ b/content/child/webmessageportchannel_impl.cc |
| @@ -59,6 +59,25 @@ WebMessagePortChannelImpl::~WebMessagePortChannelImpl() { |
| ChildThread::current()->RemoveRoute(route_id_); |
| } |
| +// static |
| +void WebMessagePortChannelImpl::ExtractMessagePortIDs( |
| + WebMessagePortChannelArray* channels, |
| + std::vector<int>* message_port_ids) { |
| + DCHECK(message_port_ids->empty()); |
| + message_port_ids->resize(channels ? channels->size() : 0); |
|
michaeln
2014/03/11 23:17:34
looks like this could be in the if block and w/o f
jsbell
2014/03/12 18:16:16
Yep, DCHECK (a later addition) makes it optional.
|
| + 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(); |
|
michaeln
2014/03/11 23:17:34
voodoo :)
jsbell
2014/03/12 18:16:16
No kidding. I'll get a domain guru to review the v
|
| + 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); |