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/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "content/child/child_process.h" | 9 #include "content/child/child_process.h" |
10 #include "content/child/child_thread.h" | 10 #include "content/child/child_thread.h" |
11 #include "content/common/message_port_messages.h" | 11 #include "content/common/message_port_messages.h" |
12 #include "third_party/WebKit/public/platform/WebMessagePortChannelClient.h" | 12 #include "third_party/WebKit/public/platform/WebMessagePortChannelClient.h" |
13 #include "third_party/WebKit/public/platform/WebString.h" | 13 #include "third_party/WebKit/public/platform/WebString.h" |
14 | 14 |
15 using blink::WebMessagePortChannel; | 15 using blink::WebMessagePortChannel; |
16 using blink::WebMessagePortChannelArray; | 16 using blink::WebMessagePortChannelArray; |
17 using blink::WebMessagePortChannelClient; | 17 using blink::WebMessagePortChannelClient; |
18 using blink::WebString; | 18 using blink::WebString; |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 WebMessagePortChannelImpl::WebMessagePortChannelImpl( | 22 WebMessagePortChannelImpl::WebMessagePortChannelImpl( |
23 base::MessageLoopProxy* child_thread_loop) | 23 const scoped_refptr<base::MessageLoopProxy>& child_thread_loop) |
24 : client_(NULL), | 24 : client_(NULL), |
25 route_id_(MSG_ROUTING_NONE), | 25 route_id_(MSG_ROUTING_NONE), |
26 message_port_id_(MSG_ROUTING_NONE), | 26 message_port_id_(MSG_ROUTING_NONE), |
27 child_thread_loop_(child_thread_loop) { | 27 child_thread_loop_(child_thread_loop) { |
28 AddRef(); | 28 AddRef(); |
29 Init(); | 29 Init(); |
30 } | 30 } |
31 | 31 |
32 WebMessagePortChannelImpl::WebMessagePortChannelImpl( | 32 WebMessagePortChannelImpl::WebMessagePortChannelImpl( |
33 int route_id, | 33 int route_id, |
34 int message_port_id, | 34 int message_port_id, |
35 base::MessageLoopProxy* child_thread_loop) | 35 const scoped_refptr<base::MessageLoopProxy>& child_thread_loop) |
36 : client_(NULL), | 36 : client_(NULL), |
37 route_id_(route_id), | 37 route_id_(route_id), |
38 message_port_id_(message_port_id), | 38 message_port_id_(message_port_id), |
39 child_thread_loop_(child_thread_loop) { | 39 child_thread_loop_(child_thread_loop) { |
40 AddRef(); | 40 AddRef(); |
41 Init(); | 41 Init(); |
42 } | 42 } |
43 | 43 |
44 WebMessagePortChannelImpl::~WebMessagePortChannelImpl() { | 44 WebMessagePortChannelImpl::~WebMessagePortChannelImpl() { |
45 // If we have any queued messages with attached ports, manually destroy them. | 45 // If we have any queued messages with attached ports, manually destroy them. |
46 while (!message_queue_.empty()) { | 46 while (!message_queue_.empty()) { |
47 const std::vector<WebMessagePortChannelImpl*>& channel_array = | 47 const std::vector<WebMessagePortChannelImpl*>& channel_array = |
48 message_queue_.front().ports; | 48 message_queue_.front().ports; |
49 for (size_t i = 0; i < channel_array.size(); i++) { | 49 for (size_t i = 0; i < channel_array.size(); i++) { |
50 channel_array[i]->destroy(); | 50 channel_array[i]->destroy(); |
51 } | 51 } |
52 message_queue_.pop(); | 52 message_queue_.pop(); |
53 } | 53 } |
54 | 54 |
55 if (message_port_id_ != MSG_ROUTING_NONE) | 55 if (message_port_id_ != MSG_ROUTING_NONE) |
56 Send(new MessagePortHostMsg_DestroyMessagePort(message_port_id_)); | 56 Send(new MessagePortHostMsg_DestroyMessagePort(message_port_id_)); |
57 | 57 |
58 if (route_id_ != MSG_ROUTING_NONE) | 58 if (route_id_ != MSG_ROUTING_NONE) |
59 ChildThread::current()->GetRouter()->RemoveRoute(route_id_); | 59 ChildThread::current()->GetRouter()->RemoveRoute(route_id_); |
60 } | 60 } |
61 | 61 |
62 // static | 62 // static |
63 void WebMessagePortChannelImpl::CreatePair( | 63 void WebMessagePortChannelImpl::CreatePair( |
64 base::MessageLoopProxy* child_thread_loop, | 64 const scoped_refptr<base::MessageLoopProxy>& child_thread_loop, |
65 blink::WebMessagePortChannel** channel1, | 65 blink::WebMessagePortChannel** channel1, |
66 blink::WebMessagePortChannel** channel2) { | 66 blink::WebMessagePortChannel** channel2) { |
67 WebMessagePortChannelImpl* impl1 = | 67 WebMessagePortChannelImpl* impl1 = |
68 new WebMessagePortChannelImpl(child_thread_loop); | 68 new WebMessagePortChannelImpl(child_thread_loop); |
69 WebMessagePortChannelImpl* impl2 = | 69 WebMessagePortChannelImpl* impl2 = |
70 new WebMessagePortChannelImpl(child_thread_loop); | 70 new WebMessagePortChannelImpl(child_thread_loop); |
71 | 71 |
72 impl1->Entangle(impl2); | 72 impl1->Entangle(impl2); |
73 impl2->Entangle(impl1); | 73 impl2->Entangle(impl1); |
74 | 74 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
277 Release(); | 277 Release(); |
278 ChildProcess::current()->ReleaseProcess(); | 278 ChildProcess::current()->ReleaseProcess(); |
279 } | 279 } |
280 | 280 |
281 WebMessagePortChannelImpl::Message::Message() {} | 281 WebMessagePortChannelImpl::Message::Message() {} |
282 | 282 |
283 WebMessagePortChannelImpl::Message::~Message() {} | 283 WebMessagePortChannelImpl::Message::~Message() {} |
284 | 284 |
285 } // namespace content | 285 } // namespace content |
OLD | NEW |