| OLD | NEW |
| 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" |
| 11 #include "core/inspector/ConsoleMessage.h" | 11 #include "core/inspector/ConsoleMessage.h" |
| 12 #include "modules/cachestorage/CacheStorageError.h" | 12 #include "modules/cachestorage/CacheStorageError.h" |
| 13 #include "modules/fetch/Request.h" | 13 #include "modules/fetch/Request.h" |
| 14 #include "modules/fetch/Response.h" | 14 #include "modules/fetch/Response.h" |
| 15 #include "platform/RuntimeEnabledFeatures.h" | 15 #include "platform/RuntimeEnabledFeatures.h" |
| 16 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheError.h" | 16 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheError.h" |
| 17 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheStorage.h" | 17 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheStorage.h" |
| 18 #include "wtf/PtrUtil.h" | |
| 19 #include <memory> | |
| 20 | 18 |
| 21 namespace blink { | 19 namespace blink { |
| 22 | 20 |
| 23 namespace { | 21 namespace { |
| 24 | 22 |
| 25 DOMException* createNoImplementationException() | 23 DOMException* createNoImplementationException() |
| 26 { | 24 { |
| 27 return DOMException::create(NotSupportedError, "No CacheStorage implementati
on provided."); | 25 return DOMException::create(NotSupportedError, "No CacheStorage implementati
on provided."); |
| 28 } | 26 } |
| 29 | 27 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 WTF_MAKE_NONCOPYABLE(WithCacheCallbacks); | 88 WTF_MAKE_NONCOPYABLE(WithCacheCallbacks); |
| 91 public: | 89 public: |
| 92 WithCacheCallbacks(const String& cacheName, CacheStorage* cacheStorage, Scri
ptPromiseResolver* resolver) | 90 WithCacheCallbacks(const String& cacheName, CacheStorage* cacheStorage, Scri
ptPromiseResolver* resolver) |
| 93 : m_cacheName(cacheName), m_cacheStorage(cacheStorage), m_resolver(resol
ver) { } | 91 : m_cacheName(cacheName), m_cacheStorage(cacheStorage), m_resolver(resol
ver) { } |
| 94 ~WithCacheCallbacks() override { } | 92 ~WithCacheCallbacks() override { } |
| 95 | 93 |
| 96 void onSuccess(std::unique_ptr<WebServiceWorkerCache> webCache) override | 94 void onSuccess(std::unique_ptr<WebServiceWorkerCache> webCache) override |
| 97 { | 95 { |
| 98 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 96 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 99 return; | 97 return; |
| 100 Cache* cache = Cache::create(m_cacheStorage->m_scopedFetcher, wrapUnique
(webCache.release())); | 98 Cache* cache = Cache::create(m_cacheStorage->m_scopedFetcher, adoptPtr(w
ebCache.release())); |
| 101 m_cacheStorage->m_nameToCacheMap.set(m_cacheName, cache); | 99 m_cacheStorage->m_nameToCacheMap.set(m_cacheName, cache); |
| 102 m_resolver->resolve(cache); | 100 m_resolver->resolve(cache); |
| 103 m_resolver.clear(); | 101 m_resolver.clear(); |
| 104 } | 102 } |
| 105 | 103 |
| 106 void onError(WebServiceWorkerCacheError reason) override | 104 void onError(WebServiceWorkerCacheError reason) override |
| 107 { | 105 { |
| 108 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 106 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 109 return; | 107 return; |
| 110 if (reason == WebServiceWorkerCacheErrorNotFound) | 108 if (reason == WebServiceWorkerCacheErrorNotFound) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 m_resolver->reject(CacheStorageError::createException(reason)); | 209 m_resolver->reject(CacheStorageError::createException(reason)); |
| 212 m_resolver.clear(); | 210 m_resolver.clear(); |
| 213 } | 211 } |
| 214 | 212 |
| 215 private: | 213 private: |
| 216 Persistent<ScriptPromiseResolver> m_resolver; | 214 Persistent<ScriptPromiseResolver> m_resolver; |
| 217 }; | 215 }; |
| 218 | 216 |
| 219 CacheStorage* CacheStorage::create(GlobalFetch::ScopedFetcher* fetcher, WebServi
ceWorkerCacheStorage* webCacheStorage) | 217 CacheStorage* CacheStorage::create(GlobalFetch::ScopedFetcher* fetcher, WebServi
ceWorkerCacheStorage* webCacheStorage) |
| 220 { | 218 { |
| 221 return new CacheStorage(fetcher, wrapUnique(webCacheStorage)); | 219 return new CacheStorage(fetcher, adoptPtr(webCacheStorage)); |
| 222 } | 220 } |
| 223 | 221 |
| 224 ScriptPromise CacheStorage::open(ScriptState* scriptState, const String& cacheNa
me, ExceptionState& exceptionState) | 222 ScriptPromise CacheStorage::open(ScriptState* scriptState, const String& cacheNa
me, ExceptionState& exceptionState) |
| 225 { | 223 { |
| 226 if (!commonChecks(scriptState, exceptionState)) | 224 if (!commonChecks(scriptState, exceptionState)) |
| 227 return ScriptPromise(); | 225 return ScriptPromise(); |
| 228 | 226 |
| 229 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 227 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 230 const ScriptPromise promise = resolver->promise(); | 228 const ScriptPromise promise = resolver->promise(); |
| 231 | 229 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 const ScriptPromise promise = resolver->promise(); | 318 const ScriptPromise promise = resolver->promise(); |
| 321 | 319 |
| 322 if (m_webCacheStorage) | 320 if (m_webCacheStorage) |
| 323 m_webCacheStorage->dispatchMatch(new MatchCallbacks(resolver), webReques
t, Cache::toWebQueryParams(options)); | 321 m_webCacheStorage->dispatchMatch(new MatchCallbacks(resolver), webReques
t, Cache::toWebQueryParams(options)); |
| 324 else | 322 else |
| 325 resolver->reject(createNoImplementationException()); | 323 resolver->reject(createNoImplementationException()); |
| 326 | 324 |
| 327 return promise; | 325 return promise; |
| 328 } | 326 } |
| 329 | 327 |
| 330 CacheStorage::CacheStorage(GlobalFetch::ScopedFetcher* fetcher, std::unique_ptr<
WebServiceWorkerCacheStorage> webCacheStorage) | 328 CacheStorage::CacheStorage(GlobalFetch::ScopedFetcher* fetcher, PassOwnPtr<WebSe
rviceWorkerCacheStorage> webCacheStorage) |
| 331 : m_scopedFetcher(fetcher) | 329 : m_scopedFetcher(fetcher) |
| 332 , m_webCacheStorage(std::move(webCacheStorage)) | 330 , m_webCacheStorage(std::move(webCacheStorage)) |
| 333 { | 331 { |
| 334 } | 332 } |
| 335 | 333 |
| 336 CacheStorage::~CacheStorage() | 334 CacheStorage::~CacheStorage() |
| 337 { | 335 { |
| 338 } | 336 } |
| 339 | 337 |
| 340 void CacheStorage::dispose() | 338 void CacheStorage::dispose() |
| 341 { | 339 { |
| 342 m_webCacheStorage.reset(); | 340 m_webCacheStorage.reset(); |
| 343 } | 341 } |
| 344 | 342 |
| 345 DEFINE_TRACE(CacheStorage) | 343 DEFINE_TRACE(CacheStorage) |
| 346 { | 344 { |
| 347 visitor->trace(m_scopedFetcher); | 345 visitor->trace(m_scopedFetcher); |
| 348 visitor->trace(m_nameToCacheMap); | 346 visitor->trace(m_nameToCacheMap); |
| 349 } | 347 } |
| 350 | 348 |
| 351 } // namespace blink | 349 } // namespace blink |
| OLD | NEW |