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" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | |
63 void WebMessagePortChannelImpl::ExtractMessagePortIDs( | |
64 WebMessagePortChannelArray* channels, | |
65 std::vector<int>* message_port_ids) { | |
66 DCHECK(message_port_ids->empty()); | |
67 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
| |
68 message_port_ids->resize(channels->size()); | |
69 // Extract the port IDs from the source array, then free it. | |
70 for (size_t i = 0; i < channels->size(); ++i) { | |
71 WebMessagePortChannelImpl* webchannel = | |
72 static_cast<WebMessagePortChannelImpl*>((*channels)[i]); | |
73 (*message_port_ids)[i] = webchannel->message_port_id(); | |
74 webchannel->QueueMessages(); | |
75 DCHECK((*message_port_ids)[i] != MSG_ROUTING_NONE); | |
76 } | |
77 delete channels; | |
78 } | |
79 } | |
80 | |
62 void WebMessagePortChannelImpl::setClient(WebMessagePortChannelClient* client) { | 81 void WebMessagePortChannelImpl::setClient(WebMessagePortChannelClient* client) { |
63 // Must lock here since client_ is called on the main thread. | 82 // Must lock here since client_ is called on the main thread. |
64 base::AutoLock auto_lock(lock_); | 83 base::AutoLock auto_lock(lock_); |
65 client_ = client; | 84 client_ = client; |
66 } | 85 } |
67 | 86 |
68 void WebMessagePortChannelImpl::destroy() { | 87 void WebMessagePortChannelImpl::destroy() { |
69 setClient(NULL); | 88 setClient(NULL); |
70 | 89 |
71 // Release the object on the main thread, since the destructor might want to | 90 // Release the object on the main thread, since the destructor might want to |
(...skipping 19 matching lines...) Expand all Loading... | |
91 base::Bind( | 110 base::Bind( |
92 &WebMessagePortChannelImpl::PostMessage, this, message, channels)); | 111 &WebMessagePortChannelImpl::PostMessage, this, message, channels)); |
93 } else { | 112 } else { |
94 PostMessage(message, channels); | 113 PostMessage(message, channels); |
95 } | 114 } |
96 } | 115 } |
97 | 116 |
98 void WebMessagePortChannelImpl::PostMessage( | 117 void WebMessagePortChannelImpl::PostMessage( |
99 const base::string16& message, | 118 const base::string16& message, |
100 WebMessagePortChannelArray* channels) { | 119 WebMessagePortChannelArray* channels) { |
101 std::vector<int> message_port_ids(channels ? channels->size() : 0); | 120 std::vector<int> message_port_ids; |
102 if (channels) { | 121 ExtractMessagePortIDs(channels, &message_port_ids); |
103 // Extract the port IDs from the source array, then free it. | |
104 for (size_t i = 0; i < channels->size(); ++i) { | |
105 WebMessagePortChannelImpl* webchannel = | |
106 static_cast<WebMessagePortChannelImpl*>((*channels)[i]); | |
107 message_port_ids[i] = webchannel->message_port_id(); | |
108 webchannel->QueueMessages(); | |
109 DCHECK(message_port_ids[i] != MSG_ROUTING_NONE); | |
110 } | |
111 delete channels; | |
112 } | |
113 | |
114 IPC::Message* msg = new MessagePortHostMsg_PostMessage( | 122 IPC::Message* msg = new MessagePortHostMsg_PostMessage( |
115 message_port_id_, message, message_port_ids); | 123 message_port_id_, message, message_port_ids); |
116 Send(msg); | 124 Send(msg); |
117 } | 125 } |
118 | 126 |
119 bool WebMessagePortChannelImpl::tryGetMessage( | 127 bool WebMessagePortChannelImpl::tryGetMessage( |
120 WebString* message, | 128 WebString* message, |
121 WebMessagePortChannelArray& channels) { | 129 WebMessagePortChannelArray& channels) { |
122 base::AutoLock auto_lock(lock_); | 130 base::AutoLock auto_lock(lock_); |
123 if (message_queue_.empty()) | 131 if (message_queue_.empty()) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 | 263 |
256 Release(); | 264 Release(); |
257 ChildProcess::current()->ReleaseProcess(); | 265 ChildProcess::current()->ReleaseProcess(); |
258 } | 266 } |
259 | 267 |
260 WebMessagePortChannelImpl::Message::Message() {} | 268 WebMessagePortChannelImpl::Message::Message() {} |
261 | 269 |
262 WebMessagePortChannelImpl::Message::~Message() {} | 270 WebMessagePortChannelImpl::Message::~Message() {} |
263 | 271 |
264 } // namespace content | 272 } // namespace content |
OLD | NEW |