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

Side by Side Diff: content/browser/service_worker/service_worker_cache.h

Issue 477973002: Add Keys() function to ServiceWorkerCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cache_patch
Patch Set: Addresses comments from PS9 Created 6 years, 3 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 unified diff | Download patch
OLDNEW
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 CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "content/common/service_worker/service_worker_types.h" 11 #include "content/common/service_worker/service_worker_types.h"
12 #include "net/base/completion_callback.h" 12 #include "net/base/completion_callback.h"
13 #include "net/disk_cache/disk_cache.h" 13 #include "net/disk_cache/disk_cache.h"
14 14
15 namespace net { 15 namespace net {
16 class URLRequestContext; 16 class URLRequestContext;
17 class IOBufferWithSize; 17 class IOBufferWithSize;
18 } 18 }
19 19
20 namespace storage { 20 namespace storage {
21 class BlobData; 21 class BlobData;
22 class BlobDataHandle; 22 class BlobDataHandle;
23 class BlobStorageContext; 23 class BlobStorageContext;
24 } 24 }
25 25
26 namespace content { 26 namespace content {
27 class ChromeBlobStorageContext; 27 class ChromeBlobStorageContext;
28 class ServiceWorkerRequestResponseHeaders;
28 29
29 // TODO(jkarlin): Unload cache backend from memory once the cache object is no 30 // TODO(jkarlin): Unload cache backend from memory once the cache object is no
30 // longer referenced in javascript. 31 // longer referenced in javascript.
31 32
32 // Represents a ServiceWorker Cache as seen in 33 // Represents a ServiceWorker Cache as seen in
33 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. 34 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html.
34 // InitializeIfNeeded must be called before calling the other public members. 35 // InitializeIfNeeded must be called before calling the other public members.
35 class CONTENT_EXPORT ServiceWorkerCache { 36 class CONTENT_EXPORT ServiceWorkerCache {
36 public: 37 public:
37 enum ErrorType { 38 enum ErrorType {
38 ErrorTypeOK = 0, 39 ErrorTypeOK = 0,
39 ErrorTypeExists, 40 ErrorTypeExists,
40 ErrorTypeStorage, 41 ErrorTypeStorage,
41 ErrorTypeNotFound 42 ErrorTypeNotFound
42 }; 43 };
43 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY }; 44 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY };
44 typedef base::Callback<void(ErrorType)> ErrorCallback; 45 typedef base::Callback<void(ErrorType)> ErrorCallback;
45 typedef base::Callback<void(ErrorType, 46 typedef base::Callback<void(ErrorType,
46 scoped_ptr<ServiceWorkerResponse>, 47 scoped_ptr<ServiceWorkerResponse>,
47 scoped_ptr<storage::BlobDataHandle>)> 48 scoped_ptr<storage::BlobDataHandle>)>
48 ResponseCallback; 49 ResponseCallback;
50 typedef std::vector<ServiceWorkerFetchRequest> Requests;
51 typedef base::Callback<void(ErrorType, scoped_ptr<Requests>)>
52 RequestsCallback;
53
49 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( 54 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache(
50 net::URLRequestContext* request_context, 55 net::URLRequestContext* request_context,
51 base::WeakPtr<storage::BlobStorageContext> blob_context); 56 base::WeakPtr<storage::BlobStorageContext> blob_context);
52 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( 57 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache(
53 const base::FilePath& path, 58 const base::FilePath& path,
54 net::URLRequestContext* request_context, 59 net::URLRequestContext* request_context,
55 base::WeakPtr<storage::BlobStorageContext> blob_context); 60 base::WeakPtr<storage::BlobStorageContext> blob_context);
56 61
57 virtual ~ServiceWorkerCache(); 62 virtual ~ServiceWorkerCache();
58 63
(...skipping 14 matching lines...) Expand all
73 void Put(ServiceWorkerFetchRequest* request, 78 void Put(ServiceWorkerFetchRequest* request,
74 ServiceWorkerResponse* response, 79 ServiceWorkerResponse* response,
75 const ErrorCallback& callback); 80 const ErrorCallback& callback);
76 81
77 // Returns ErrorNotFound if not found. Otherwise deletes and returns 82 // Returns ErrorNotFound if not found. Otherwise deletes and returns
78 // ErrorTypeOK. The callback will always be called. |request| must remain 83 // ErrorTypeOK. The callback will always be called. |request| must remain
79 // valid until the callback is called. 84 // valid until the callback is called.
80 void Delete(ServiceWorkerFetchRequest* request, 85 void Delete(ServiceWorkerFetchRequest* request,
81 const ErrorCallback& callback); 86 const ErrorCallback& callback);
82 87
88 // TODO(jkarlin): Have keys take an optional ServiceWorkerFetchRequest.
89 // Returns ErrorTypeOK and a vector of requests if there are no errors. The
90 // callback will always be called.
91 void Keys(const RequestsCallback& callback);
92
83 // Call to determine if CreateBackend must be called. 93 // Call to determine if CreateBackend must be called.
84 bool HasCreatedBackend() const; 94 bool HasCreatedBackend() const;
85 95
86 void set_backend(scoped_ptr<disk_cache::Backend> backend) { 96 void set_backend(scoped_ptr<disk_cache::Backend> backend) {
87 backend_ = backend.Pass(); 97 backend_ = backend.Pass();
88 } 98 }
89 99
90 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); 100 base::WeakPtr<ServiceWorkerCache> AsWeakPtr();
91 101
92 private: 102 private:
103 struct KeysContext;
104 typedef std::vector<disk_cache::Entry*> Entries;
105
93 ServiceWorkerCache(const base::FilePath& path, 106 ServiceWorkerCache(const base::FilePath& path,
94 net::URLRequestContext* request_context, 107 net::URLRequestContext* request_context,
95 base::WeakPtr<storage::BlobStorageContext> blob_context); 108 base::WeakPtr<storage::BlobStorageContext> blob_context);
96 109
110 // Static callbacks for the Keys function.
111 static void KeysDidOpenNextEntry(scoped_ptr<KeysContext> keys_context,
112 int rv);
113 static void KeysProcessNextEntry(scoped_ptr<KeysContext> keys_context,
114 const Entries::iterator& iter);
115 static void KeysDidReadHeaders(
116 scoped_ptr<KeysContext> keys_context,
117 const Entries::iterator& iter,
118 scoped_ptr<ServiceWorkerRequestResponseHeaders> headers);
119
97 scoped_ptr<disk_cache::Backend> backend_; 120 scoped_ptr<disk_cache::Backend> backend_;
98 base::FilePath path_; 121 base::FilePath path_;
99 net::URLRequestContext* request_context_; 122 net::URLRequestContext* request_context_;
100 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; 123 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_;
101 124
102 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; 125 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_;
103 126
104 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); 127 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache);
105 }; 128 };
106 129
107 } // namespace content 130 } // namespace content
108 131
109 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ 132 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698