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

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

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Eliminate unnecessary PostTask Created 3 years, 10 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
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 25 matching lines...) Expand all
36 ~HandleImpl() override {} 36 ~HandleImpl() override {}
37 37
38 blink::WebServiceWorker* serviceWorker() override { return worker_.get(); } 38 blink::WebServiceWorker* serviceWorker() override { return worker_.get(); }
39 39
40 private: 40 private:
41 scoped_refptr<WebServiceWorkerImpl> worker_; 41 scoped_refptr<WebServiceWorkerImpl> worker_;
42 42
43 DISALLOW_COPY_AND_ASSIGN(HandleImpl); 43 DISALLOW_COPY_AND_ASSIGN(HandleImpl);
44 }; 44 };
45 45
46 void SendPostMessageToWorkerOnMainThread( 46 void SendPostMessageToWorkerOnMainThread(ThreadSafeSender* thread_safe_sender,
47 ThreadSafeSender* thread_safe_sender, 47 int handle_id,
48 int handle_id, 48 int provider_id,
49 int provider_id, 49 const base::string16& message,
50 const base::string16& message, 50 const url::Origin& source_origin,
51 const url::Origin& source_origin, 51 WebMessagePortChannelArray channels) {
52 std::unique_ptr<WebMessagePortChannelArray> channels) {
53 thread_safe_sender->Send(new ServiceWorkerHostMsg_PostMessageToWorker( 52 thread_safe_sender->Send(new ServiceWorkerHostMsg_PostMessageToWorker(
54 handle_id, provider_id, message, source_origin, 53 handle_id, provider_id, message, source_origin,
55 WebMessagePortChannelImpl::ExtractMessagePortIDs(std::move(channels)))); 54 WebMessagePortChannelImpl::ExtractMessagePorts(std::move(channels))));
56 } 55 }
57 56
58 } // namespace 57 } // namespace
59 58
60 WebServiceWorkerImpl::WebServiceWorkerImpl( 59 WebServiceWorkerImpl::WebServiceWorkerImpl(
61 std::unique_ptr<ServiceWorkerHandleReference> handle_ref, 60 std::unique_ptr<ServiceWorkerHandleReference> handle_ref,
62 ThreadSafeSender* thread_safe_sender) 61 ThreadSafeSender* thread_safe_sender)
63 : handle_ref_(std::move(handle_ref)), 62 : handle_ref_(std::move(handle_ref)),
64 state_(handle_ref_->state()), 63 state_(handle_ref_->state()),
65 thread_safe_sender_(thread_safe_sender), 64 thread_safe_sender_(thread_safe_sender),
(...skipping 28 matching lines...) Expand all
94 } 93 }
95 94
96 blink::WebServiceWorkerState WebServiceWorkerImpl::state() const { 95 blink::WebServiceWorkerState WebServiceWorkerImpl::state() const {
97 return state_; 96 return state_;
98 } 97 }
99 98
100 void WebServiceWorkerImpl::postMessage( 99 void WebServiceWorkerImpl::postMessage(
101 blink::WebServiceWorkerProvider* provider, 100 blink::WebServiceWorkerProvider* provider,
102 const WebString& message, 101 const WebString& message,
103 const WebSecurityOrigin& source_origin, 102 const WebSecurityOrigin& source_origin,
104 WebMessagePortChannelArray* channels) { 103 WebMessagePortChannelArray channels) {
105 WebServiceWorkerProviderImpl* provider_impl = 104 WebServiceWorkerProviderImpl* provider_impl =
106 static_cast<WebServiceWorkerProviderImpl*>(provider); 105 static_cast<WebServiceWorkerProviderImpl*>(provider);
107 ServiceWorkerDispatcher* dispatcher = 106 ServiceWorkerDispatcher* dispatcher =
108 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 107 ServiceWorkerDispatcher::GetThreadSpecificInstance();
109 DCHECK(dispatcher); 108 DCHECK(dispatcher);
110 109
111 // This may send channels for MessagePorts, and all internal book-keeping 110 // This may send channels for MessagePorts, and all internal book-keeping
112 // messages for MessagePort (e.g. QueueMessages) are sent from main thread 111 // 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 112 // (with thread hopping), so we need to do the same thread hopping here not
114 // to overtake those messages. 113 // to overtake those messages.
115 dispatcher->main_thread_task_runner()->PostTask( 114 dispatcher->main_thread_task_runner()->PostTask(
116 FROM_HERE, 115 FROM_HERE,
117 base::Bind(&SendPostMessageToWorkerOnMainThread, 116 base::Bind(&SendPostMessageToWorkerOnMainThread,
118 base::RetainedRef(thread_safe_sender_), 117 base::RetainedRef(thread_safe_sender_),
119 handle_ref_->handle_id(), provider_impl->provider_id(), 118 handle_ref_->handle_id(), provider_impl->provider_id(),
120 // We convert WebString to string16 before crossing 119 // We convert WebString to string16 before crossing
121 // threads for thread-safety. 120 // threads for thread-safety.
122 message.utf16(), url::Origin(source_origin), 121 message.utf16(), url::Origin(source_origin),
123 base::Passed(base::WrapUnique(channels)))); 122 base::Passed(&channels)));
124 } 123 }
125 124
126 void WebServiceWorkerImpl::terminate() { 125 void WebServiceWorkerImpl::terminate() {
127 thread_safe_sender_->Send( 126 thread_safe_sender_->Send(
128 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id())); 127 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id()));
129 } 128 }
130 129
131 // static 130 // static
132 std::unique_ptr<blink::WebServiceWorker::Handle> 131 std::unique_ptr<blink::WebServiceWorker::Handle>
133 WebServiceWorkerImpl::CreateHandle( 132 WebServiceWorkerImpl::CreateHandle(
134 const scoped_refptr<WebServiceWorkerImpl>& worker) { 133 const scoped_refptr<WebServiceWorkerImpl>& worker) {
135 if (!worker) 134 if (!worker)
136 return nullptr; 135 return nullptr;
137 return base::MakeUnique<HandleImpl>(worker); 136 return base::MakeUnique<HandleImpl>(worker);
138 } 137 }
139 138
140 WebServiceWorkerImpl::~WebServiceWorkerImpl() { 139 WebServiceWorkerImpl::~WebServiceWorkerImpl() {
141 ServiceWorkerDispatcher* dispatcher = 140 ServiceWorkerDispatcher* dispatcher =
142 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 141 ServiceWorkerDispatcher::GetThreadSpecificInstance();
143 if (dispatcher) 142 if (dispatcher)
144 dispatcher->RemoveServiceWorker(handle_ref_->handle_id()); 143 dispatcher->RemoveServiceWorker(handle_ref_->handle_id());
145 } 144 }
146 145
147 } // namespace content 146 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698