Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: content/child/webmessageportchannel_impl.cc

Issue 189253002: Implement ServiceWorker::postMessage() [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename message handler per review feedback Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 std::vector<int> WebMessagePortChannelImpl::ExtractMessagePortIDs(
64 WebMessagePortChannelArray* channels) {
65 std::vector<int> message_port_ids;
66 if (channels) {
67 message_port_ids.resize(channels->size());
68 // Extract the port IDs from the source array, then free it.
69 for (size_t i = 0; i < channels->size(); ++i) {
70 WebMessagePortChannelImpl* webchannel =
71 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
72 message_port_ids[i] = webchannel->message_port_id();
73 webchannel->QueueMessages();
74 DCHECK(message_port_ids[i] != MSG_ROUTING_NONE);
75 }
76 delete channels;
77 }
78 return message_port_ids;
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
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);
102 if (channels) {
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( 120 IPC::Message* msg = new MessagePortHostMsg_PostMessage(
115 message_port_id_, message, message_port_ids); 121 message_port_id_, message, ExtractMessagePortIDs(channels));
116 Send(msg); 122 Send(msg);
117 } 123 }
118 124
119 bool WebMessagePortChannelImpl::tryGetMessage( 125 bool WebMessagePortChannelImpl::tryGetMessage(
120 WebString* message, 126 WebString* message,
121 WebMessagePortChannelArray& channels) { 127 WebMessagePortChannelArray& channels) {
122 base::AutoLock auto_lock(lock_); 128 base::AutoLock auto_lock(lock_);
123 if (message_queue_.empty()) 129 if (message_queue_.empty())
124 return false; 130 return false;
125 131
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 261
256 Release(); 262 Release();
257 ChildProcess::current()->ReleaseProcess(); 263 ChildProcess::current()->ReleaseProcess();
258 } 264 }
259 265
260 WebMessagePortChannelImpl::Message::Message() {} 266 WebMessagePortChannelImpl::Message::Message() {}
261 267
262 WebMessagePortChannelImpl::Message::~Message() {} 268 WebMessagePortChannelImpl::Message::~Message() {}
263 269
264 } // namespace content 270 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webmessageportchannel_impl.h ('k') | content/common/service_worker/service_worker_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698