// 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 class GlobalIndexedDBImpl final : public GarbageCollected>, public Supplement { USING_GARBAGE_COLLECTED_MIXIN(GlobalIndexedDBImpl); public: static const char kSupplementName[]; static GlobalIndexedDBImpl& From(T& supplementable) { GlobalIndexedDBImpl* supplement = Supplement::template From(supplementable); if (!supplement) { supplement = MakeGarbageCollected(); Supplement::ProvideTo(supplementable, supplement); } return *supplement; } GlobalIndexedDBImpl() = default; IDBFactory* IdbFactory(T& fetching_scope) { if (!idb_factory_) idb_factory_ = MakeGarbageCollected(); return idb_factory_; } void Trace(Visitor* visitor) const override { visitor->Trace(idb_factory_); Supplement::Trace(visitor); } private: Member idb_factory_; }; // static template const char GlobalIndexedDBImpl::kSupplementName[] = "GlobalIndexedDBImpl"; } // namespace IDBFactory* GlobalIndexedDB::indexedDB(LocalDOMWindow& window) { return GlobalIndexedDBImpl::From(window).IdbFactory(window); } IDBFactory* GlobalIndexedDB::indexedDB(WorkerGlobalScope& worker) { return GlobalIndexedDBImpl::From(worker).IdbFactory( worker); } } // namespace blink