| 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" | 8 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| 9 #include "content/browser/service_worker/service_worker_handle.h" | 9 #include "content/browser/service_worker/service_worker_handle.h" |
| 10 #include "content/common/service_worker/service_worker_messages.h" | 10 #include "content/common/service_worker/service_worker_messages.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 ServiceWorkerRegistrationObjectInfo | 40 ServiceWorkerRegistrationObjectInfo |
| 41 ServiceWorkerRegistrationHandle::GetObjectInfo() { | 41 ServiceWorkerRegistrationHandle::GetObjectInfo() { |
| 42 ServiceWorkerRegistrationObjectInfo info; | 42 ServiceWorkerRegistrationObjectInfo info; |
| 43 info.handle_id = handle_id_; | 43 info.handle_id = handle_id_; |
| 44 info.scope = registration_->pattern(); | 44 info.scope = registration_->pattern(); |
| 45 return info; | 45 return info; |
| 46 } | 46 } |
| 47 | 47 |
| 48 ServiceWorkerObjectInfo |
| 49 ServiceWorkerRegistrationHandle::CreateServiceWorkerHandleAndPass( |
| 50 ServiceWorkerVersion* version) { |
| 51 ServiceWorkerObjectInfo info; |
| 52 if (context_ && version) { |
| 53 scoped_ptr<ServiceWorkerHandle> handle = |
| 54 ServiceWorkerHandle::Create(context_, |
| 55 dispatcher_host_, |
| 56 kDocumentMainThreadId, |
| 57 provider_id_, |
| 58 version); |
| 59 info = handle->GetObjectInfo(); |
| 60 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); |
| 61 } |
| 62 return info; |
| 63 } |
| 64 |
| 48 void ServiceWorkerRegistrationHandle::IncrementRefCount() { | 65 void ServiceWorkerRegistrationHandle::IncrementRefCount() { |
| 49 DCHECK_GT(ref_count_, 0); | 66 DCHECK_GT(ref_count_, 0); |
| 50 ++ref_count_; | 67 ++ref_count_; |
| 51 } | 68 } |
| 52 | 69 |
| 53 void ServiceWorkerRegistrationHandle::DecrementRefCount() { | 70 void ServiceWorkerRegistrationHandle::DecrementRefCount() { |
| 54 DCHECK_GT(ref_count_, 0); | 71 DCHECK_GT(ref_count_, 0); |
| 55 --ref_count_; | 72 --ref_count_; |
| 56 } | 73 } |
| 57 | 74 |
| 58 void ServiceWorkerRegistrationHandle::OnVersionAttributesChanged( | 75 void ServiceWorkerRegistrationHandle::OnVersionAttributesChanged( |
| 59 ServiceWorkerRegistration* registration, | 76 ServiceWorkerRegistration* registration, |
| 60 ChangedVersionAttributesMask changed_mask, | 77 ChangedVersionAttributesMask changed_mask, |
| 61 const ServiceWorkerRegistrationInfo& info) { | 78 const ServiceWorkerRegistrationInfo& info) { |
| 62 DCHECK_EQ(registration->id(), registration_->id()); | 79 DCHECK_EQ(registration->id(), registration_->id()); |
| 63 SetVersionAttributes(registration->installing_version(), | 80 SetVersionAttributes(registration->installing_version(), |
| 64 registration->waiting_version(), | 81 registration->waiting_version(), |
| 65 registration->active_version()); | 82 registration->active_version()); |
| 66 } | 83 } |
| 67 | 84 |
| 68 void ServiceWorkerRegistrationHandle::OnRegistrationFailed( | 85 void ServiceWorkerRegistrationHandle::OnRegistrationFailed( |
| 69 ServiceWorkerRegistration* registration) { | 86 ServiceWorkerRegistration* registration) { |
| 70 DCHECK_EQ(registration->id(), registration_->id()); | 87 DCHECK_EQ(registration->id(), registration_->id()); |
| 71 ClearVersionAttributes(); | 88 ClearVersionAttributes(); |
| 72 } | 89 } |
| 73 | 90 |
| 91 void ServiceWorkerRegistrationHandle::OnUpdateFound( |
| 92 ServiceWorkerRegistration* registration) { |
| 93 if (!dispatcher_host_) |
| 94 return; // Could be NULL in some tests. |
| 95 dispatcher_host_->Send(new ServiceWorkerMsg_UpdateFound( |
| 96 kDocumentMainThreadId, GetObjectInfo())); |
| 97 } |
| 98 |
| 74 void ServiceWorkerRegistrationHandle::SetVersionAttributes( | 99 void ServiceWorkerRegistrationHandle::SetVersionAttributes( |
| 75 ServiceWorkerVersion* installing_version, | 100 ServiceWorkerVersion* installing_version, |
| 76 ServiceWorkerVersion* waiting_version, | 101 ServiceWorkerVersion* waiting_version, |
| 77 ServiceWorkerVersion* active_version) { | 102 ServiceWorkerVersion* active_version) { |
| 78 ChangedVersionAttributesMask mask; | 103 ChangedVersionAttributesMask mask; |
| 79 | 104 |
| 80 if (installing_version != installing_version_.get()) { | 105 if (installing_version != installing_version_.get()) { |
| 81 installing_version_ = installing_version; | 106 installing_version_ = installing_version; |
| 82 mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); | 107 mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); |
| 83 } | 108 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 111 | 136 |
| 112 dispatcher_host_->Send(new ServiceWorkerMsg_SetVersionAttributes( | 137 dispatcher_host_->Send(new ServiceWorkerMsg_SetVersionAttributes( |
| 113 kDocumentMainThreadId, provider_id_, handle_id_, | 138 kDocumentMainThreadId, provider_id_, handle_id_, |
| 114 mask.changed(), attributes)); | 139 mask.changed(), attributes)); |
| 115 } | 140 } |
| 116 | 141 |
| 117 void ServiceWorkerRegistrationHandle::ClearVersionAttributes() { | 142 void ServiceWorkerRegistrationHandle::ClearVersionAttributes() { |
| 118 SetVersionAttributes(NULL, NULL, NULL); | 143 SetVersionAttributes(NULL, NULL, NULL); |
| 119 } | 144 } |
| 120 | 145 |
| 121 ServiceWorkerObjectInfo | |
| 122 ServiceWorkerRegistrationHandle::CreateServiceWorkerHandleAndPass( | |
| 123 ServiceWorkerVersion* version) { | |
| 124 ServiceWorkerObjectInfo info; | |
| 125 if (context_ && version) { | |
| 126 scoped_ptr<ServiceWorkerHandle> handle = | |
| 127 ServiceWorkerHandle::Create(context_, | |
| 128 dispatcher_host_, | |
| 129 kDocumentMainThreadId, | |
| 130 provider_id_, | |
| 131 version); | |
| 132 info = handle->GetObjectInfo(); | |
| 133 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); | |
| 134 } | |
| 135 return info; | |
| 136 } | |
| 137 | |
| 138 } // namespace content | 146 } // namespace content |
| OLD | NEW |