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