OLD | NEW |
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/service_worker/service_worker_message_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 WebServiceWorkerImpl::WebServiceWorkerImpl( | 22 WebServiceWorkerImpl::WebServiceWorkerImpl( |
23 scoped_ptr<ServiceWorkerHandleReference> handle_ref, | 23 scoped_ptr<ServiceWorkerHandleReference> handle_ref, |
24 ThreadSafeSender* thread_safe_sender) | 24 ServiceWorkerMessageSender* sender) |
25 : handle_ref_(handle_ref.Pass()), | 25 : handle_ref_(handle_ref.Pass()), |
26 state_(handle_ref_->state()), | 26 state_(handle_ref_->state()), |
27 thread_safe_sender_(thread_safe_sender), | 27 sender_(sender), |
28 proxy_(NULL) { | 28 proxy_(NULL) { |
29 ServiceWorkerDispatcher* dispatcher = | 29 ServiceWorkerDispatcher* dispatcher = |
30 ServiceWorkerDispatcher::GetThreadSpecificInstance(); | 30 ServiceWorkerDispatcher::GetThreadSpecificInstance(); |
31 DCHECK(dispatcher); | 31 DCHECK(dispatcher); |
32 dispatcher->AddServiceWorker(handle_ref_->handle_id(), this); | 32 dispatcher->AddServiceWorker(handle_ref_->handle_id(), this); |
33 } | 33 } |
34 | 34 |
35 WebServiceWorkerImpl::~WebServiceWorkerImpl() { | 35 WebServiceWorkerImpl::~WebServiceWorkerImpl() { |
36 if (handle_ref_->handle_id() == kInvalidServiceWorkerHandleId) | 36 if (handle_ref_->handle_id() == kInvalidServiceWorkerHandleId) |
37 return; | 37 return; |
(...skipping 20 matching lines...) Expand all Loading... |
58 blink::WebURL WebServiceWorkerImpl::url() const { | 58 blink::WebURL WebServiceWorkerImpl::url() const { |
59 return handle_ref_->url(); | 59 return handle_ref_->url(); |
60 } | 60 } |
61 | 61 |
62 blink::WebServiceWorkerState WebServiceWorkerImpl::state() const { | 62 blink::WebServiceWorkerState WebServiceWorkerImpl::state() const { |
63 return state_; | 63 return state_; |
64 } | 64 } |
65 | 65 |
66 void WebServiceWorkerImpl::postMessage(const WebString& message, | 66 void WebServiceWorkerImpl::postMessage(const WebString& message, |
67 WebMessagePortChannelArray* channels) { | 67 WebMessagePortChannelArray* channels) { |
68 thread_safe_sender_->Send(new ServiceWorkerHostMsg_PostMessageToWorker( | 68 sender_->Send(new ServiceWorkerHostMsg_PostMessageToWorker( |
69 handle_ref_->handle_id(), | 69 handle_ref_->handle_id(), |
70 message, | 70 message, |
71 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels))); | 71 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels))); |
72 } | 72 } |
73 | 73 |
74 void WebServiceWorkerImpl::terminate() { | 74 void WebServiceWorkerImpl::terminate() { |
75 thread_safe_sender_->Send( | 75 sender_->Send( |
76 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id())); | 76 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id())); |
77 } | 77 } |
78 | 78 |
79 } // namespace content | 79 } // namespace content |
OLD | NEW |