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

Unified Diff: public/platform/WebServiceWorkerCache.h

Issue 433793002: Introducing the WebServiceWorkerCache. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: partial remediation Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: public/platform/WebServiceWorkerCache.h
diff --git a/public/platform/WebServiceWorkerCache.h b/public/platform/WebServiceWorkerCache.h
new file mode 100644
index 0000000000000000000000000000000000000000..7de182265f120fe402cc5ed1e52f38565d0a6005
--- /dev/null
+++ b/public/platform/WebServiceWorkerCache.h
@@ -0,0 +1,84 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WebServiceWorkerCache_h
+#define WebServiceWorkerCache_h
+
+#include "WebCommon.h"
+#include "public/platform/WebCallbacks.h"
+#include "public/platform/WebServiceWorkerCacheError.h"
+#include "public/platform/WebServiceWorkerRequest.h"
+#include "public/platform/WebServiceWorkerResponse.h"
+#include "public/platform/WebString.h"
+#include "public/platform/WebVector.h"
+
+namespace blink {
+
+// The Service Worker Cache API. The embedder provides the implementation of the Cache to Blink. Blink uses the interface
+// to operate on entries.
+// This object is owned by Blink, and should be destroyed as each Cache instance is no longer in use.
+class WebServiceWorkerCache {
+public:
+ typedef WebCallbacks<WebServiceWorkerResponse, WebServiceWorkerCacheError> CacheMatchCallbacks;
+ typedef WebCallbacks<WebVector<WebServiceWorkerResponse>, WebServiceWorkerCacheError> CacheWithResponsesCallbacks;
+ typedef WebCallbacks<WebVector<WebServiceWorkerRequest>, WebServiceWorkerCacheError> CacheWithRequestsCallbacks;
+
+ virtual ~WebServiceWorkerCache() { }
+
+ // The ProxyInterface is used to allow a single object in Blink to serve as its interface in JavaScript; so that == will
dominicc (has gone to gerrit) 2014/08/15 06:20:24 I feel like there's redundancy here with the bit a
gavinp 2014/08/19 21:09:37 How do you like that rewrite?
+ // always test two interfaces to the same cache as equal.
+ class ProxyInterface {
+ public:
+ virtual inline ~ProxyInterface() = 0;
+ };
+
+ // Options that affect the scope of searches.
+ struct QueryParams {
+ QueryParams() : ignoreSearch(false), ignoreMethod(false), ignoreVary(false), prefixMatch(false) { }
+
+ bool ignoreSearch;
+ bool ignoreMethod;
+ bool ignoreVary;
+ bool prefixMatch;
+ };
+
+ enum WebServiceWorkerCacheOperationType {
+ WebServiceWorkerCacheOperationTypeUndefined,
+ WebServiceWorkerCacheOperationTypePut,
+ WebServiceWorkerCacheOperationTypeDelete,
+ WebServiceWorkerCacheOperationTypeLast = WebServiceWorkerCacheOperationTypeDelete
+ };
+
+ struct BatchOperation {
+ BatchOperation() : operationType(WebServiceWorkerCacheOperationTypeUndefined) { }
+
+ WebServiceWorkerCacheOperationType operationType;
+ WebServiceWorkerRequest request;
+ WebServiceWorkerResponse response;
+ QueryParams matchParams;
+ };
+
+ WebServiceWorkerCache() : m_proxyInterface(0) { }
+
+ void setProxyInterface(ProxyInterface* proxyInterface) { m_proxyInterface = proxyInterface; }
+ ProxyInterface* proxyInterface() { return m_proxyInterface; }
+
+ // Ownership of the Cache*Callbacks methods passes to the WebServiceWorkerCache instance, which will delete it after
+ // calling onSuccess or onFailure.
+ virtual void dispatchMatch(CacheMatchCallbacks*, const WebServiceWorkerRequest&, const QueryParams&) = 0;
+ virtual void dispatchMatchAll(CacheWithResponsesCallbacks*, const WebServiceWorkerRequest&, const QueryParams&) = 0;
+ virtual void dispatchKeys(CacheWithRequestsCallbacks*, const WebServiceWorkerRequest*, const QueryParams&) = 0;
+ virtual void dispatchBatch(CacheWithResponsesCallbacks*, const WebVector<BatchOperation>&) = 0;
+
+private:
+ ProxyInterface* m_proxyInterface;
+};
+
+// The pure virtual destructor makes the interface abstract, but we still want an inline destructor for descendents to call. Thus we
+// use the inline keyword and provide an out of line definition.
+inline WebServiceWorkerCache::ProxyInterface::~ProxyInterface() { }
+
+} // namespace blink
+
+#endif // WebServiceWorkerCache_h

Powered by Google App Engine
This is Rietveld 408576698