Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_registration_handle.cc
blob42fe249dc2f1c0db5e487493df37ec5b1336e2aa
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
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_registration_handle.h"
7 #include "content/browser/service_worker/service_worker_context_core.h"
8 #include "content/browser/service_worker/service_worker_handle.h"
9 #include "content/common/service_worker/service_worker_messages.h"
10 #include "content/common/service_worker/service_worker_types.h"
12 namespace content {
14 ServiceWorkerRegistrationHandle::ServiceWorkerRegistrationHandle(
15 base::WeakPtr<ServiceWorkerContextCore> context,
16 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
17 ServiceWorkerRegistration* registration)
18 : context_(context),
19 provider_host_(provider_host),
20 provider_id_(provider_host ? provider_host->provider_id()
21 : kInvalidServiceWorkerProviderId),
22 handle_id_(context ? context->GetNewRegistrationHandleId()
23 : kInvalidServiceWorkerRegistrationHandleId),
24 ref_count_(1),
25 registration_(registration) {
26 DCHECK(registration_.get());
27 ChangedVersionAttributesMask changed_mask;
28 if (registration->installing_version())
29 changed_mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION);
30 if (registration->waiting_version())
31 changed_mask.add(ChangedVersionAttributesMask::WAITING_VERSION);
32 if (registration->active_version())
33 changed_mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION);
34 SetVersionAttributes(changed_mask,
35 registration->installing_version(),
36 registration->waiting_version(),
37 registration->active_version());
38 registration_->AddListener(this);
41 ServiceWorkerRegistrationHandle::~ServiceWorkerRegistrationHandle() {
42 DCHECK(registration_.get());
43 registration_->RemoveListener(this);
46 ServiceWorkerRegistrationObjectInfo
47 ServiceWorkerRegistrationHandle::GetObjectInfo() {
48 ServiceWorkerRegistrationObjectInfo info;
49 info.handle_id = handle_id_;
50 info.scope = registration_->pattern();
51 info.registration_id = registration_->id();
52 return info;
55 void ServiceWorkerRegistrationHandle::IncrementRefCount() {
56 DCHECK_GT(ref_count_, 0);
57 ++ref_count_;
60 void ServiceWorkerRegistrationHandle::DecrementRefCount() {
61 DCHECK_GT(ref_count_, 0);
62 --ref_count_;
65 void ServiceWorkerRegistrationHandle::OnVersionAttributesChanged(
66 ServiceWorkerRegistration* registration,
67 ChangedVersionAttributesMask changed_mask,
68 const ServiceWorkerRegistrationInfo& info) {
69 DCHECK_EQ(registration->id(), registration_->id());
70 SetVersionAttributes(changed_mask,
71 registration->installing_version(),
72 registration->waiting_version(),
73 registration->active_version());
76 void ServiceWorkerRegistrationHandle::OnRegistrationFailed(
77 ServiceWorkerRegistration* registration) {
78 DCHECK_EQ(registration->id(), registration_->id());
79 ChangedVersionAttributesMask changed_mask(
80 ChangedVersionAttributesMask::INSTALLING_VERSION |
81 ChangedVersionAttributesMask::WAITING_VERSION |
82 ChangedVersionAttributesMask::ACTIVE_VERSION);
83 SetVersionAttributes(changed_mask, nullptr, nullptr, nullptr);
86 void ServiceWorkerRegistrationHandle::OnUpdateFound(
87 ServiceWorkerRegistration* registration) {
88 if (!provider_host_)
89 return; // Could be nullptr in some tests.
90 provider_host_->SendUpdateFoundMessage(handle_id_);
93 void ServiceWorkerRegistrationHandle::SetVersionAttributes(
94 ChangedVersionAttributesMask changed_mask,
95 ServiceWorkerVersion* installing_version,
96 ServiceWorkerVersion* waiting_version,
97 ServiceWorkerVersion* active_version) {
98 if (!provider_host_)
99 return; // Could be nullptr in some tests.
100 provider_host_->SendSetVersionAttributesMessage(handle_id_,
101 changed_mask,
102 installing_version,
103 waiting_version,
104 active_version);
107 } // namespace content