| 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/service_worker/service_worker_provider_context.h" | 9 #include "content/child/service_worker/service_worker_provider_context.h" |
| 10 #include "content/common/service_worker/service_worker_messages.h" | 10 #include "content/common/service_worker/service_worker_messages.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 ServiceWorkerNetworkProvider* ServiceWorkerNetworkProvider::FromDocumentState( | 41 ServiceWorkerNetworkProvider* ServiceWorkerNetworkProvider::FromDocumentState( |
| 42 base::SupportsUserData* datasource_userdata) { | 42 base::SupportsUserData* datasource_userdata) { |
| 43 return static_cast<ServiceWorkerNetworkProvider*>( | 43 return static_cast<ServiceWorkerNetworkProvider*>( |
| 44 datasource_userdata->GetUserData(&kUserDataKey)); | 44 datasource_userdata->GetUserData(&kUserDataKey)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 47 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
| 48 int route_id, | 48 int route_id, |
| 49 ServiceWorkerProviderType provider_type) | 49 ServiceWorkerProviderType provider_type, |
| 50 : provider_id_(GenerateProviderIdForType(provider_type)) { | 50 int browser_provider_id) |
| 51 : provider_id_(browser_provider_id) { |
| 51 if (provider_id_ == kInvalidServiceWorkerProviderId) | 52 if (provider_id_ == kInvalidServiceWorkerProviderId) |
| 52 return; | 53 return; |
| 53 context_ = new ServiceWorkerProviderContext(provider_id_, provider_type); | 54 context_ = new ServiceWorkerProviderContext(provider_id_, provider_type); |
| 54 if (!ChildThreadImpl::current()) | 55 if (!ChildThreadImpl::current()) |
| 55 return; // May be null in some tests. | 56 return; // May be null in some tests. |
| 56 ChildThreadImpl::current()->Send(new ServiceWorkerHostMsg_ProviderCreated( | 57 ChildThreadImpl::current()->Send(new ServiceWorkerHostMsg_ProviderCreated( |
| 57 provider_id_, route_id, provider_type)); | 58 provider_id_, route_id, provider_type)); |
| 58 } | 59 } |
| 59 | 60 |
| 61 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
| 62 int route_id, |
| 63 ServiceWorkerProviderType provider_type) |
| 64 : ServiceWorkerNetworkProvider(route_id, |
| 65 provider_type, |
| 66 GenerateProviderIdForType(provider_type)) {} |
| 67 |
| 68 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() |
| 69 : provider_id_(kInvalidServiceWorkerProviderId) {} |
| 70 |
| 60 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { | 71 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { |
| 61 if (provider_id_ == kInvalidServiceWorkerProviderId) | 72 if (provider_id_ == kInvalidServiceWorkerProviderId) |
| 62 return; | 73 return; |
| 63 if (!ChildThreadImpl::current()) | 74 if (!ChildThreadImpl::current()) |
| 64 return; // May be null in some tests. | 75 return; // May be null in some tests. |
| 65 ChildThreadImpl::current()->Send( | 76 ChildThreadImpl::current()->Send( |
| 66 new ServiceWorkerHostMsg_ProviderDestroyed(provider_id_)); | 77 new ServiceWorkerHostMsg_ProviderDestroyed(provider_id_)); |
| 67 } | 78 } |
| 68 | 79 |
| 69 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( | 80 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( |
| 70 int64 version_id) { | 81 int64 version_id) { |
| 71 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); | 82 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); |
| 72 if (!ChildThreadImpl::current()) | 83 if (!ChildThreadImpl::current()) |
| 73 return; // May be null in some tests. | 84 return; // May be null in some tests. |
| 74 ChildThreadImpl::current()->Send( | 85 ChildThreadImpl::current()->Send( |
| 75 new ServiceWorkerHostMsg_SetVersionId(provider_id_, version_id)); | 86 new ServiceWorkerHostMsg_SetVersionId(provider_id_, version_id)); |
| 76 } | 87 } |
| 77 | 88 |
| 78 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { | 89 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { |
| 79 return context() && context()->controller(); | 90 return context() && context()->controller(); |
| 80 } | 91 } |
| 81 | 92 |
| 82 } // namespace content | 93 } // namespace content |
| OLD | NEW |