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 21 matching lines...) Expand all Loading... |
32 // Should NOT be used on the IO thread since this does blocking | 32 // Should NOT be used on the IO thread since this does blocking |
33 // file io. The ServiceWorkerStorage class owns this class and | 33 // file io. The ServiceWorkerStorage class owns this class and |
34 // is responsible for only calling it serially on background | 34 // is responsible for only calling it serially on background |
35 // non-IO threads (ala SequencedWorkerPool). | 35 // non-IO threads (ala SequencedWorkerPool). |
36 class CONTENT_EXPORT ServiceWorkerDatabase { | 36 class CONTENT_EXPORT ServiceWorkerDatabase { |
37 public: | 37 public: |
38 // We do leveldb stuff in |path| or in memory if |path| is empty. | 38 // We do leveldb stuff in |path| or in memory if |path| is empty. |
39 explicit ServiceWorkerDatabase(const base::FilePath& path); | 39 explicit ServiceWorkerDatabase(const base::FilePath& path); |
40 ~ServiceWorkerDatabase(); | 40 ~ServiceWorkerDatabase(); |
41 | 41 |
| 42 // Used in UMA. A new value must be appended only. |
42 enum Status { | 43 enum Status { |
43 STATUS_OK, | 44 STATUS_OK, |
44 STATUS_ERROR_NOT_FOUND, | 45 STATUS_ERROR_NOT_FOUND, |
| 46 STATUS_ERROR_IO_ERROR, |
45 STATUS_ERROR_CORRUPTED, | 47 STATUS_ERROR_CORRUPTED, |
46 STATUS_ERROR_FAILED, | 48 STATUS_ERROR_FAILED, |
| 49 STATUS_ERROR_MAX, |
47 }; | 50 }; |
48 | 51 |
49 struct CONTENT_EXPORT RegistrationData { | 52 struct CONTENT_EXPORT RegistrationData { |
50 // These values are immutable for the life of a registration. | 53 // These values are immutable for the life of a registration. |
51 int64 registration_id; | 54 int64 registration_id; |
52 GURL scope; | 55 GURL scope; |
53 GURL script; | 56 GURL script; |
54 | 57 |
55 // Versions are first stored once they successfully install and become | 58 // Versions are first stored once they successfully install and become |
56 // the waiting version. Then transition to the active version. The stored | 59 // the waiting version. Then transition to the active version. The stored |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // cached one. | 269 // cached one. |
267 void BumpNextRegistrationIdIfNeeded( | 270 void BumpNextRegistrationIdIfNeeded( |
268 int64 used_id, | 271 int64 used_id, |
269 leveldb::WriteBatch* batch); | 272 leveldb::WriteBatch* batch); |
270 void BumpNextVersionIdIfNeeded( | 273 void BumpNextVersionIdIfNeeded( |
271 int64 used_id, | 274 int64 used_id, |
272 leveldb::WriteBatch* batch); | 275 leveldb::WriteBatch* batch); |
273 | 276 |
274 bool IsOpen(); | 277 bool IsOpen(); |
275 | 278 |
276 void HandleError( | 279 void Disable( |
277 const tracked_objects::Location& from_here, | 280 const tracked_objects::Location& from_here, |
278 const leveldb::Status& status); | 281 Status status); |
| 282 void HandleOpenResult( |
| 283 const tracked_objects::Location& from_here, |
| 284 Status status); |
| 285 void HandleReadResult( |
| 286 const tracked_objects::Location& from_here, |
| 287 Status status); |
| 288 void HandleWriteResult( |
| 289 const tracked_objects::Location& from_here, |
| 290 Status status); |
279 | 291 |
280 base::FilePath path_; | 292 base::FilePath path_; |
281 scoped_ptr<leveldb::Env> env_; | 293 scoped_ptr<leveldb::Env> env_; |
282 scoped_ptr<leveldb::DB> db_; | 294 scoped_ptr<leveldb::DB> db_; |
283 | 295 |
284 int64 next_avail_registration_id_; | 296 int64 next_avail_registration_id_; |
285 int64 next_avail_resource_id_; | 297 int64 next_avail_resource_id_; |
286 int64 next_avail_version_id_; | 298 int64 next_avail_version_id_; |
287 | 299 |
288 enum State { | 300 enum State { |
289 UNINITIALIZED, | 301 UNINITIALIZED, |
290 INITIALIZED, | 302 INITIALIZED, |
291 DISABLED, | 303 DISABLED, |
292 }; | 304 }; |
293 State state_; | 305 State state_; |
294 | 306 |
295 base::SequenceChecker sequence_checker_; | 307 base::SequenceChecker sequence_checker_; |
296 | 308 |
297 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); | 309 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); |
298 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); | 310 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); |
299 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); | 311 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); |
300 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); | 312 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); |
301 | 313 |
302 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); | 314 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); |
303 }; | 315 }; |
304 | 316 |
305 } // namespace content | 317 } // namespace content |
306 | 318 |
307 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 319 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
OLD | NEW |