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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 Status ClearPurgeableResourceIds(const std::set<int64>& ids); | 173 Status ClearPurgeableResourceIds(const std::set<int64>& ids); |
174 | 174 |
175 // Deletes all data for |origin|, namely, unique origin, registrations and | 175 // Deletes all data for |origin|, namely, unique origin, registrations and |
176 // resource records. Resources are moved to the purgeable list. Returns OK if | 176 // resource records. Resources are moved to the purgeable list. Returns OK if |
177 // they are successfully deleted or not found in the database. Otherwise, | 177 // they are successfully deleted or not found in the database. Otherwise, |
178 // returns an error. | 178 // returns an error. |
179 Status DeleteAllDataForOrigin( | 179 Status DeleteAllDataForOrigin( |
180 const GURL& origin, | 180 const GURL& origin, |
181 std::vector<int64>* newly_purgeable_resources); | 181 std::vector<int64>* newly_purgeable_resources); |
182 | 182 |
183 bool is_disabled() const { return is_disabled_; } | |
184 bool was_corruption_detected() const { return was_corruption_detected_; } | |
185 | |
186 private: | 183 private: |
187 // 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 |
188 // 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. |
189 // 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 |
190 // false. Otherwise, returns an error. | 187 // false. Otherwise, returns an error. |
191 Status LazyOpen(bool create_if_missing); | 188 Status LazyOpen(bool create_if_missing); |
192 | 189 |
193 // Helper for LazyOpen(). |status| must be the return value from LazyOpen() | 190 // Helper for LazyOpen(). |status| must be the return value from LazyOpen() |
194 // and this must be called just after LazyOpen() is called. Returns true if | 191 // and this must be called just after LazyOpen() is called. Returns true if |
195 // the database is new or nonexistent, that is, it has never been used. | 192 // the database is new or nonexistent, that is, it has never been used. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 const leveldb::Status& status); | 266 const leveldb::Status& status); |
270 | 267 |
271 base::FilePath path_; | 268 base::FilePath path_; |
272 scoped_ptr<leveldb::Env> env_; | 269 scoped_ptr<leveldb::Env> env_; |
273 scoped_ptr<leveldb::DB> db_; | 270 scoped_ptr<leveldb::DB> db_; |
274 | 271 |
275 int64 next_avail_registration_id_; | 272 int64 next_avail_registration_id_; |
276 int64 next_avail_resource_id_; | 273 int64 next_avail_resource_id_; |
277 int64 next_avail_version_id_; | 274 int64 next_avail_version_id_; |
278 | 275 |
279 // True if a database error has occurred (e.g. cannot read data). | 276 enum State { |
280 // If true, all database accesses will fail. | 277 UNINITIALIZED, |
281 bool is_disabled_; | 278 INITIALIZED, |
282 | 279 DISABLED, |
283 // True if a database corruption was detected. | 280 }; |
284 bool was_corruption_detected_; | 281 State state_; |
285 | |
286 // True if a database was initialized, that is, the schema version was written | |
287 // in the database. | |
288 bool is_initialized_; | |
289 | 282 |
290 base::SequenceChecker sequence_checker_; | 283 base::SequenceChecker sequence_checker_; |
291 | 284 |
292 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); | 285 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); |
293 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); | 286 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); |
294 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); | 287 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); |
295 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); | 288 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); |
296 | 289 |
297 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); | 290 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); |
298 }; | 291 }; |
299 | 292 |
300 } // namespace content | 293 } // namespace content |
301 | 294 |
302 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 295 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
OLD | NEW |