summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/background_fetch/service_worker_registration_background_fetch.cc
blob: d09a081ffdc8ea679f97561ddade74419cced050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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) {
  visitor->Trace(registration_);
  visitor->Trace(background_fetch_manager_);
  Supplement<ServiceWorkerRegistration>::Trace(visitor);
}

}  // namespace blink