OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/service_worker_provider_context.h" | 5 #include "content/child/service_worker/service_worker_provider_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/child/child_thread_impl.h" | 10 #include "content/child/child_thread_impl.h" |
11 #include "content/child/service_worker/service_worker_dispatcher.h" | 11 #include "content/child/service_worker/service_worker_dispatcher.h" |
12 #include "content/child/service_worker/service_worker_handle_reference.h" | 12 #include "content/child/service_worker/service_worker_handle_reference.h" |
13 #include "content/child/service_worker/service_worker_message_sender.h" | |
13 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" | 14 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" |
14 #include "content/child/thread_safe_sender.h" | 15 #include "content/child/thread_safe_sender.h" |
15 #include "content/child/worker_task_runner.h" | 16 #include "content/child/worker_task_runner.h" |
16 #include "content/common/service_worker/service_worker_messages.h" | 17 #include "content/common/service_worker/service_worker_messages.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 ServiceWorkerProviderContext::ServiceWorkerProviderContext(int provider_id) | 21 ServiceWorkerProviderContext::ServiceWorkerProviderContext(int provider_id) |
21 : provider_id_(provider_id), | 22 : provider_id_(provider_id), |
22 main_thread_loop_proxy_(base::MessageLoopProxy::current()) { | 23 main_thread_loop_proxy_(base::MessageLoopProxy::current()) { |
23 if (!ChildThreadImpl::current()) | 24 if (!ChildThreadImpl::current()) |
24 return; // May be null in some tests. | 25 return; // May be null in some tests. |
25 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender(); | 26 ThreadSafeSender* thread_safe_sender = |
27 ChildThreadImpl::current()->thread_safe_sender(); | |
28 sender_ = new ServiceWorkerMessageSender(thread_safe_sender); | |
26 ServiceWorkerDispatcher* dispatcher = | 29 ServiceWorkerDispatcher* dispatcher = |
27 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 30 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
Kunihiko Sakamoto
2015/03/17 03:40:38
Why not make this take a ServiceWorkerMessageSende
nhiroki
2015/03/17 07:36:53
Done.
| |
28 thread_safe_sender_.get()); | 31 thread_safe_sender); |
29 DCHECK(dispatcher); | 32 DCHECK(dispatcher); |
30 dispatcher->AddProviderContext(this); | 33 dispatcher->AddProviderContext(this); |
31 } | 34 } |
32 | 35 |
33 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() { | 36 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() { |
34 if (ServiceWorkerDispatcher* dispatcher = | 37 if (ServiceWorkerDispatcher* dispatcher = |
35 ServiceWorkerDispatcher::GetThreadSpecificInstance()) { | 38 ServiceWorkerDispatcher::GetThreadSpecificInstance()) { |
36 // Remove this context from the dispatcher living on the main thread. | 39 // Remove this context from the dispatcher living on the main thread. |
37 dispatcher->RemoveProviderContext(this); | 40 dispatcher->RemoveProviderContext(this); |
38 } | 41 } |
(...skipping 23 matching lines...) Expand all Loading... | |
62 | 65 |
63 void ServiceWorkerProviderContext::SetVersionAttributes( | 66 void ServiceWorkerProviderContext::SetVersionAttributes( |
64 ChangedVersionAttributesMask mask, | 67 ChangedVersionAttributesMask mask, |
65 const ServiceWorkerVersionAttributes& attrs) { | 68 const ServiceWorkerVersionAttributes& attrs) { |
66 base::AutoLock lock(lock_); | 69 base::AutoLock lock(lock_); |
67 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 70 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
68 DCHECK(registration_); | 71 DCHECK(registration_); |
69 | 72 |
70 if (mask.installing_changed()) { | 73 if (mask.installing_changed()) { |
71 installing_ = ServiceWorkerHandleReference::Adopt( | 74 installing_ = ServiceWorkerHandleReference::Adopt( |
72 attrs.installing, thread_safe_sender_.get()); | 75 attrs.installing, sender_.get()); |
73 } | 76 } |
74 if (mask.waiting_changed()) { | 77 if (mask.waiting_changed()) { |
75 waiting_ = ServiceWorkerHandleReference::Adopt( | 78 waiting_ = ServiceWorkerHandleReference::Adopt( |
76 attrs.waiting, thread_safe_sender_.get()); | 79 attrs.waiting, sender_.get()); |
77 } | 80 } |
78 if (mask.active_changed()) { | 81 if (mask.active_changed()) { |
79 active_ = ServiceWorkerHandleReference::Adopt( | 82 active_ = ServiceWorkerHandleReference::Adopt( |
80 attrs.active, thread_safe_sender_.get()); | 83 attrs.active, sender_.get()); |
81 } | 84 } |
82 } | 85 } |
83 | 86 |
84 void ServiceWorkerProviderContext::OnAssociateRegistration( | 87 void ServiceWorkerProviderContext::OnAssociateRegistration( |
85 const ServiceWorkerRegistrationObjectInfo& info, | 88 const ServiceWorkerRegistrationObjectInfo& info, |
86 const ServiceWorkerVersionAttributes& attrs) { | 89 const ServiceWorkerVersionAttributes& attrs) { |
87 base::AutoLock lock(lock_); | 90 base::AutoLock lock(lock_); |
88 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 91 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
89 DCHECK(!registration_); | 92 DCHECK(!registration_); |
90 DCHECK_NE(kInvalidServiceWorkerRegistrationId, info.registration_id); | 93 DCHECK_NE(kInvalidServiceWorkerRegistrationId, info.registration_id); |
91 DCHECK_NE(kInvalidServiceWorkerRegistrationHandleId, info.handle_id); | 94 DCHECK_NE(kInvalidServiceWorkerRegistrationHandleId, info.handle_id); |
92 | 95 |
93 registration_ = ServiceWorkerRegistrationHandleReference::Adopt( | 96 registration_ = |
94 info, thread_safe_sender_.get()); | 97 ServiceWorkerRegistrationHandleReference::Adopt(info, sender_.get()); |
95 installing_ = ServiceWorkerHandleReference::Adopt( | 98 installing_ = |
96 attrs.installing, thread_safe_sender_.get()); | 99 ServiceWorkerHandleReference::Adopt(attrs.installing, sender_.get()); |
97 waiting_ = ServiceWorkerHandleReference::Adopt( | 100 waiting_ = ServiceWorkerHandleReference::Adopt(attrs.waiting, sender_.get()); |
98 attrs.waiting, thread_safe_sender_.get()); | 101 active_ = ServiceWorkerHandleReference::Adopt(attrs.active, sender_.get()); |
99 active_ = ServiceWorkerHandleReference::Adopt( | |
100 attrs.active, thread_safe_sender_.get()); | |
101 } | 102 } |
102 | 103 |
103 void ServiceWorkerProviderContext::OnDisassociateRegistration() { | 104 void ServiceWorkerProviderContext::OnDisassociateRegistration() { |
104 base::AutoLock lock(lock_); | 105 base::AutoLock lock(lock_); |
105 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 106 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
106 | 107 |
107 controller_.reset(); | 108 controller_.reset(); |
108 active_.reset(); | 109 active_.reset(); |
109 waiting_.reset(); | 110 waiting_.reset(); |
110 installing_.reset(); | 111 installing_.reset(); |
(...skipping 26 matching lines...) Expand all Loading... | |
137 // when we support navigator.serviceWorker in dedicated workers. | 138 // when we support navigator.serviceWorker in dedicated workers. |
138 } | 139 } |
139 | 140 |
140 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( | 141 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( |
141 const ServiceWorkerObjectInfo& info) { | 142 const ServiceWorkerObjectInfo& info) { |
142 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 143 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
143 DCHECK(registration_); | 144 DCHECK(registration_); |
144 | 145 |
145 // This context is is the primary owner of this handle, keeps the | 146 // This context is is the primary owner of this handle, keeps the |
146 // initial reference until it goes away. | 147 // initial reference until it goes away. |
147 controller_ = | 148 controller_ = ServiceWorkerHandleReference::Adopt(info, sender_.get()); |
148 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | |
149 | 149 |
150 // TODO(kinuko): We can forward the message to other threads here | 150 // TODO(kinuko): We can forward the message to other threads here |
151 // when we support navigator.serviceWorker in dedicated workers. | 151 // when we support navigator.serviceWorker in dedicated workers. |
152 } | 152 } |
153 | 153 |
154 int ServiceWorkerProviderContext::installing_handle_id() const { | 154 int ServiceWorkerProviderContext::installing_handle_id() const { |
155 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 155 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
156 return installing_ ? installing_->info().handle_id | 156 return installing_ ? installing_->info().handle_id |
157 : kInvalidServiceWorkerHandleId; | 157 : kInvalidServiceWorkerHandleId; |
158 } | 158 } |
(...skipping 24 matching lines...) Expand all Loading... | |
183 | 183 |
184 void ServiceWorkerProviderContext::DestructOnMainThread() const { | 184 void ServiceWorkerProviderContext::DestructOnMainThread() const { |
185 if (!main_thread_loop_proxy_->RunsTasksOnCurrentThread() && | 185 if (!main_thread_loop_proxy_->RunsTasksOnCurrentThread() && |
186 main_thread_loop_proxy_->DeleteSoon(FROM_HERE, this)) { | 186 main_thread_loop_proxy_->DeleteSoon(FROM_HERE, this)) { |
187 return; | 187 return; |
188 } | 188 } |
189 delete this; | 189 delete this; |
190 } | 190 } |
191 | 191 |
192 } // namespace content | 192 } // namespace content |
OLD | NEW |