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/thread_safe_sender.h" | 8 #include "content/child/thread_safe_sender.h" |
9 #include "content/child/webmessageportchannel_impl.h" | 9 #include "content/child/webmessageportchannel_impl.h" |
10 #include "content/common/service_worker/service_worker_messages.h" | 10 #include "content/common/service_worker/service_worker_messages.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 if (handle_id_ == kInvalidServiceWorkerHandleId) | 37 if (handle_id_ == kInvalidServiceWorkerHandleId) |
38 return; | 38 return; |
39 thread_safe_sender_->Send( | 39 thread_safe_sender_->Send( |
40 new ServiceWorkerHostMsg_ServiceWorkerObjectDestroyed(handle_id_)); | 40 new ServiceWorkerHostMsg_ServiceWorkerObjectDestroyed(handle_id_)); |
41 ServiceWorkerDispatcher* dispatcher = | 41 ServiceWorkerDispatcher* dispatcher = |
42 ServiceWorkerDispatcher::GetThreadSpecificInstance(); | 42 ServiceWorkerDispatcher::GetThreadSpecificInstance(); |
43 if (dispatcher) | 43 if (dispatcher) |
44 dispatcher->RemoveServiceWorker(handle_id_); | 44 dispatcher->RemoveServiceWorker(handle_id_); |
45 } | 45 } |
46 | 46 |
47 void WebServiceWorkerImpl::SetState(blink::WebServiceWorkerState new_state) { | 47 void WebServiceWorkerImpl::OnStateChanged( |
48 state_ = new_state; | 48 blink::WebServiceWorkerState new_state) { |
49 if (!proxy_) | 49 DCHECK(proxy_); |
50 return; | 50 if (proxy_->isReady()) |
51 proxy_->dispatchStateChangeEvent(); | 51 ChangeState(new_state); |
| 52 else |
| 53 queued_states_.push_back(new_state); |
52 } | 54 } |
53 | 55 |
54 void WebServiceWorkerImpl::setProxy(blink::WebServiceWorkerProxy* proxy) { | 56 void WebServiceWorkerImpl::setProxy(blink::WebServiceWorkerProxy* proxy) { |
55 proxy_ = proxy; | 57 proxy_ = proxy; |
56 } | 58 } |
57 | 59 |
| 60 void WebServiceWorkerImpl::proxyReadyChanged() { |
| 61 if (!proxy_->isReady()) |
| 62 return; |
| 63 for (std::vector<blink::WebServiceWorkerState>::iterator it = |
| 64 queued_states_.begin(); |
| 65 it != queued_states_.end(); |
| 66 ++it) { |
| 67 ChangeState(*it); |
| 68 } |
| 69 queued_states_.clear(); |
| 70 } |
| 71 |
58 blink::WebURL WebServiceWorkerImpl::scope() const { | 72 blink::WebURL WebServiceWorkerImpl::scope() const { |
59 return scope_; | 73 return scope_; |
60 } | 74 } |
61 | 75 |
62 blink::WebURL WebServiceWorkerImpl::url() const { | 76 blink::WebURL WebServiceWorkerImpl::url() const { |
63 return url_; | 77 return url_; |
64 } | 78 } |
65 | 79 |
66 blink::WebServiceWorkerState WebServiceWorkerImpl::state() const { | 80 blink::WebServiceWorkerState WebServiceWorkerImpl::state() const { |
67 return state_; | 81 return state_; |
68 } | 82 } |
69 | 83 |
70 void WebServiceWorkerImpl::postMessage(const WebString& message, | 84 void WebServiceWorkerImpl::postMessage(const WebString& message, |
71 WebMessagePortChannelArray* channels) { | 85 WebMessagePortChannelArray* channels) { |
72 thread_safe_sender_->Send(new ServiceWorkerHostMsg_PostMessage( | 86 thread_safe_sender_->Send(new ServiceWorkerHostMsg_PostMessage( |
73 handle_id_, | 87 handle_id_, |
74 message, | 88 message, |
75 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels))); | 89 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels))); |
76 } | 90 } |
77 | 91 |
| 92 void WebServiceWorkerImpl::ChangeState(blink::WebServiceWorkerState new_state) { |
| 93 DCHECK(proxy_); |
| 94 DCHECK(proxy_->isReady()); |
| 95 state_ = new_state; |
| 96 proxy_->dispatchStateChangeEvent(); |
| 97 } |
| 98 |
78 } // namespace content | 99 } // namespace content |
OLD | NEW |