blob: 66c4f6208b2727915386b7b3a0421c7b3839ec02 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/background_fetch/service_worker_registration_background_fetch.h"
#include "third_party/blink/renderer/modules/background_fetch/background_fetch_manager.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
namespace blink {
ServiceWorkerRegistrationBackgroundFetch::
ServiceWorkerRegistrationBackgroundFetch(
ServiceWorkerRegistration* registration)
: registration_(registration) {}
ServiceWorkerRegistrationBackgroundFetch::
~ServiceWorkerRegistrationBackgroundFetch() = default;
const char ServiceWorkerRegistrationBackgroundFetch::kSupplementName[] =
"ServiceWorkerRegistrationBackgroundFetch";
ServiceWorkerRegistrationBackgroundFetch&
ServiceWorkerRegistrationBackgroundFetch::From(
ServiceWorkerRegistration& registration) {
ServiceWorkerRegistrationBackgroundFetch* supplement =
Supplement<ServiceWorkerRegistration>::From<
ServiceWorkerRegistrationBackgroundFetch>(registration);
if (!supplement) {
supplement = MakeGarbageCollected<ServiceWorkerRegistrationBackgroundFetch>(
&registration);
ProvideTo(registration, supplement);
}
return *supplement;
}
BackgroundFetchManager*
ServiceWorkerRegistrationBackgroundFetch::backgroundFetch(
ServiceWorkerRegistration& registration) {
return ServiceWorkerRegistrationBackgroundFetch::From(registration)
.backgroundFetch();
}
BackgroundFetchManager*
ServiceWorkerRegistrationBackgroundFetch::backgroundFetch() {
if (!background_fetch_manager_) {
background_fetch_manager_ =
MakeGarbageCollected<BackgroundFetchManager>(registration_);
}
return background_fetch_manager_.Get();
}
void ServiceWorkerRegistrationBackgroundFetch::Trace(Visitor* visitor) const {
visitor->Trace(registration_);
visitor->Trace(background_fetch_manager_);
Supplement<ServiceWorkerRegistration>::Trace(visitor);
}
} // namespace blink