| Index: content/browser/service_worker/service_worker_cache.h
|
| diff --git a/content/browser/service_worker/service_worker_cache.h b/content/browser/service_worker/service_worker_cache.h
|
| index 6956cc1f78cf708124b02130cbc70f1435af9b3e..6eac2a74940b2588a841fa22aafb3bc709fae3c9 100644
|
| --- a/content/browser/service_worker/service_worker_cache.h
|
| +++ b/content/browser/service_worker/service_worker_cache.h
|
| @@ -8,28 +8,44 @@
|
| #include "base/callback.h"
|
| #include "base/files/file_path.h"
|
| #include "base/memory/weak_ptr.h"
|
| +#include "content/common/service_worker/service_worker_types.h"
|
| +#include "net/base/completion_callback.h"
|
| +#include "net/disk_cache/disk_cache.h"
|
|
|
| namespace net {
|
| class URLRequestContext;
|
| +class IOBufferWithSize;
|
| }
|
|
|
| namespace storage {
|
| +class BlobData;
|
| +class BlobDataHandle;
|
| class BlobStorageContext;
|
| }
|
|
|
| namespace content {
|
| +class ChromeBlobStorageContext;
|
|
|
| -// TODO(jkarlin): Fill this in with a real Cache implementation as
|
| -// specified in
|
| -// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html.
|
| // TODO(jkarlin): Unload cache backend from memory once the cache object is no
|
| // longer referenced in javascript.
|
|
|
| // Represents a ServiceWorker Cache as seen in
|
| // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html.
|
| // InitializeIfNeeded must be called before calling the other public members.
|
| -class ServiceWorkerCache {
|
| +class CONTENT_EXPORT ServiceWorkerCache {
|
| public:
|
| + enum ErrorType {
|
| + ErrorTypeOK = 0,
|
| + ErrorTypeExists,
|
| + ErrorTypeStorage,
|
| + ErrorTypeNotFound
|
| + };
|
| + enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY };
|
| + typedef base::Callback<void(ErrorType)> ErrorCallback;
|
| + typedef base::Callback<void(ErrorType,
|
| + scoped_ptr<ServiceWorkerResponse>,
|
| + scoped_ptr<storage::BlobDataHandle>)>
|
| + ResponseCallback;
|
| static scoped_ptr<ServiceWorkerCache> CreateMemoryCache(
|
| const std::string& name,
|
| net::URLRequestContext* request_context,
|
| @@ -44,9 +60,34 @@ class ServiceWorkerCache {
|
|
|
| // Loads the backend and calls the callback with the result (true for
|
| // success). This must be called before member functions that require a
|
| - // backend are called.
|
| - void CreateBackend(const base::Callback<void(bool)>& callback);
|
| -
|
| + // backend are called. The callback will always be called.
|
| + void CreateBackend(const ErrorCallback& callback);
|
| +
|
| + // Returns ErrorTypeNotFound if not found. The callback will always be called.
|
| + // |request| must remain valid until the callback is called.
|
| + void Match(ServiceWorkerFetchRequest* request,
|
| + const ResponseCallback& callback);
|
| +
|
| + // Puts the request and response object in the cache. The response body (if
|
| + // present) is stored in the cache, but not the request body. Returns
|
| + // ErrorTypeOK on success. The callback will always be called. |request| and
|
| + // |response| must remain valid until the callback is called.
|
| + void Put(ServiceWorkerFetchRequest* request,
|
| + ServiceWorkerResponse* response,
|
| + const ErrorCallback& callback);
|
| +
|
| + // Returns ErrorNotFound if not found. Otherwise deletes and returns
|
| + // ErrorTypeOK. The callback will always be called. |request| must remain
|
| + // valid until the callback is called.
|
| + void Delete(ServiceWorkerFetchRequest* request,
|
| + const ErrorCallback& callback);
|
| +
|
| + // Call to determine if CreateBackend must be called.
|
| + bool HasCreatedBackend() const;
|
| +
|
| + void set_backend(scoped_ptr<disk_cache::Backend> backend) {
|
| + backend_ = backend.Pass();
|
| + }
|
| void set_name(const std::string& name) { name_ = name; }
|
| const std::string& name() const { return name_; }
|
| int32 id() const { return id_; }
|
| @@ -60,6 +101,7 @@ class ServiceWorkerCache {
|
| net::URLRequestContext* request_context,
|
| base::WeakPtr<storage::BlobStorageContext> blob_context);
|
|
|
| + scoped_ptr<disk_cache::Backend> backend_;
|
| base::FilePath path_;
|
| std::string name_;
|
| net::URLRequestContext* request_context_;
|
|
|