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

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

Issue 503823002: Creates CacheContext for ServiceWorkerCacheStorage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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_STORAGE_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/id_map.h" 13 #include "base/id_map.h"
falken 2014/08/26 06:31:33 Can this id_map.h be removed?
jkarlin 2014/08/26 12:03:10 Done.
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 15
16 namespace base { 16 namespace base {
17 class SequencedTaskRunner; 17 class SequencedTaskRunner;
18 } 18 }
19 19
20 namespace net { 20 namespace net {
21 class URLRequestContext; 21 class URLRequestContext;
22 } 22 }
23 23
24 namespace storage { 24 namespace storage {
25 class BlobStorageContext; 25 class BlobStorageContext;
26 } 26 }
27 27
28 namespace content { 28 namespace content {
29 class ServiceWorkerCache; 29 class ServiceWorkerCache;
30 30
31 // TODO(jkarlin): Constrain the total bytes used per origin. 31 // TODO(jkarlin): Constrain the total bytes used per origin.
32 32
33 // ServiceWorkerCacheStorage holds the set of caches for a given origin. It is 33 // ServiceWorkerCacheStorage holds the set of caches for a given origin. It is
34 // owned by the ServiceWorkerCacheStorageManager. This class expects to be run 34 // owned by the ServiceWorkerCacheStorageManager. This class expects to be run
35 // on the IO thread. 35 // on the IO thread.
36 class ServiceWorkerCacheStorage { 36 class ServiceWorkerCacheStorage {
37 public: 37 public:
38 // TODO(jkarlin): Convert this (and everything that uses it) to int64_t so
39 // that we don't run out of id space.
40 typedef int32_t CacheID;
41
38 enum CacheStorageError { 42 enum CacheStorageError {
39 CACHE_STORAGE_ERROR_NO_ERROR, 43 CACHE_STORAGE_ERROR_NO_ERROR,
40 CACHE_STORAGE_ERROR_NOT_IMPLEMENTED, 44 CACHE_STORAGE_ERROR_NOT_IMPLEMENTED,
41 CACHE_STORAGE_ERROR_NOT_FOUND, 45 CACHE_STORAGE_ERROR_NOT_FOUND,
42 CACHE_STORAGE_ERROR_EXISTS, 46 CACHE_STORAGE_ERROR_EXISTS,
43 CACHE_STORAGE_ERROR_STORAGE, 47 CACHE_STORAGE_ERROR_STORAGE,
44 CACHE_STORAGE_ERROR_EMPTY_KEY, 48 CACHE_STORAGE_ERROR_EMPTY_KEY,
49 CACHE_STORAGE_ERROR_CLOSING
45 }; 50 };
46 51
47 typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback; 52 typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback;
48 typedef base::Callback<void(int, CacheStorageError)> CacheAndErrorCallback; 53 typedef base::Callback<void(int, CacheStorageError)> CacheAndErrorCallback;
49 typedef base::Callback<void(const std::vector<std::string>&, 54 typedef base::Callback<void(const std::vector<std::string>&,
50 CacheStorageError)> StringsAndErrorCallback; 55 CacheStorageError)> StringsAndErrorCallback;
51 56
52 ServiceWorkerCacheStorage( 57 ServiceWorkerCacheStorage(
53 const base::FilePath& origin_path, 58 const base::FilePath& origin_path,
54 bool memory_only, 59 bool memory_only,
(...skipping 25 matching lines...) Expand all
80 85
81 // Calls the callback with a vector of cache names (keys) available. 86 // Calls the callback with a vector of cache names (keys) available.
82 void EnumerateCaches(const StringsAndErrorCallback& callback); 87 void EnumerateCaches(const StringsAndErrorCallback& callback);
83 88
84 // TODO(jkarlin): Add match() function. 89 // TODO(jkarlin): Add match() function.
85 90
86 private: 91 private:
87 class MemoryLoader; 92 class MemoryLoader;
88 class SimpleCacheLoader; 93 class SimpleCacheLoader;
89 class CacheLoader; 94 class CacheLoader;
95 struct CacheContext;
90 96
91 typedef IDMap<ServiceWorkerCache, IDMapOwnPointer> CacheMap; 97 typedef std::map<CacheID, CacheContext*> CacheMap;
92 typedef CacheMap::KeyType CacheID;
93 typedef std::map<std::string, CacheID> NameMap; 98 typedef std::map<std::string, CacheID> NameMap;
94 99
95 ServiceWorkerCache* GetLoadedCache(const std::string& cache_name) const; 100 CacheContext* GetLoadedCache(const std::string& cache_name) const;
96 101
97 // Initializer and its callback are below. 102 // Initializer and its callback are below.
98 void LazyInit(const base::Closure& closure); 103 void LazyInit(const base::Closure& closure);
99 void LazyInitDidLoadIndex( 104 void LazyInitDidLoadIndex(
100 const base::Closure& callback, 105 const base::Closure& callback,
101 scoped_ptr<std::vector<std::string> > indexed_cache_names); 106 scoped_ptr<std::vector<std::string> > indexed_cache_names);
102 void LazyInitIterateAndLoadCacheName( 107 void LazyInitIterateAndLoadCacheName(
103 const base::Closure& callback, 108 const base::Closure& callback,
104 scoped_ptr<std::vector<std::string> > indexed_cache_names, 109 scoped_ptr<std::vector<std::string> > indexed_cache_names,
105 const std::vector<std::string>::const_iterator& iter, 110 const std::vector<std::string>::const_iterator& iter,
111 const std::string& cache_name,
106 scoped_ptr<ServiceWorkerCache> cache); 112 scoped_ptr<ServiceWorkerCache> cache);
107 void LazyInitDone(); 113 void LazyInitDone();
108 114
109 void DidCreateBackend(base::WeakPtr<ServiceWorkerCache> cache, 115 void DidCreateBackend(base::WeakPtr<ServiceWorkerCache> cache,
116 CacheID cache_id,
110 const CacheAndErrorCallback& callback, 117 const CacheAndErrorCallback& callback,
111 bool success); 118 bool success);
112 119
113 void AddCacheToMaps(scoped_ptr<ServiceWorkerCache> cache); 120 CacheContext* AddCacheToMaps(const std::string& cache_name,
121 scoped_ptr<ServiceWorkerCache> cache);
114 122
115 // The CreateCache callbacks are below. 123 // The CreateCache callbacks are below.
116 void CreateCacheDidCreateCache(const std::string& cache_name, 124 void CreateCacheDidCreateCache(const std::string& cache_name,
117 const CacheAndErrorCallback& callback, 125 const CacheAndErrorCallback& callback,
118 scoped_ptr<ServiceWorkerCache> cache); 126 scoped_ptr<ServiceWorkerCache> cache);
119 void CreateCacheDidWriteIndex(const CacheAndErrorCallback& callback, 127 void CreateCacheDidWriteIndex(const CacheAndErrorCallback& callback,
120 base::WeakPtr<ServiceWorkerCache> cache, 128 base::WeakPtr<ServiceWorkerCache> cache,
129 CacheID id,
121 bool success); 130 bool success);
122 131
123 // The DeleteCache callbacks are below. 132 // The DeleteCache callbacks are below.
124 void DeleteCacheDidWriteIndex(const std::string& cache_name, 133 void DeleteCacheDidWriteIndex(const std::string& cache_name,
125 const BoolAndErrorCallback& callback, 134 const BoolAndErrorCallback& callback,
126 bool success); 135 bool success);
127 void DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback, 136 void DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback,
128 bool success); 137 bool success);
129 138
130 // Whether or not we've loaded the list of cache names into memory. 139 // Whether or not we've loaded the list of cache names into memory.
131 bool initialized_; 140 bool initialized_;
132 141
133 // The list of operations waiting on initialization. 142 // The list of operations waiting on initialization.
134 std::vector<base::Closure> init_callbacks_; 143 std::vector<base::Closure> init_callbacks_;
135 144
136 // The map of ServiceWorkerCache objects to their integer ids that 145 // The map of CacheIds to their CacheContext objects. Owns the CacheContext
137 // ServiceWorkers reference. Owns the cache objects. 146 // object. The CacheIDs are used by JavaScript to reference a
falken 2014/08/26 06:31:33 nit: Be consistent about CacheID vs CacheId
jkarlin 2014/08/26 12:03:10 Done.
147 // ServiceWorkerCache.
138 CacheMap cache_map_; 148 CacheMap cache_map_;
149 CacheID next_cache_id_; // The next CacheID to use in cache_map_;
falken 2014/08/26 06:31:33 nit: no need to end comment with semicolon
jkarlin 2014/08/26 12:03:10 Done.
139 150
140 // The map of cache names to their integer ids. 151 // The map of cache names to their integer ids.
141 NameMap name_map_; 152 NameMap name_map_;
142 153
143 // The file path for this CacheStorage. 154 // The file path for this CacheStorage.
144 base::FilePath origin_path_; 155 base::FilePath origin_path_;
145 156
146 // The TaskRunner to run file IO on. 157 // The TaskRunner to run file IO on.
147 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; 158 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_;
148 159
149 // Performs backend specific operations (memory vs disk). 160 // Performs backend specific operations (memory vs disk).
150 scoped_refptr<CacheLoader> cache_loader_; 161 scoped_refptr<CacheLoader> cache_loader_;
151 162
152 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; 163 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_;
153 164
154 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); 165 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage);
155 }; 166 };
156 167
157 } // namespace content 168 } // namespace content
158 169
159 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ 170 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698