| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/cachestorage/GlobalCacheStorage.h" | 5 #include "modules/cachestorage/GlobalCacheStorage.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/frame/LocalDOMWindow.h" | 8 #include "core/frame/LocalDOMWindow.h" |
| 9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
| 10 #include "core/workers/WorkerGlobalScope.h" | 10 #include "core/workers/WorkerGlobalScope.h" |
| 11 #include "modules/cachestorage/CacheStorage.h" | 11 #include "modules/cachestorage/CacheStorage.h" |
| 12 #include "platform/Supplementable.h" | 12 #include "platform/Supplementable.h" |
| 13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 14 #include "platform/weborigin/DatabaseIdentifier.h" | 14 #include "platform/weborigin/DatabaseIdentifier.h" |
| 15 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 template <typename T> | 21 template <typename T> |
| 22 class GlobalCacheStorageImpl final : public NoBaseWillBeGarbageCollectedFinalize
d<GlobalCacheStorageImpl<T>>, public WillBeHeapSupplement<T> { | 22 class GlobalCacheStorageImpl final : public GarbageCollectedFinalized<GlobalCach
eStorageImpl<T>>, public HeapSupplement<T> { |
| 23 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalCacheStorageImpl); | 23 USING_GARBAGE_COLLECTED_MIXIN(GlobalCacheStorageImpl); |
| 24 public: | 24 public: |
| 25 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe
cutionContext) | 25 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe
cutionContext) |
| 26 { | 26 { |
| 27 GlobalCacheStorageImpl* supplement = static_cast<GlobalCacheStorageImpl*
>(WillBeHeapSupplement<T>::from(supplementable, name())); | 27 GlobalCacheStorageImpl* supplement = static_cast<GlobalCacheStorageImpl*
>(HeapSupplement<T>::from(supplementable, name())); |
| 28 if (!supplement) { | 28 if (!supplement) { |
| 29 supplement = new GlobalCacheStorageImpl(); | 29 supplement = new GlobalCacheStorageImpl(); |
| 30 WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrW
illBeNoop(supplement)); | 30 HeapSupplement<T>::provideTo(supplementable, name(), (supplement)); |
| 31 } | 31 } |
| 32 return *supplement; | 32 return *supplement; |
| 33 } | 33 } |
| 34 | 34 |
| 35 ~GlobalCacheStorageImpl() | 35 ~GlobalCacheStorageImpl() |
| 36 { | 36 { |
| 37 if (m_caches) | 37 if (m_caches) |
| 38 m_caches->dispose(); | 38 m_caches->dispose(); |
| 39 } | 39 } |
| 40 | 40 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 m_caches = CacheStorage::create(GlobalFetch::ScopedFetcher::from(fet
chingScope), Platform::current()->cacheStorage(identifier)); | 57 m_caches = CacheStorage::create(GlobalFetch::ScopedFetcher::from(fet
chingScope), Platform::current()->cacheStorage(identifier)); |
| 58 } | 58 } |
| 59 return m_caches; | 59 return m_caches; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Promptly dispose of associated CacheStorage. | 62 // Promptly dispose of associated CacheStorage. |
| 63 EAGERLY_FINALIZE(); | 63 EAGERLY_FINALIZE(); |
| 64 DEFINE_INLINE_VIRTUAL_TRACE() | 64 DEFINE_INLINE_VIRTUAL_TRACE() |
| 65 { | 65 { |
| 66 visitor->trace(m_caches); | 66 visitor->trace(m_caches); |
| 67 WillBeHeapSupplement<T>::trace(visitor); | 67 HeapSupplement<T>::trace(visitor); |
| 68 } | 68 } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 GlobalCacheStorageImpl() | 71 GlobalCacheStorageImpl() |
| 72 { | 72 { |
| 73 } | 73 } |
| 74 | 74 |
| 75 static const char* name() { return "CacheStorage"; } | 75 static const char* name() { return "CacheStorage"; } |
| 76 | 76 |
| 77 PersistentWillBeMember<CacheStorage> m_caches; | 77 Member<CacheStorage> m_caches; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 CacheStorage* GlobalCacheStorage::caches(DOMWindow& window, ExceptionState& exce
ptionState) | 82 CacheStorage* GlobalCacheStorage::caches(DOMWindow& window, ExceptionState& exce
ptionState) |
| 83 { | 83 { |
| 84 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window)
, window.executionContext()).caches(toLocalDOMWindow(window), exceptionState); | 84 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window)
, window.executionContext()).caches(toLocalDOMWindow(window), exceptionState); |
| 85 } | 85 } |
| 86 | 86 |
| 87 CacheStorage* GlobalCacheStorage::caches(WorkerGlobalScope& worker, ExceptionSta
te& exceptionState) | 87 CacheStorage* GlobalCacheStorage::caches(WorkerGlobalScope& worker, ExceptionSta
te& exceptionState) |
| 88 { | 88 { |
| 89 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut
ionContext()).caches(worker, exceptionState); | 89 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut
ionContext()).caches(worker, exceptionState); |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace blink | 92 } // namespace blink |
| OLD | NEW |