Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Side by Side Diff: Source/modules/cachestorage/GlobalCacheStorage.cpp

Issue 1183373006: Promptly finalize CacheStorage's embedder object. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/cachestorage/CacheStorage.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "modules/cachestorage/GlobalCacheStorage.h" 6 #include "modules/cachestorage/GlobalCacheStorage.h"
7 7
8 #include "core/dom/ExecutionContext.h" 8 #include "core/dom/ExecutionContext.h"
9 #include "core/frame/LocalDOMWindow.h" 9 #include "core/frame/LocalDOMWindow.h"
10 #include "core/frame/UseCounter.h" 10 #include "core/frame/UseCounter.h"
(...skipping 15 matching lines...) Expand all
26 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe cutionContext) 26 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe cutionContext)
27 { 27 {
28 GlobalCacheStorageImpl* supplement = static_cast<GlobalCacheStorageImpl* >(WillBeHeapSupplement<T>::from(supplementable, name())); 28 GlobalCacheStorageImpl* supplement = static_cast<GlobalCacheStorageImpl* >(WillBeHeapSupplement<T>::from(supplementable, name()));
29 if (!supplement) { 29 if (!supplement) {
30 supplement = new GlobalCacheStorageImpl(); 30 supplement = new GlobalCacheStorageImpl();
31 WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrW illBeNoop(supplement)); 31 WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrW illBeNoop(supplement));
32 } 32 }
33 return *supplement; 33 return *supplement;
34 } 34 }
35 35
36 ~GlobalCacheStorageImpl()
37 {
38 if (m_caches)
39 m_caches->dispose();
40 }
41
36 CacheStorage* caches(T& fetchingScope, ExceptionState& exceptionState) 42 CacheStorage* caches(T& fetchingScope, ExceptionState& exceptionState)
37 { 43 {
38 ExecutionContext* context = fetchingScope.executionContext(); 44 ExecutionContext* context = fetchingScope.executionContext();
39 if (!context->securityOrigin()->canAccessCacheStorage()) { 45 if (!context->securityOrigin()->canAccessCacheStorage()) {
40 if (context->securityContext().isSandboxed(SandboxOrigin)) 46 if (context->securityContext().isSandboxed(SandboxOrigin))
41 exceptionState.throwSecurityError("Cache storage is disabled bec ause the context is sandboxed and lacks the 'allow-same-origin' flag."); 47 exceptionState.throwSecurityError("Cache storage is disabled bec ause the context is sandboxed and lacks the 'allow-same-origin' flag.");
42 else if (context->url().protocolIs("data")) 48 else if (context->url().protocolIs("data"))
43 exceptionState.throwSecurityError("Cache storage is disabled ins ide 'data:' URLs."); 49 exceptionState.throwSecurityError("Cache storage is disabled ins ide 'data:' URLs.");
44 else 50 else
45 exceptionState.throwSecurityError("Access to cache storage is de nied."); 51 exceptionState.throwSecurityError("Access to cache storage is de nied.");
46 return nullptr; 52 return nullptr;
47 } 53 }
48 54
49 if (!m_caches) { 55 if (!m_caches) {
50 String identifier = createDatabaseIdentifierFromSecurityOrigin(conte xt->securityOrigin()); 56 String identifier = createDatabaseIdentifierFromSecurityOrigin(conte xt->securityOrigin());
51 ASSERT(!identifier.isEmpty()); 57 ASSERT(!identifier.isEmpty());
52 m_caches = CacheStorage::create(GlobalFetch::ScopedFetcher::from(fet chingScope), Platform::current()->cacheStorage(identifier)); 58 m_caches = CacheStorage::create(GlobalFetch::ScopedFetcher::from(fet chingScope), Platform::current()->cacheStorage(identifier));
53 } 59 }
54 return m_caches; 60 return m_caches;
55 } 61 }
56 62
63 // Promptly dispose of associated CacheStorage.
64 EAGERLY_FINALIZE();
57 DEFINE_INLINE_VIRTUAL_TRACE() 65 DEFINE_INLINE_VIRTUAL_TRACE()
58 { 66 {
59 visitor->trace(m_caches); 67 visitor->trace(m_caches);
60 WillBeHeapSupplement<T>::trace(visitor); 68 WillBeHeapSupplement<T>::trace(visitor);
61 } 69 }
62 70
63 private: 71 private:
64 GlobalCacheStorageImpl() 72 GlobalCacheStorageImpl()
65 { 73 {
66 } 74 }
67 75
68 static const char* name() { return "CacheStorage"; } 76 static const char* name() { return "CacheStorage"; }
69 77
70 PersistentWillBeMember<CacheStorage> m_caches; 78 PersistentWillBeMember<CacheStorage> m_caches;
71 }; 79 };
72 80
73 } // namespace 81 } // namespace
74 82
75 CacheStorage* GlobalCacheStorage::caches(DOMWindow& window, ExceptionState& exce ptionState) 83 CacheStorage* GlobalCacheStorage::caches(DOMWindow& window, ExceptionState& exce ptionState)
76 { 84 {
77 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window) , window.executionContext()).caches(toLocalDOMWindow(window), exceptionState); 85 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window) , window.executionContext()).caches(toLocalDOMWindow(window), exceptionState);
78 } 86 }
79 87
80 CacheStorage* GlobalCacheStorage::caches(WorkerGlobalScope& worker, ExceptionSta te& exceptionState) 88 CacheStorage* GlobalCacheStorage::caches(WorkerGlobalScope& worker, ExceptionSta te& exceptionState)
81 { 89 {
82 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut ionContext()).caches(worker, exceptionState); 90 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut ionContext()).caches(worker, exceptionState);
83 } 91 }
84 92
85 } // namespace blink 93 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/cachestorage/CacheStorage.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698