Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / modules / serviceworker / WebServiceWorkerCache.h
blob5417b2239c7162960b45f3b932a5cf319289a5fe
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
3 // found in the LICENSE file.
5 #ifndef WebServiceWorkerCache_h
6 #define WebServiceWorkerCache_h
8 #include "public/platform/WebCallbacks.h"
9 #include "public/platform/WebCommon.h"
10 #include "public/platform/WebServiceWorkerCacheError.h"
11 #include "public/platform/WebServiceWorkerRequest.h"
12 #include "public/platform/WebServiceWorkerResponse.h"
13 #include "public/platform/WebString.h"
14 #include "public/platform/WebVector.h"
16 namespace blink {
18 // The Service Worker Cache API. The embedder provides the implementation of the Cache to Blink. Blink uses the interface
19 // to operate on entries.
20 // This object is owned by Blink, and should be destroyed as each Cache instance is no longer in use.
21 class WebServiceWorkerCache {
22 public:
23 using CacheMatchCallbacks = WebCallbacks<const WebServiceWorkerResponse&, WebServiceWorkerCacheError>;
24 using CacheWithResponsesCallbacks = WebCallbacks<const WebVector<WebServiceWorkerResponse>&, WebServiceWorkerCacheError>;
25 using CacheWithRequestsCallbacks = WebCallbacks<const WebVector<WebServiceWorkerRequest>&, WebServiceWorkerCacheError>;
26 using CacheBatchCallbacks = WebCallbacks<void, WebServiceWorkerCacheError>;
28 virtual ~WebServiceWorkerCache() { }
30 // Options that affect the scope of searches.
31 struct QueryParams {
32 QueryParams() : ignoreSearch(false), ignoreMethod(false), ignoreVary(false) { }
34 bool ignoreSearch;
35 bool ignoreMethod;
36 bool ignoreVary;
37 WebString cacheName;
40 enum OperationType {
41 OperationTypeUndefined,
42 OperationTypePut,
43 OperationTypeDelete,
44 OperationTypeLast = OperationTypeDelete
47 struct BatchOperation {
48 BatchOperation() : operationType(OperationTypeUndefined) { }
50 OperationType operationType;
51 WebServiceWorkerRequest request;
52 WebServiceWorkerResponse response;
53 QueryParams matchParams;
56 WebServiceWorkerCache() { }
58 // Ownership of the Cache*Callbacks methods passes to the WebServiceWorkerCache instance, which will delete it after
59 // calling onSuccess or onFailure.
60 virtual void dispatchMatch(CacheMatchCallbacks*, const WebServiceWorkerRequest&, const QueryParams&) = 0;
61 virtual void dispatchMatchAll(CacheWithResponsesCallbacks*, const WebServiceWorkerRequest&, const QueryParams&) = 0;
62 virtual void dispatchKeys(CacheWithRequestsCallbacks*, const WebServiceWorkerRequest*, const QueryParams&) = 0;
63 virtual void dispatchBatch(CacheBatchCallbacks*, const WebVector<BatchOperation>&) = 0;
66 } // namespace blink
68 #endif // WebServiceWorkerCache_h