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_network_provider.h" | 5 #include "content/child/service_worker/service_worker_network_provider.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "content/child/child_thread_impl.h" | 8 #include "content/child/child_thread_impl.h" |
9 #include "content/child/request_extra_data.h" | 9 #include "content/child/request_extra_data.h" |
| 10 #include "content/child/service_worker/service_worker_dispatcher.h" |
10 #include "content/child/service_worker/service_worker_handle_reference.h" | 11 #include "content/child/service_worker/service_worker_handle_reference.h" |
11 #include "content/child/service_worker/service_worker_provider_context.h" | 12 #include "content/child/service_worker/service_worker_provider_context.h" |
12 #include "content/common/navigation_params.h" | 13 #include "content/common/navigation_params.h" |
13 #include "content/common/service_worker/service_worker_messages.h" | 14 #include "content/common/service_worker/service_worker_messages.h" |
14 #include "content/common/service_worker/service_worker_provider_host_info.h" | 15 #include "content/common/service_worker/service_worker_provider_host_info.h" |
15 #include "content/common/service_worker/service_worker_utils.h" | 16 #include "content/common/service_worker/service_worker_utils.h" |
16 #include "content/public/common/browser_side_navigation_policy.h" | 17 #include "content/public/common/browser_side_navigation_policy.h" |
17 #include "ipc/ipc_sync_channel.h" | 18 #include "ipc/ipc_sync_channel.h" |
18 #include "mojo/public/cpp/bindings/associated_group.h" | 19 #include "mojo/public/cpp/bindings/associated_group.h" |
19 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 20 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 197 |
197 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 198 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
198 int route_id, | 199 int route_id, |
199 ServiceWorkerProviderType provider_type, | 200 ServiceWorkerProviderType provider_type, |
200 bool is_parent_frame_secure) | 201 bool is_parent_frame_secure) |
201 : ServiceWorkerNetworkProvider(route_id, | 202 : ServiceWorkerNetworkProvider(route_id, |
202 provider_type, | 203 provider_type, |
203 GetNextProviderId(), | 204 GetNextProviderId(), |
204 is_parent_frame_secure) {} | 205 is_parent_frame_secure) {} |
205 | 206 |
| 207 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
| 208 mojom::ServiceWorkerProviderClientInfoPtr info) |
| 209 : provider_id_(info->provider_id) { |
| 210 context_ = new ServiceWorkerProviderContext( |
| 211 provider_id_, info->type, std::move(info->client_request), |
| 212 ChildThreadImpl::current()->thread_safe_sender()); |
| 213 |
| 214 ServiceWorkerDispatcher* dispatcher = |
| 215 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
| 216 ChildThreadImpl::current()->thread_safe_sender(), |
| 217 base::ThreadTaskRunnerHandle::Get().get()); |
| 218 // TODO(shimazu): Set registration/attributes directly to |context_|. |
| 219 dispatcher->OnAssociateRegistration(-1, info->provider_id, info->registration, |
| 220 info->attributes); |
| 221 |
| 222 provider_host_.Bind(std::move(info->host_ptr_info)); |
| 223 } |
| 224 |
206 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() | 225 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() |
207 : provider_id_(kInvalidServiceWorkerProviderId) {} | 226 : provider_id_(kInvalidServiceWorkerProviderId) {} |
208 | 227 |
209 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { | 228 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { |
210 if (provider_id_ == kInvalidServiceWorkerProviderId) | 229 if (provider_id_ == kInvalidServiceWorkerProviderId) |
211 return; | 230 return; |
212 if (!ChildThreadImpl::current()) | 231 if (!ChildThreadImpl::current()) |
213 return; // May be null in some tests. | 232 return; // May be null in some tests. |
214 provider_host_.reset(); | 233 provider_host_.reset(); |
215 } | 234 } |
216 | 235 |
217 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( | |
218 int64_t version_id, | |
219 int embedded_worker_id) { | |
220 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); | |
221 if (!ChildThreadImpl::current()) | |
222 return; // May be null in some tests. | |
223 dispatcher_host_->OnSetHostedVersionId(provider_id(), version_id, | |
224 embedded_worker_id); | |
225 } | |
226 | |
227 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { | 236 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { |
228 return context() && context()->controller(); | 237 return context() && context()->controller(); |
229 } | 238 } |
230 | 239 |
231 } // namespace content | 240 } // namespace content |
OLD | NEW |