| 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/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 WebServiceWorkerImpl::WebServiceWorkerImpl( | 22 WebServiceWorkerImpl::WebServiceWorkerImpl( |
| 23 const ServiceWorkerObjectInfo& info, | |
| 24 ThreadSafeSender* thread_safe_sender) | |
| 25 : handle_ref_( | |
| 26 ServiceWorkerHandleReference::CreateForDeleter(info, | |
| 27 thread_safe_sender)), | |
| 28 state_(handle_ref_->state()), | |
| 29 thread_safe_sender_(thread_safe_sender), | |
| 30 proxy_(NULL) { | |
| 31 ServiceWorkerDispatcher* dispatcher = | |
| 32 ServiceWorkerDispatcher::GetThreadSpecificInstance(); | |
| 33 DCHECK(dispatcher); | |
| 34 dispatcher->AddServiceWorker(handle_ref_->handle_id(), this); | |
| 35 } | |
| 36 | |
| 37 WebServiceWorkerImpl::WebServiceWorkerImpl( | |
| 38 scoped_ptr<ServiceWorkerHandleReference> handle_ref, | 23 scoped_ptr<ServiceWorkerHandleReference> handle_ref, |
| 39 ThreadSafeSender* thread_safe_sender) | 24 ThreadSafeSender* thread_safe_sender) |
| 40 : handle_ref_(handle_ref.Pass()), | 25 : handle_ref_(handle_ref.Pass()), |
| 41 state_(handle_ref_->state()), | 26 state_(handle_ref_->state()), |
| 42 thread_safe_sender_(thread_safe_sender), | 27 thread_safe_sender_(thread_safe_sender), |
| 43 proxy_(NULL) { | 28 proxy_(NULL) { |
| 44 ServiceWorkerDispatcher* dispatcher = | 29 ServiceWorkerDispatcher* dispatcher = |
| 45 ServiceWorkerDispatcher::GetThreadSpecificInstance(); | 30 ServiceWorkerDispatcher::GetThreadSpecificInstance(); |
| 46 DCHECK(dispatcher); | 31 DCHECK(dispatcher); |
| 47 dispatcher->AddServiceWorker(handle_ref_->handle_id(), this); | 32 dispatcher->AddServiceWorker(handle_ref_->handle_id(), this); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 62 if (proxy_->isReady()) | 47 if (proxy_->isReady()) |
| 63 ChangeState(new_state); | 48 ChangeState(new_state); |
| 64 else | 49 else |
| 65 queued_states_.push_back(new_state); | 50 queued_states_.push_back(new_state); |
| 66 } | 51 } |
| 67 | 52 |
| 68 void WebServiceWorkerImpl::setProxy(blink::WebServiceWorkerProxy* proxy) { | 53 void WebServiceWorkerImpl::setProxy(blink::WebServiceWorkerProxy* proxy) { |
| 69 proxy_ = proxy; | 54 proxy_ = proxy; |
| 70 } | 55 } |
| 71 | 56 |
| 57 blink::WebServiceWorkerProxy* WebServiceWorkerImpl::proxy() { |
| 58 return proxy_; |
| 59 } |
| 60 |
| 72 void WebServiceWorkerImpl::proxyReadyChanged() { | 61 void WebServiceWorkerImpl::proxyReadyChanged() { |
| 73 if (!proxy_->isReady()) | 62 if (!proxy_->isReady()) |
| 74 return; | 63 return; |
| 75 for (std::vector<blink::WebServiceWorkerState>::iterator it = | 64 for (std::vector<blink::WebServiceWorkerState>::iterator it = |
| 76 queued_states_.begin(); | 65 queued_states_.begin(); |
| 77 it != queued_states_.end(); | 66 it != queued_states_.end(); |
| 78 ++it) { | 67 ++it) { |
| 79 ChangeState(*it); | 68 ChangeState(*it); |
| 80 } | 69 } |
| 81 queued_states_.clear(); | 70 queued_states_.clear(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 102 } | 91 } |
| 103 | 92 |
| 104 void WebServiceWorkerImpl::ChangeState(blink::WebServiceWorkerState new_state) { | 93 void WebServiceWorkerImpl::ChangeState(blink::WebServiceWorkerState new_state) { |
| 105 DCHECK(proxy_); | 94 DCHECK(proxy_); |
| 106 DCHECK(proxy_->isReady()); | 95 DCHECK(proxy_->isReady()); |
| 107 state_ = new_state; | 96 state_ = new_state; |
| 108 proxy_->dispatchStateChangeEvent(); | 97 proxy_->dispatchStateChangeEvent(); |
| 109 } | 98 } |
| 110 | 99 |
| 111 } // namespace content | 100 } // namespace content |
| OLD | NEW |