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

Side by Side Diff: third_party/WebKit/Source/modules/cachestorage/CacheStorage.cpp

Issue 2270413003: [CacheStorage] Don't store open caches in Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/modules/cachestorage/CacheStorage.h ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/CacheStorage.h" 5 #include "modules/cachestorage/CacheStorage.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 public: 80 public:
81 WithCacheCallbacks(const String& cacheName, CacheStorage* cacheStorage, Scri ptPromiseResolver* resolver) 81 WithCacheCallbacks(const String& cacheName, CacheStorage* cacheStorage, Scri ptPromiseResolver* resolver)
82 : m_cacheName(cacheName), m_cacheStorage(cacheStorage), m_resolver(resol ver) { } 82 : m_cacheName(cacheName), m_cacheStorage(cacheStorage), m_resolver(resol ver) { }
83 ~WithCacheCallbacks() override { } 83 ~WithCacheCallbacks() override { }
84 84
85 void onSuccess(std::unique_ptr<WebServiceWorkerCache> webCache) override 85 void onSuccess(std::unique_ptr<WebServiceWorkerCache> webCache) override
86 { 86 {
87 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 87 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
88 return; 88 return;
89 Cache* cache = Cache::create(m_cacheStorage->m_scopedFetcher, wrapUnique (webCache.release())); 89 Cache* cache = Cache::create(m_cacheStorage->m_scopedFetcher, wrapUnique (webCache.release()));
90 m_cacheStorage->m_nameToCacheMap.set(m_cacheName, cache);
91 m_resolver->resolve(cache); 90 m_resolver->resolve(cache);
92 m_resolver.clear(); 91 m_resolver.clear();
93 } 92 }
94 93
95 void onError(WebServiceWorkerCacheError reason) override 94 void onError(WebServiceWorkerCacheError reason) override
96 { 95 {
97 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 96 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
98 return; 97 return;
99 if (reason == WebServiceWorkerCacheErrorNotFound) 98 if (reason == WebServiceWorkerCacheErrorNotFound)
100 m_resolver->resolve(); 99 m_resolver->resolve();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // FIXME: Consider using CallbackPromiseAdapter. 143 // FIXME: Consider using CallbackPromiseAdapter.
145 class CacheStorage::DeleteCallbacks final : public WebServiceWorkerCacheStorage: :CacheStorageCallbacks { 144 class CacheStorage::DeleteCallbacks final : public WebServiceWorkerCacheStorage: :CacheStorageCallbacks {
146 WTF_MAKE_NONCOPYABLE(DeleteCallbacks); 145 WTF_MAKE_NONCOPYABLE(DeleteCallbacks);
147 public: 146 public:
148 DeleteCallbacks(const String& cacheName, CacheStorage* cacheStorage, ScriptP romiseResolver* resolver) 147 DeleteCallbacks(const String& cacheName, CacheStorage* cacheStorage, ScriptP romiseResolver* resolver)
149 : m_cacheName(cacheName), m_cacheStorage(cacheStorage), m_resolver(resol ver) { } 148 : m_cacheName(cacheName), m_cacheStorage(cacheStorage), m_resolver(resol ver) { }
150 ~DeleteCallbacks() override { } 149 ~DeleteCallbacks() override { }
151 150
152 void onSuccess() override 151 void onSuccess() override
153 { 152 {
154 m_cacheStorage->m_nameToCacheMap.remove(m_cacheName);
155 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 153 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
156 return; 154 return;
157 m_resolver->resolve(true); 155 m_resolver->resolve(true);
158 m_resolver.clear(); 156 m_resolver.clear();
159 } 157 }
160 158
161 void onError(WebServiceWorkerCacheError reason) override 159 void onError(WebServiceWorkerCacheError reason) override
162 { 160 {
163 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 161 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
164 return; 162 return;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 210 }
213 211
214 ScriptPromise CacheStorage::open(ScriptState* scriptState, const String& cacheNa me, ExceptionState& exceptionState) 212 ScriptPromise CacheStorage::open(ScriptState* scriptState, const String& cacheNa me, ExceptionState& exceptionState)
215 { 213 {
216 if (!commonChecks(scriptState, exceptionState)) 214 if (!commonChecks(scriptState, exceptionState))
217 return ScriptPromise(); 215 return ScriptPromise();
218 216
219 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 217 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
220 const ScriptPromise promise = resolver->promise(); 218 const ScriptPromise promise = resolver->promise();
221 219
222 if (m_nameToCacheMap.contains(cacheName)) {
223 Cache* cache = m_nameToCacheMap.find(cacheName)->value;
224 resolver->resolve(cache);
225 return promise;
226 }
227
228 if (m_webCacheStorage) 220 if (m_webCacheStorage)
229 m_webCacheStorage->dispatchOpen(new WithCacheCallbacks(cacheName, this, resolver), cacheName); 221 m_webCacheStorage->dispatchOpen(new WithCacheCallbacks(cacheName, this, resolver), cacheName);
230 else 222 else
231 resolver->reject(createNoImplementationException()); 223 resolver->reject(createNoImplementationException());
232 224
233 return promise; 225 return promise;
234 } 226 }
235 227
236 ScriptPromise CacheStorage::has(ScriptState* scriptState, const String& cacheNam e, ExceptionState& exceptionState) 228 ScriptPromise CacheStorage::has(ScriptState* scriptState, const String& cacheNam e, ExceptionState& exceptionState)
237 { 229 {
238 if (!commonChecks(scriptState, exceptionState)) 230 if (!commonChecks(scriptState, exceptionState))
239 return ScriptPromise(); 231 return ScriptPromise();
240 232
241 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 233 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
242 const ScriptPromise promise = resolver->promise(); 234 const ScriptPromise promise = resolver->promise();
243 235
244 if (m_nameToCacheMap.contains(cacheName)) {
245 resolver->resolve(true);
246 return promise;
247 }
248
249 if (m_webCacheStorage) 236 if (m_webCacheStorage)
250 m_webCacheStorage->dispatchHas(new Callbacks(resolver), cacheName); 237 m_webCacheStorage->dispatchHas(new Callbacks(resolver), cacheName);
251 else 238 else
252 resolver->reject(createNoImplementationException()); 239 resolver->reject(createNoImplementationException());
253 240
254 return promise; 241 return promise;
255 } 242 }
256 243
257 ScriptPromise CacheStorage::deleteFunction(ScriptState* scriptState, const Strin g& cacheName, ExceptionState& exceptionState) 244 ScriptPromise CacheStorage::deleteFunction(ScriptState* scriptState, const Strin g& cacheName, ExceptionState& exceptionState)
258 { 245 {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 319 }
333 320
334 void CacheStorage::dispose() 321 void CacheStorage::dispose()
335 { 322 {
336 m_webCacheStorage.reset(); 323 m_webCacheStorage.reset();
337 } 324 }
338 325
339 DEFINE_TRACE(CacheStorage) 326 DEFINE_TRACE(CacheStorage)
340 { 327 {
341 visitor->trace(m_scopedFetcher); 328 visitor->trace(m_scopedFetcher);
342 visitor->trace(m_nameToCacheMap);
343 } 329 }
344 330
345 } // namespace blink 331 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/cachestorage/CacheStorage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698