OLD | NEW |
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_DATABASE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 std::vector<ResourceRecord>* resources); | 107 std::vector<ResourceRecord>* resources); |
108 | 108 |
109 // Writes |registration| and |resources| into the database and does following | 109 // Writes |registration| and |resources| into the database and does following |
110 // things: | 110 // things: |
111 // - Deletes an old version of the registration if exists. | 111 // - Deletes an old version of the registration if exists. |
112 // - Bumps the next registration id and the next version id if needed. | 112 // - Bumps the next registration id and the next version id if needed. |
113 // - Removes |resources| from the uncommitted list if exist. | 113 // - Removes |resources| from the uncommitted list if exist. |
114 // Returns OK they are successfully written. Otherwise, returns an error. | 114 // Returns OK they are successfully written. Otherwise, returns an error. |
115 Status WriteRegistration( | 115 Status WriteRegistration( |
116 const RegistrationData& registration, | 116 const RegistrationData& registration, |
117 const std::vector<ResourceRecord>& resources); | 117 const std::vector<ResourceRecord>& resources, |
| 118 std::vector<int64>* newly_purgeable_resources); |
118 | 119 |
119 // Updates a registration for |registration_id| to an active state. Returns OK | 120 // Updates a registration for |registration_id| to an active state. Returns OK |
120 // if it's successfully updated. Otherwise, returns an error. | 121 // if it's successfully updated. Otherwise, returns an error. |
121 Status UpdateVersionToActive( | 122 Status UpdateVersionToActive( |
122 int64 registration_id, | 123 int64 registration_id, |
123 const GURL& origin); | 124 const GURL& origin); |
124 | 125 |
125 // Updates last check time of a registration for |registration_id| by |time|. | 126 // Updates last check time of a registration for |registration_id| by |time|. |
126 // Returns OK if it's successfully updated. Otherwise, returns an error. | 127 // Returns OK if it's successfully updated. Otherwise, returns an error. |
127 Status UpdateLastCheckTime( | 128 Status UpdateLastCheckTime( |
128 int64 registration_id, | 129 int64 registration_id, |
129 const GURL& origin, | 130 const GURL& origin, |
130 const base::Time& time); | 131 const base::Time& time); |
131 | 132 |
132 // Deletes a registration for |registration_id| and moves resource records | 133 // Deletes a registration for |registration_id| and moves resource records |
133 // associated with it into the purgeable list. Returns OK if it's successfully | 134 // associated with it into the purgeable list. Returns OK if it's successfully |
134 // deleted or not found in the database. Otherwise, returns an error. | 135 // deleted or not found in the database. Otherwise, returns an error. |
135 Status DeleteRegistration( | 136 Status DeleteRegistration( |
136 int64 registration_id, | 137 int64 registration_id, |
137 const GURL& origin); | 138 const GURL& origin, |
| 139 std::vector<int64>* newly_purgeable_resources); |
138 | 140 |
139 // As new resources are put into the diskcache, they go into an uncommitted | 141 // As new resources are put into the diskcache, they go into an uncommitted |
140 // list. When a registration is saved that refers to those ids, they're | 142 // list. When a registration is saved that refers to those ids, they're |
141 // removed from that list. When a resource no longer has any registrations or | 143 // removed from that list. When a resource no longer has any registrations or |
142 // caches referring to it, it's added to the purgeable list. Periodically, | 144 // caches referring to it, it's added to the purgeable list. Periodically, |
143 // the purgeable list can be purged from the diskcache. At system startup, all | 145 // the purgeable list can be purged from the diskcache. At system startup, all |
144 // uncommitted ids are moved to the purgeable list. | 146 // uncommitted ids are moved to the purgeable list. |
145 | 147 |
146 // Reads uncommitted resource ids from the database. Returns OK on success. | 148 // Reads uncommitted resource ids from the database. Returns OK on success. |
147 // Otherwise clears |ids| and returns an error. | 149 // Otherwise clears |ids| and returns an error. |
(...skipping 16 matching lines...) Expand all Loading... |
164 Status WritePurgeableResourceIds(const std::set<int64>& ids); | 166 Status WritePurgeableResourceIds(const std::set<int64>& ids); |
165 | 167 |
166 // Deletes purgeable resource ids specified by |ids| from the database. | 168 // Deletes purgeable resource ids specified by |ids| from the database. |
167 // Returns OK on success. Otherwise deletes nothing and returns an error. | 169 // Returns OK on success. Otherwise deletes nothing and returns an error. |
168 Status ClearPurgeableResourceIds(const std::set<int64>& ids); | 170 Status ClearPurgeableResourceIds(const std::set<int64>& ids); |
169 | 171 |
170 // Deletes all data for |origin|, namely, unique origin, registrations and | 172 // Deletes all data for |origin|, namely, unique origin, registrations and |
171 // resource records. Resources are moved to the purgeable list. Returns OK if | 173 // resource records. Resources are moved to the purgeable list. Returns OK if |
172 // they are successfully deleted or not found in the database. Otherwise, | 174 // they are successfully deleted or not found in the database. Otherwise, |
173 // returns an error. | 175 // returns an error. |
174 Status DeleteAllDataForOrigin(const GURL& origin); | 176 Status DeleteAllDataForOrigin( |
| 177 const GURL& origin, |
| 178 std::vector<int64>* newly_purgeable_resources); |
175 | 179 |
176 bool is_disabled() const { return is_disabled_; } | 180 bool is_disabled() const { return is_disabled_; } |
177 bool was_corruption_detected() const { return was_corruption_detected_; } | 181 bool was_corruption_detected() const { return was_corruption_detected_; } |
178 | 182 |
179 private: | 183 private: |
180 // Opens the database at the |path_|. This is lazily called when the first | 184 // Opens the database at the |path_|. This is lazily called when the first |
181 // database API is called. Returns OK if the database is successfully opened. | 185 // database API is called. Returns OK if the database is successfully opened. |
182 // Returns NOT_FOUND if the database does not exist and |create_if_missing| is | 186 // Returns NOT_FOUND if the database does not exist and |create_if_missing| is |
183 // false. Otherwise, returns an error. | 187 // false. Otherwise, returns an error. |
184 Status LazyOpen(bool create_if_missing); | 188 Status LazyOpen(bool create_if_missing); |
(...skipping 22 matching lines...) Expand all Loading... |
207 // error. | 211 // error. |
208 Status ReadResourceRecords( | 212 Status ReadResourceRecords( |
209 int64 version_id, | 213 int64 version_id, |
210 std::vector<ResourceRecord>* resources); | 214 std::vector<ResourceRecord>* resources); |
211 | 215 |
212 // Deletes resource records for |version_id| from the database. Returns OK if | 216 // Deletes resource records for |version_id| from the database. Returns OK if |
213 // they are successfully deleted or not found in the database. Otherwise, | 217 // they are successfully deleted or not found in the database. Otherwise, |
214 // returns an error. | 218 // returns an error. |
215 Status DeleteResourceRecords( | 219 Status DeleteResourceRecords( |
216 int64 version_id, | 220 int64 version_id, |
| 221 std::vector<int64>* newly_purgeable_resources, |
217 leveldb::WriteBatch* batch); | 222 leveldb::WriteBatch* batch); |
218 | 223 |
219 // Reads resource ids for |id_key_prefix| from the database. Returns OK if | 224 // Reads resource ids for |id_key_prefix| from the database. Returns OK if |
220 // it's successfully read or not found in the database. Otherwise, returns an | 225 // it's successfully read or not found in the database. Otherwise, returns an |
221 // error. | 226 // error. |
222 Status ReadResourceIds( | 227 Status ReadResourceIds( |
223 const char* id_key_prefix, | 228 const char* id_key_prefix, |
224 std::set<int64>* ids); | 229 std::set<int64>* ids); |
225 | 230 |
226 // Write resource ids for |id_key_prefix| into the database. Returns OK on | 231 // Write resource ids for |id_key_prefix| into the database. Returns OK on |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); | 290 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); |
286 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); | 291 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); |
287 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); | 292 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); |
288 | 293 |
289 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); | 294 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); |
290 }; | 295 }; |
291 | 296 |
292 } // namespace content | 297 } // namespace content |
293 | 298 |
294 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 299 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
OLD | NEW |