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

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

Issue 2224393002: Fix a data race in WebMessagePortChannelImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // Release the object on the main thread, since the destructor might want to 161 // Release the object on the main thread, since the destructor might want to
162 // send an IPC, and that has to happen on the main thread. 162 // send an IPC, and that has to happen on the main thread.
163 main_thread_task_runner_->ReleaseSoon(FROM_HERE, this); 163 main_thread_task_runner_->ReleaseSoon(FROM_HERE, this);
164 } 164 }
165 165
166 void WebMessagePortChannelImpl::postMessage( 166 void WebMessagePortChannelImpl::postMessage(
167 const WebString& message, 167 const WebString& message,
168 WebMessagePortChannelArray* channels_ptr) { 168 WebMessagePortChannelArray* channels_ptr) {
169 std::unique_ptr<WebMessagePortChannelArray> channels(channels_ptr); 169 std::unique_ptr<WebMessagePortChannelArray> channels(channels_ptr);
170 if (!main_thread_task_runner_->BelongsToCurrentThread()) { 170 if (!main_thread_task_runner_->BelongsToCurrentThread()) {
171 // Note: we must construct the base::string16 here and pass that. Otherwise,
172 // the WebString will be passed, leading to references to the StringImpl
173 // from two threads, which is a data race.
171 main_thread_task_runner_->PostTask( 174 main_thread_task_runner_->PostTask(
172 FROM_HERE, base::Bind(&WebMessagePortChannelImpl::SendPostMessage, this, 175 FROM_HERE, base::Bind(&WebMessagePortChannelImpl::SendPostMessage, this,
173 message, base::Passed(std::move(channels)))); 176 base::Passed(base::string16(message)),
177 base::Passed(std::move(channels))));
174 } else { 178 } else {
175 SendPostMessage(message, std::move(channels)); 179 SendPostMessage(message, std::move(channels));
176 } 180 }
177 } 181 }
178 182
179 void WebMessagePortChannelImpl::SendPostMessage( 183 void WebMessagePortChannelImpl::SendPostMessage(
180 const base::string16& message, 184 const base::string16& message,
181 std::unique_ptr<WebMessagePortChannelArray> channels) { 185 std::unique_ptr<WebMessagePortChannelArray> channels) {
182 IPC::Message* msg = new MessagePortHostMsg_PostMessage( 186 IPC::Message* msg = new MessagePortHostMsg_PostMessage(
183 message_port_id_, message, ExtractMessagePortIDs(std::move(channels))); 187 message_port_id_, message, ExtractMessagePortIDs(std::move(channels)));
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 ChildProcess::current()->ReleaseProcess(); 316 ChildProcess::current()->ReleaseProcess();
313 } 317 }
314 318
315 WebMessagePortChannelImpl::Message::Message() {} 319 WebMessagePortChannelImpl::Message::Message() {}
316 320
317 WebMessagePortChannelImpl::Message::Message(const Message& other) = default; 321 WebMessagePortChannelImpl::Message::Message(const Message& other) = default;
318 322
319 WebMessagePortChannelImpl::Message::~Message() {} 323 WebMessagePortChannelImpl::Message::~Message() {}
320 324
321 } // namespace content 325 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698