Chromium Code Reviews| Index: content/browser/service_worker/service_worker_database.h |
| diff --git a/content/browser/service_worker/service_worker_database.h b/content/browser/service_worker/service_worker_database.h |
| index 889f983667230a56d028a58ec2e28ca848338d9e..db3b81f0a33783981ad358f48d758930caf10f01 100644 |
| --- a/content/browser/service_worker/service_worker_database.h |
| +++ b/content/browser/service_worker/service_worker_database.h |
| @@ -5,6 +5,9 @@ |
| #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
| #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
| +#include <set> |
| +#include <vector> |
| + |
| #include "base/files/file_path.h" |
| #include "base/macros.h" |
| #include "base/memory/scoped_ptr.h" |
| @@ -23,6 +26,9 @@ class WriteBatch; |
| namespace content { |
| +class ServiceWorkerRegistrationData; |
| +class ServiceWorkerResourceRecord; |
|
michaeln
2014/04/26 00:29:02
looks like these aren't needed in the .h file anym
nhiroki
2014/04/28 04:15:59
Done.
|
| + |
| // Class to persist serviceworker registration data in a database. |
| // Should NOT be used on the IO thread since this does blocking |
| // file io. The ServiceWorkerStorage class owns this class and |
| @@ -58,10 +64,40 @@ class CONTENT_EXPORT ServiceWorkerDatabase { |
| ~RegistrationData(); |
| }; |
| + struct ResourceRecord { |
| + int64 resource_id; |
| + GURL url; |
| + }; |
| + |
| // For use during initialization. |
| bool GetNextAvailableIds(int64* next_avail_registration_id, |
| int64* next_avail_version_id, |
| int64* next_avail_resource_id); |
| + bool GetOriginsWithRegistrations(std::set<GURL>* origins); |
| + |
| + // For use when first handling a request in an origin with registrations. |
| + bool GetRegistrationsForOrigin(const GURL& origin, |
| + std::vector<RegistrationData>* registrations); |
| + |
| + // Saving, retrieving, and updating registration data. |
| + // (will bump next_avail_xxxx_ids as needed) |
| + // (resource ids will be added/removed from the uncommitted/purgeable |
| + // lists as needed) |
| + |
| + bool ReadRegistration(int64 registration_id, |
| + const GURL& origin, |
| + RegistrationData* registration, |
| + std::vector<ResourceRecord>* resources); |
| + bool WriteRegistration(const RegistrationData& registration, |
| + const std::vector<ResourceRecord>& resources); |
| + |
| + bool UpdateVersionToActive(int64 registration_id, |
| + const GURL& origin); |
| + bool UpdateLastCheckTime(int64 registration_id, |
| + const GURL& origin, |
| + const base::Time& time); |
| + bool DeleteRegistration(int64 registration_id, |
| + const GURL& origin); |
| bool is_disabled() const { return is_disabled_; } |
| bool was_corruption_detected() const { return was_corruption_detected_; } |
| @@ -73,14 +109,25 @@ class CONTENT_EXPORT ServiceWorkerDatabase { |
| // does not exist and |create_if_needed| is false. |
| bool LazyOpen(bool create_if_needed); |
| - // Populates the database with initial data, namely, database schema version |
| - // and next available IDs. |
| - bool PopulateInitialData(); |
| - |
| bool ReadNextAvailableId(const char* id_key, |
| int64* next_avail_id); |
| + bool ReadRegistrationData(int64 registration_id, |
| + const GURL& origin, |
| + RegistrationData* registration); |
| + bool ReadDatabaseVersion(int64* db_version); |
| + |
| + // Write a batch into the database. |
| + // NOTE: You must call this when you want to put something into the database |
| + // because this initializes the database if needed. |
| bool WriteBatch(leveldb::WriteBatch* batch); |
| + // Bumps the next available id if |used_id| is greater than or equal to the |
| + // cached one. |
| + void BumpNextRegistrationIdIfNeeded(int64 used_id, |
| + leveldb::WriteBatch* batch); |
| + void BumpNextVersionIdIfNeeded(int64 used_id, |
| + leveldb::WriteBatch* batch); |
| + |
| bool IsOpen(); |
| bool IsEmpty(); |
|
michaeln
2014/04/26 00:29:02
IsEmpty() can be deleted here
nhiroki
2014/04/28 04:15:59
Done.
|
| @@ -91,6 +138,10 @@ class CONTENT_EXPORT ServiceWorkerDatabase { |
| scoped_ptr<leveldb::Env> env_; |
| scoped_ptr<leveldb::DB> db_; |
| + int64 next_avail_registration_id_; |
| + int64 next_avail_resource_id_; |
| + int64 next_avail_version_id_; |
| + |
| // True if a database error has occurred (e.g. cannot read data). |
| // If true, all database accesses will fail. |
| bool is_disabled_; |
| @@ -98,6 +149,10 @@ class CONTENT_EXPORT ServiceWorkerDatabase { |
| // True if a database corruption was detected. |
| bool was_corruption_detected_; |
| + // True if a database was initialized, that is, the schema version was written |
| + // in the database. |
| + bool is_initialized_; |
| + |
| base::SequenceChecker sequence_checker_; |
| FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); |