OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/child/webmessageportchannel_impl.h" | 5 #include "content/child/webmessageportchannel_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "content/child/child_process.h" | 9 #include "content/child/child_process.h" |
10 #include "content/child/child_thread_impl.h" | 10 #include "content/child/child_thread_impl.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 message_ports[i].id = webchannel->message_port_id(); | 112 message_ports[i].id = webchannel->message_port_id(); |
113 message_ports[i].send_messages_as_values = | 113 message_ports[i].send_messages_as_values = |
114 webchannel->send_messages_as_values_; | 114 webchannel->send_messages_as_values_; |
115 webchannel->QueueMessages(); | 115 webchannel->QueueMessages(); |
116 DCHECK(message_ports[i].id != MSG_ROUTING_NONE); | 116 DCHECK(message_ports[i].id != MSG_ROUTING_NONE); |
117 } | 117 } |
118 return message_ports; | 118 return message_ports; |
119 } | 119 } |
120 | 120 |
121 // static | 121 // static |
| 122 std::vector<TransferredMessagePort> |
| 123 WebMessagePortChannelImpl::ExtractMessagePortIDsWithoutQueueing( |
| 124 scoped_ptr<WebMessagePortChannelArray> channels) { |
| 125 if (!channels) |
| 126 return std::vector<TransferredMessagePort>(); |
| 127 |
| 128 std::vector<TransferredMessagePort> message_ports(channels->size()); |
| 129 for (size_t i = 0; i < channels->size(); ++i) { |
| 130 WebMessagePortChannelImpl* webchannel = |
| 131 static_cast<WebMessagePortChannelImpl*>((*channels)[i]); |
| 132 // The message port ids might not be set up yet if this channel |
| 133 // wasn't created on the main thread. |
| 134 DCHECK(webchannel->main_thread_task_runner_->BelongsToCurrentThread()); |
| 135 message_ports[i].id = webchannel->message_port_id(); |
| 136 message_ports[i].send_messages_as_values = |
| 137 webchannel->send_messages_as_values_; |
| 138 // Don't queue messages, but do increase the child processes ref-count to |
| 139 // ensure this child process stays alive long enough to receive all |
| 140 // in-flight messages. |
| 141 ChildProcess::current()->AddRefProcess(); |
| 142 DCHECK(message_ports[i].id != MSG_ROUTING_NONE); |
| 143 } |
| 144 return message_ports; |
| 145 } |
| 146 |
| 147 // static |
122 WebMessagePortChannelArray WebMessagePortChannelImpl::CreatePorts( | 148 WebMessagePortChannelArray WebMessagePortChannelImpl::CreatePorts( |
123 const std::vector<TransferredMessagePort>& message_ports, | 149 const std::vector<TransferredMessagePort>& message_ports, |
124 const std::vector<int>& new_routing_ids, | 150 const std::vector<int>& new_routing_ids, |
125 const scoped_refptr<base::SingleThreadTaskRunner>& | 151 const scoped_refptr<base::SingleThreadTaskRunner>& |
126 main_thread_task_runner) { | 152 main_thread_task_runner) { |
127 DCHECK_EQ(message_ports.size(), new_routing_ids.size()); | 153 DCHECK_EQ(message_ports.size(), new_routing_ids.size()); |
128 WebMessagePortChannelArray channels(message_ports.size()); | 154 WebMessagePortChannelArray channels(message_ports.size()); |
129 for (size_t i = 0; i < message_ports.size() && i < new_routing_ids.size(); | 155 for (size_t i = 0; i < message_ports.size() && i < new_routing_ids.size(); |
130 ++i) { | 156 ++i) { |
131 channels[i] = new WebMessagePortChannelImpl( | 157 channels[i] = new WebMessagePortChannelImpl( |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 349 |
324 Release(); | 350 Release(); |
325 ChildProcess::current()->ReleaseProcess(); | 351 ChildProcess::current()->ReleaseProcess(); |
326 } | 352 } |
327 | 353 |
328 WebMessagePortChannelImpl::Message::Message() {} | 354 WebMessagePortChannelImpl::Message::Message() {} |
329 | 355 |
330 WebMessagePortChannelImpl::Message::~Message() {} | 356 WebMessagePortChannelImpl::Message::~Message() {} |
331 | 357 |
332 } // namespace content | 358 } // namespace content |
OLD | NEW |