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

Unified Diff: content/child/webmessageportchannel_impl.cc

Issue 189253002: Implement ServiceWorker::postMessage() [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reup 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 side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698