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

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

Issue 2596173002: Use explicit WebString <-> string conversion methods for workers (Closed)
Patch Set: Created 4 years 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 // This may send channels for MessagePorts, and all internal book-keeping 111 // This may send channels for MessagePorts, and all internal book-keeping
112 // messages for MessagePort (e.g. QueueMessages) are sent from main thread 112 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
113 // (with thread hopping), so we need to do the same thread hopping here not 113 // (with thread hopping), so we need to do the same thread hopping here not
114 // to overtake those messages. 114 // to overtake those messages.
115 dispatcher->main_thread_task_runner()->PostTask( 115 dispatcher->main_thread_task_runner()->PostTask(
116 FROM_HERE, 116 FROM_HERE,
117 base::Bind(&SendPostMessageToWorkerOnMainThread, 117 base::Bind(&SendPostMessageToWorkerOnMainThread,
118 base::RetainedRef(thread_safe_sender_), 118 base::RetainedRef(thread_safe_sender_),
119 handle_ref_->handle_id(), provider_impl->provider_id(), 119 handle_ref_->handle_id(), provider_impl->provider_id(),
120 // We cast WebString to string16 before crossing 120 // We convert WebString to string16 before crossing
121 // threads for thread-safety. 121 // threads for thread-safety.
122 static_cast<base::string16>(message), 122 message.utf16(), url::Origin(source_origin),
falken 2016/12/26 01:26:20 Do you know why this IPC should be a string16 and
123 url::Origin(source_origin),
124 base::Passed(base::WrapUnique(channels)))); 123 base::Passed(base::WrapUnique(channels))));
125 } 124 }
126 125
127 void WebServiceWorkerImpl::terminate() { 126 void WebServiceWorkerImpl::terminate() {
128 thread_safe_sender_->Send( 127 thread_safe_sender_->Send(
129 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id())); 128 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id()));
130 } 129 }
131 130
132 // static 131 // static
133 std::unique_ptr<blink::WebServiceWorker::Handle> 132 std::unique_ptr<blink::WebServiceWorker::Handle>
134 WebServiceWorkerImpl::CreateHandle( 133 WebServiceWorkerImpl::CreateHandle(
135 const scoped_refptr<WebServiceWorkerImpl>& worker) { 134 const scoped_refptr<WebServiceWorkerImpl>& worker) {
136 if (!worker) 135 if (!worker)
137 return nullptr; 136 return nullptr;
138 return base::MakeUnique<HandleImpl>(worker); 137 return base::MakeUnique<HandleImpl>(worker);
139 } 138 }
140 139
141 WebServiceWorkerImpl::~WebServiceWorkerImpl() { 140 WebServiceWorkerImpl::~WebServiceWorkerImpl() {
142 ServiceWorkerDispatcher* dispatcher = 141 ServiceWorkerDispatcher* dispatcher =
143 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 142 ServiceWorkerDispatcher::GetThreadSpecificInstance();
144 if (dispatcher) 143 if (dispatcher)
145 dispatcher->RemoveServiceWorker(handle_ref_->handle_id()); 144 dispatcher->RemoveServiceWorker(handle_ref_->handle_id());
146 } 145 }
147 146
148 } // namespace content 147 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698