| 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/browser/service_worker/service_worker_registration_handle.h" | 5 #include "content/browser/service_worker/service_worker_registration_handle.h" |
| 6 | 6 |
| 7 #include "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | |
| 9 #include "content/browser/service_worker/service_worker_handle.h" | 8 #include "content/browser/service_worker/service_worker_handle.h" |
| 10 #include "content/common/service_worker/service_worker_messages.h" | 9 #include "content/common/service_worker/service_worker_messages.h" |
| 11 #include "content/common/service_worker/service_worker_types.h" | 10 #include "content/common/service_worker/service_worker_types.h" |
| 12 | 11 |
| 13 namespace content { | 12 namespace content { |
| 14 | 13 |
| 15 ServiceWorkerRegistrationHandle::ServiceWorkerRegistrationHandle( | 14 ServiceWorkerRegistrationHandle::ServiceWorkerRegistrationHandle( |
| 16 base::WeakPtr<ServiceWorkerContextCore> context, | 15 base::WeakPtr<ServiceWorkerContextCore> context, |
| 17 ServiceWorkerDispatcherHost* dispatcher_host, | 16 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 18 int provider_id, | |
| 19 ServiceWorkerRegistration* registration) | 17 ServiceWorkerRegistration* registration) |
| 20 : context_(context), | 18 : context_(context), |
| 21 dispatcher_host_(dispatcher_host), | 19 provider_host_(provider_host), |
| 22 provider_id_(provider_id), | 20 provider_id_(provider_host ? provider_host->provider_id() |
| 21 : kInvalidServiceWorkerProviderId), |
| 23 handle_id_(context ? context->GetNewRegistrationHandleId() | 22 handle_id_(context ? context->GetNewRegistrationHandleId() |
| 24 : kInvalidServiceWorkerRegistrationHandleId), | 23 : kInvalidServiceWorkerRegistrationHandleId), |
| 25 ref_count_(1), | 24 ref_count_(1), |
| 26 registration_(registration) { | 25 registration_(registration) { |
| 27 DCHECK(registration_.get()); | 26 DCHECK(registration_.get()); |
| 28 ChangedVersionAttributesMask changed_mask; | 27 ChangedVersionAttributesMask changed_mask; |
| 29 if (registration->installing_version()) | 28 if (registration->installing_version()) |
| 30 changed_mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); | 29 changed_mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); |
| 31 if (registration->waiting_version()) | 30 if (registration->waiting_version()) |
| 32 changed_mask.add(ChangedVersionAttributesMask::WAITING_VERSION); | 31 changed_mask.add(ChangedVersionAttributesMask::WAITING_VERSION); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 DCHECK_EQ(registration->id(), registration_->id()); | 78 DCHECK_EQ(registration->id(), registration_->id()); |
| 80 ChangedVersionAttributesMask changed_mask( | 79 ChangedVersionAttributesMask changed_mask( |
| 81 ChangedVersionAttributesMask::INSTALLING_VERSION | | 80 ChangedVersionAttributesMask::INSTALLING_VERSION | |
| 82 ChangedVersionAttributesMask::WAITING_VERSION | | 81 ChangedVersionAttributesMask::WAITING_VERSION | |
| 83 ChangedVersionAttributesMask::ACTIVE_VERSION); | 82 ChangedVersionAttributesMask::ACTIVE_VERSION); |
| 84 SetVersionAttributes(changed_mask, nullptr, nullptr, nullptr); | 83 SetVersionAttributes(changed_mask, nullptr, nullptr, nullptr); |
| 85 } | 84 } |
| 86 | 85 |
| 87 void ServiceWorkerRegistrationHandle::OnUpdateFound( | 86 void ServiceWorkerRegistrationHandle::OnUpdateFound( |
| 88 ServiceWorkerRegistration* registration) { | 87 ServiceWorkerRegistration* registration) { |
| 89 if (!dispatcher_host_) | 88 if (!provider_host_) |
| 90 return; // Could be nullptr in some tests. | 89 return; // Could be nullptr in some tests. |
| 91 dispatcher_host_->Send(new ServiceWorkerMsg_UpdateFound( | 90 provider_host_->SendUpdateFoundMessage(GetObjectInfo()); |
| 92 kDocumentMainThreadId, GetObjectInfo())); | |
| 93 } | 91 } |
| 94 | 92 |
| 95 void ServiceWorkerRegistrationHandle::SetVersionAttributes( | 93 void ServiceWorkerRegistrationHandle::SetVersionAttributes( |
| 96 ChangedVersionAttributesMask changed_mask, | 94 ChangedVersionAttributesMask changed_mask, |
| 97 ServiceWorkerVersion* installing_version, | 95 ServiceWorkerVersion* installing_version, |
| 98 ServiceWorkerVersion* waiting_version, | 96 ServiceWorkerVersion* waiting_version, |
| 99 ServiceWorkerVersion* active_version) { | 97 ServiceWorkerVersion* active_version) { |
| 100 if (!dispatcher_host_) | 98 if (!provider_host_) |
| 101 return; // Could be nullptr in some tests. | 99 return; // Could be nullptr in some tests. |
| 102 if (!changed_mask.changed()) | 100 provider_host_->SendSetVersionAttributesMessage(handle_id_, |
| 103 return; | 101 changed_mask, |
| 104 | 102 installing_version, |
| 105 ServiceWorkerVersionAttributes attributes; | 103 waiting_version, |
| 106 if (changed_mask.installing_changed()) { | 104 active_version); |
| 107 attributes.installing = | |
| 108 dispatcher_host_->CreateAndRegisterServiceWorkerHandle( | |
| 109 installing_version); | |
| 110 } | |
| 111 if (changed_mask.waiting_changed()) { | |
| 112 attributes.waiting = | |
| 113 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(waiting_version); | |
| 114 } | |
| 115 if (changed_mask.active_changed()) { | |
| 116 attributes.active = | |
| 117 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(active_version); | |
| 118 } | |
| 119 | |
| 120 dispatcher_host_->Send(new ServiceWorkerMsg_SetVersionAttributes( | |
| 121 kDocumentMainThreadId, provider_id_, handle_id_, | |
| 122 changed_mask.changed(), attributes)); | |
| 123 } | 105 } |
| 124 | 106 |
| 125 } // namespace content | 107 } // namespace content |
| OLD | NEW |