summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc
blob: 95add2a4b3b89bff0065eb88f7ca1c4c90e62b88 (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
63
64
65
66
67
68
// Copyright 2016 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/indexeddb/global_indexed_db.h"

#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/modules/indexeddb/idb_factory.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"

namespace blink {

namespace {

template <typename T>
class GlobalIndexedDBImpl final
    : public GarbageCollected<GlobalIndexedDBImpl<T>>,
      public Supplement<T> {
  USING_GARBAGE_COLLECTED_MIXIN(GlobalIndexedDBImpl);

 public:
  static const char kSupplementName[];

  static GlobalIndexedDBImpl& From(T& supplementable) {
    GlobalIndexedDBImpl* supplement =
        Supplement<T>::template From<GlobalIndexedDBImpl>(supplementable);
    if (!supplement) {
      supplement = MakeGarbageCollected<GlobalIndexedDBImpl>();
      Supplement<T>::ProvideTo(supplementable, supplement);
    }
    return *supplement;
  }

  GlobalIndexedDBImpl() = default;

  IDBFactory* IdbFactory(T& fetching_scope) {
    if (!idb_factory_)
      idb_factory_ = MakeGarbageCollected<IDBFactory>();
    return idb_factory_;
  }

  void Trace(Visitor* visitor) const override {
    visitor->Trace(idb_factory_);
    Supplement<T>::Trace(visitor);
  }

 private:
  Member<IDBFactory> idb_factory_;
};

// static
template <typename T>
const char GlobalIndexedDBImpl<T>::kSupplementName[] = "GlobalIndexedDBImpl";

}  // namespace

IDBFactory* GlobalIndexedDB::indexedDB(LocalDOMWindow& window) {
  return GlobalIndexedDBImpl<LocalDOMWindow>::From(window).IdbFactory(window);
}

IDBFactory* GlobalIndexedDB::indexedDB(WorkerGlobalScope& worker) {
  return GlobalIndexedDBImpl<WorkerGlobalScope>::From(worker).IdbFactory(
      worker);
}

}  // namespace blink