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

Side by Side Diff: content/child/service_worker/web_service_worker_impl.cc

Issue 1257393005: [Thread Safety] Replace WebString bound by cross-thread base::Bind() with base::string16 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 | « content/child/navigator_connect/service_port_provider.cc ('k') | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/service_worker/web_service_worker_impl.h" 5 #include "content/child/service_worker/web_service_worker_impl.h"
6 6
7 #include "content/child/service_worker/service_worker_dispatcher.h" 7 #include "content/child/service_worker/service_worker_dispatcher.h"
8 #include "content/child/service_worker/service_worker_handle_reference.h" 8 #include "content/child/service_worker/service_worker_handle_reference.h"
9 #include "content/child/thread_safe_sender.h" 9 #include "content/child/thread_safe_sender.h"
10 #include "content/child/webmessageportchannel_impl.h" 10 #include "content/child/webmessageportchannel_impl.h"
11 #include "content/common/service_worker/service_worker_messages.h" 11 #include "content/common/service_worker/service_worker_messages.h"
12 #include "third_party/WebKit/public/platform/WebServiceWorkerProxy.h" 12 #include "third_party/WebKit/public/platform/WebServiceWorkerProxy.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 namespace { 22 namespace {
23 23
24 void SendPostMessageToWorkerOnMainThread( 24 void SendPostMessageToWorkerOnMainThread(
25 ThreadSafeSender* thread_safe_sender, 25 ThreadSafeSender* thread_safe_sender,
26 int handle_id, 26 int handle_id,
27 const WebString& message, 27 const base::string16& message,
28 scoped_ptr<WebMessagePortChannelArray> channels) { 28 scoped_ptr<WebMessagePortChannelArray> channels) {
29 thread_safe_sender->Send(new ServiceWorkerHostMsg_PostMessageToWorker( 29 thread_safe_sender->Send(new ServiceWorkerHostMsg_PostMessageToWorker(
30 handle_id, message, 30 handle_id, message,
31 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels.Pass()))); 31 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels.Pass())));
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 WebServiceWorkerImpl::WebServiceWorkerImpl( 36 WebServiceWorkerImpl::WebServiceWorkerImpl(
37 scoped_ptr<ServiceWorkerHandleReference> handle_ref, 37 scoped_ptr<ServiceWorkerHandleReference> handle_ref,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 83 ServiceWorkerDispatcher::GetThreadSpecificInstance();
84 DCHECK(dispatcher); 84 DCHECK(dispatcher);
85 85
86 // This may send channels for MessagePorts, and all internal book-keeping 86 // This may send channels for MessagePorts, and all internal book-keeping
87 // messages for MessagePort (e.g. QueueMessages) are sent from main thread 87 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
88 // (with thread hopping), so we need to do the same thread hopping here not 88 // (with thread hopping), so we need to do the same thread hopping here not
89 // to overtake those messages. 89 // to overtake those messages.
90 dispatcher->main_thread_task_runner()->PostTask( 90 dispatcher->main_thread_task_runner()->PostTask(
91 FROM_HERE, base::Bind(&SendPostMessageToWorkerOnMainThread, 91 FROM_HERE, base::Bind(&SendPostMessageToWorkerOnMainThread,
92 thread_safe_sender_, handle_ref_->handle_id(), 92 thread_safe_sender_, handle_ref_->handle_id(),
93 message, base::Passed(make_scoped_ptr(channels)))); 93 // We cast WebString to string16 before crossing
94 // threads for thread-safety.
95 static_cast<base::string16>(message),
96 base::Passed(make_scoped_ptr(channels))));
94 } 97 }
95 98
96 void WebServiceWorkerImpl::terminate() { 99 void WebServiceWorkerImpl::terminate() {
97 thread_safe_sender_->Send( 100 thread_safe_sender_->Send(
98 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id())); 101 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id()));
99 } 102 }
100 103
101 } // namespace content 104 } // namespace content
OLDNEW
« no previous file with comments | « content/child/navigator_connect/service_port_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698