| 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 eb74c98ec98c378f52165c5ee0d653dd11094680..bb522917af4b9c26d2c09fa7571a0d962df01d05 100644
|
| --- a/content/browser/service_worker/service_worker_cache.h
|
| +++ b/content/browser/service_worker/service_worker_cache.h
|
| @@ -7,6 +7,7 @@
|
|
|
| #include "base/callback.h"
|
| #include "base/files/file_path.h"
|
| +#include "base/memory/ref_counted.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "content/common/service_worker/service_worker_types.h"
|
| #include "net/base/completion_callback.h"
|
| @@ -33,7 +34,8 @@ class ServiceWorkerRequestResponseHeaders;
|
| // 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 CONTENT_EXPORT ServiceWorkerCache {
|
| +class CONTENT_EXPORT ServiceWorkerCache
|
| + : public base::RefCounted<ServiceWorkerCache> {
|
| public:
|
| enum ErrorType {
|
| ErrorTypeOK = 0,
|
| @@ -51,18 +53,14 @@ class CONTENT_EXPORT ServiceWorkerCache {
|
| typedef base::Callback<void(ErrorType, scoped_ptr<Requests>)>
|
| RequestsCallback;
|
|
|
| - static scoped_ptr<ServiceWorkerCache> CreateMemoryCache(
|
| + static scoped_refptr<ServiceWorkerCache> CreateMemoryCache(
|
| net::URLRequestContext* request_context,
|
| base::WeakPtr<storage::BlobStorageContext> blob_context);
|
| - static scoped_ptr<ServiceWorkerCache> CreatePersistentCache(
|
| + static scoped_refptr<ServiceWorkerCache> CreatePersistentCache(
|
| const base::FilePath& path,
|
| net::URLRequestContext* request_context,
|
| base::WeakPtr<storage::BlobStorageContext> blob_context);
|
|
|
| - // Operations in progress will complete after the cache is deleted but pending
|
| - // operations (those operations waiting for init to finish) won't.
|
| - virtual ~ServiceWorkerCache();
|
| -
|
| // Returns ErrorTypeNotFound if not found. The callback will always be called.
|
| // |request| must remain valid until the callback is called.
|
| void Match(scoped_ptr<ServiceWorkerFetchRequest> request,
|
| @@ -87,6 +85,9 @@ class CONTENT_EXPORT ServiceWorkerCache {
|
| // callback will always be called.
|
| void Keys(const RequestsCallback& callback);
|
|
|
| + // Prevent further operations on this object and delete the backend.
|
| + void Close();
|
| +
|
| void set_backend(scoped_ptr<disk_cache::Backend> backend) {
|
| backend_ = backend.Pass();
|
| }
|
| @@ -94,6 +95,8 @@ class CONTENT_EXPORT ServiceWorkerCache {
|
| base::WeakPtr<ServiceWorkerCache> AsWeakPtr();
|
|
|
| private:
|
| + friend class base::RefCounted<ServiceWorkerCache>;
|
| +
|
| struct KeysContext;
|
| typedef std::vector<disk_cache::Entry*> Entries;
|
|
|
| @@ -101,6 +104,10 @@ class CONTENT_EXPORT ServiceWorkerCache {
|
| net::URLRequestContext* request_context,
|
| base::WeakPtr<storage::BlobStorageContext> blob_context);
|
|
|
| + // Operations in progress will complete after the cache is deleted but pending
|
| + // operations (those operations waiting for init to finish) won't.
|
| + virtual ~ServiceWorkerCache();
|
| +
|
| // Static callbacks for the Keys function.
|
| static void KeysDidOpenNextEntry(scoped_ptr<KeysContext> keys_context,
|
| int rv);
|
| @@ -118,6 +125,8 @@ class CONTENT_EXPORT ServiceWorkerCache {
|
| void Init(const base::Closure& callback);
|
| void InitDone(ErrorType error);
|
|
|
| + // The backend can be deleted via the Close function at any time so always
|
| + // check for its existence before use.
|
| scoped_ptr<disk_cache::Backend> backend_;
|
| base::FilePath path_;
|
| net::URLRequestContext* request_context_;
|
|
|