: kInvalidServiceWorkerRegistrationHandleId),
ref_count_(1),
registration_(registration) {
- DCHECK(registration_);
+ DCHECK(registration_.get());
SetVersionAttributes(registration->installing_version(),
registration->waiting_version(),
registration->active_version());
}
ServiceWorkerRegistrationHandle::~ServiceWorkerRegistrationHandle() {
- DCHECK(registration_);
+ DCHECK(registration_.get());
registration_->RemoveListener(this);
}
+ServiceWorkerRegistrationObjectInfo
+ServiceWorkerRegistrationHandle::GetObjectInfo() {
+ ServiceWorkerRegistrationObjectInfo info;
+ info.handle_id = handle_id_;
+ info.scope = registration_->pattern();
+ return info;
+}
+
+ServiceWorkerObjectInfo
+ServiceWorkerRegistrationHandle::CreateServiceWorkerHandleAndPass(
+ ServiceWorkerVersion* version) {
+ ServiceWorkerObjectInfo info;
+ if (context_ && version) {
+ scoped_ptr<ServiceWorkerHandle> handle =
+ ServiceWorkerHandle::Create(context_,
+ dispatcher_host_,
+ kDocumentMainThreadId,
+ provider_id_,
+ version);
+ info = handle->GetObjectInfo();
+ dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass());
+ }
+ return info;
+}
+
void ServiceWorkerRegistrationHandle::IncrementRefCount() {
DCHECK_GT(ref_count_, 0);
++ref_count_;
ClearVersionAttributes();
}
+void ServiceWorkerRegistrationHandle::OnUpdateFound(
+ ServiceWorkerRegistration* registration) {
+ if (!dispatcher_host_)
+ return; // Could be NULL in some tests.
+ dispatcher_host_->Send(new ServiceWorkerMsg_UpdateFound(
+ kDocumentMainThreadId, GetObjectInfo()));
+}
+
void ServiceWorkerRegistrationHandle::SetVersionAttributes(
ServiceWorkerVersion* installing_version,
ServiceWorkerVersion* waiting_version,
ServiceWorkerVersion* active_version) {
ChangedVersionAttributesMask mask;
- if (installing_version != installing_version_) {
+ if (installing_version != installing_version_.get()) {
installing_version_ = installing_version;
mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION);
}
- if (waiting_version != waiting_version_) {
+ if (waiting_version != waiting_version_.get()) {
waiting_version_ = waiting_version;
mask.add(ChangedVersionAttributesMask::WAITING_VERSION);
}
- if (active_version != active_version_) {
+ if (active_version != active_version_.get()) {
active_version_ = active_version;
mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION);
}
SetVersionAttributes(NULL, NULL, NULL);
}
-ServiceWorkerObjectInfo
-ServiceWorkerRegistrationHandle::CreateServiceWorkerHandleAndPass(
- ServiceWorkerVersion* version) {
- ServiceWorkerObjectInfo info;
- if (context_ && version) {
- scoped_ptr<ServiceWorkerHandle> handle =
- ServiceWorkerHandle::Create(context_,
- dispatcher_host_,
- kDocumentMainThreadId,
- provider_id_,
- version);
- info = handle->GetObjectInfo();
- dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass());
- }
- return info;
-}
-
} // namespace content