| 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 #ifndef WebServiceWorkerCacheStorage_h | 5 #ifndef WebServiceWorkerCacheStorage_h |
| 6 #define WebServiceWorkerCacheStorage_h | 6 #define WebServiceWorkerCacheStorage_h |
| 7 | 7 |
| 8 #include "public/platform/WebCallbacks.h" | 8 #include "public/platform/WebCallbacks.h" |
| 9 #include "public/platform/WebCommon.h" | 9 #include "public/platform/WebCommon.h" |
| 10 #include "public/platform/WebPassOwnPtr.h" | 10 #include "public/platform/WebPassOwnPtr.h" |
| 11 #include "public/platform/WebServiceWorkerCache.h" | 11 #include "public/platform/WebServiceWorkerCache.h" |
| 12 #include "public/platform/WebServiceWorkerCacheError.h" | 12 #include "public/platform/WebServiceWorkerCacheError.h" |
| 13 #include "public/platform/WebString.h" | 13 #include "public/platform/WebString.h" |
| 14 #include "public/platform/WebVector.h" | 14 #include "public/platform/WebVector.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class WebServiceWorkerCache; | 18 class WebServiceWorkerCache; |
| 19 | 19 |
| 20 // An interface to the CacheStorage API, implemented by the embedder and passed
in to Blink. Blink's implementation | 20 // An interface to the CacheStorage API, implemented by the embedder and passed
in to Blink. Blink's implementation |
| 21 // of the ServiceWorker spec will call these methods to create/open caches, and
expect callbacks from the embedder | 21 // of the ServiceWorker spec will call these methods to create/open caches, and
expect callbacks from the embedder |
| 22 // after operations complete. | 22 // after operations complete. |
| 23 class WebServiceWorkerCacheStorage { | 23 class WebServiceWorkerCacheStorage { |
| 24 public: | 24 public: |
| 25 class CacheStorageCallbacks : public WebCallbacks<void, WebServiceWorkerCach
eError> { | 25 using CacheStorageCallbacks = WebCallbacks<void, WebServiceWorkerCacheError>
; |
| 26 public: | 26 using CacheStorageWithCacheCallbacks = WebCallbacks<WebPassOwnPtr<WebService
WorkerCache>, WebServiceWorkerCacheError>; |
| 27 void onError(WebServiceWorkerCacheError* e) | 27 using CacheStorageKeysCallbacks = WebCallbacks<const WebVector<WebString>&,
WebServiceWorkerCacheError>; |
| 28 { | 28 using CacheStorageMatchCallbacks = WebCallbacks<const WebServiceWorkerRespon
se&, WebServiceWorkerCacheError>; |
| 29 onError(*e); | |
| 30 delete e; | |
| 31 } | |
| 32 void onError(WebServiceWorkerCacheError) override {} | |
| 33 }; | |
| 34 class CacheStorageWithCacheCallbacks : public WebCallbacks<WebPassOwnPtr<Web
ServiceWorkerCache>, WebServiceWorkerCacheError> { | |
| 35 public: | |
| 36 void onSuccess(WebServiceWorkerCache* r) | |
| 37 { | |
| 38 onSuccess(adoptWebPtr(r)); | |
| 39 } | |
| 40 void onError(WebServiceWorkerCacheError* e) | |
| 41 { | |
| 42 onError(*e); | |
| 43 delete e; | |
| 44 } | |
| 45 void onSuccess(WebPassOwnPtr<WebServiceWorkerCache>) override {} | |
| 46 void onError(WebServiceWorkerCacheError) override {} | |
| 47 }; | |
| 48 class CacheStorageKeysCallbacks : public WebCallbacks<const WebVector<WebStr
ing>&, WebServiceWorkerCacheError> { | |
| 49 public: | |
| 50 void onSuccess(WebVector<WebString>* r) { onSuccess(*r); } | |
| 51 void onError(WebServiceWorkerCacheError* e) | |
| 52 { | |
| 53 onError(*e); | |
| 54 delete e; | |
| 55 } | |
| 56 void onSuccess(const WebVector<WebString>&) override {} | |
| 57 void onError(WebServiceWorkerCacheError) override {} | |
| 58 }; | |
| 59 class CacheStorageMatchCallbacks : public WebCallbacks<const WebServiceWorke
rResponse&, WebServiceWorkerCacheError> { | |
| 60 public: | |
| 61 void onSuccess(WebServiceWorkerResponse* r) { onSuccess(*r); } | |
| 62 void onError(WebServiceWorkerCacheError* e) | |
| 63 { | |
| 64 onError(*e); | |
| 65 delete e; | |
| 66 } | |
| 67 void onSuccess(const WebServiceWorkerResponse&) override {} | |
| 68 void onError(WebServiceWorkerCacheError) override {} | |
| 69 }; | |
| 70 | 29 |
| 71 virtual ~WebServiceWorkerCacheStorage() { } | 30 virtual ~WebServiceWorkerCacheStorage() { } |
| 72 | 31 |
| 73 // Ownership of the CacheStorage*Callbacks methods passes to the WebServiceW
orkerCacheStorage instance, which | 32 // Ownership of the CacheStorage*Callbacks methods passes to the WebServiceW
orkerCacheStorage instance, which |
| 74 // will delete it after calling onSuccess or onFailure. | 33 // will delete it after calling onSuccess or onFailure. |
| 75 | 34 |
| 76 // dispatchOpen() can return a WebServiceWorkerCache object. These | 35 // dispatchOpen() can return a WebServiceWorkerCache object. These |
| 77 // objects are owned by Blink and should be destroyed when they are no | 36 // objects are owned by Blink and should be destroyed when they are no |
| 78 // longer needed. | 37 // longer needed. |
| 79 virtual void dispatchHas(CacheStorageCallbacks*, const WebString& cacheName)
= 0; | 38 virtual void dispatchHas(CacheStorageCallbacks*, const WebString& cacheName)
= 0; |
| 80 virtual void dispatchOpen(CacheStorageWithCacheCallbacks*, const WebString&
cacheName) = 0; | 39 virtual void dispatchOpen(CacheStorageWithCacheCallbacks*, const WebString&
cacheName) = 0; |
| 81 virtual void dispatchDelete(CacheStorageCallbacks*, const WebString& cacheNa
me) = 0; | 40 virtual void dispatchDelete(CacheStorageCallbacks*, const WebString& cacheNa
me) = 0; |
| 82 virtual void dispatchKeys(CacheStorageKeysCallbacks*) = 0; | 41 virtual void dispatchKeys(CacheStorageKeysCallbacks*) = 0; |
| 83 virtual void dispatchMatch(CacheStorageMatchCallbacks*, const WebServiceWork
erRequest&, const WebServiceWorkerCache::QueryParams&) = 0; | 42 virtual void dispatchMatch(CacheStorageMatchCallbacks*, const WebServiceWork
erRequest&, const WebServiceWorkerCache::QueryParams&) = 0; |
| 84 }; | 43 }; |
| 85 | 44 |
| 86 } // namespace blink | 45 } // namespace blink |
| 87 | 46 |
| 88 #endif // WebServiceWorkerCacheStorage_h | 47 #endif // WebServiceWorkerCacheStorage_h |
| OLD | NEW |