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 dc21acb30f7cf3fb86b62d373a55713ddb28f0ef..1b9bdb43fe76125b9977c5230587d6e3fd97ccd6 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" |
@@ -17,51 +20,88 @@ |
namespace leveldb { |
class DB; |
class Env; |
-class Slice; |
+class Status; |
class WriteBatch; |
} |
namespace content { |
-// Class to persist serviceworker regitration data in a database. |
+class ServiceWorkerRegistrationData; |
+class ServiceWorkerResourceRecord; |
+ |
+// 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 |
// is responsible for only calling it serially on background |
-// nonIO threads (ala SequencedWorkerPool). |
+// non-IO threads (ala SequencedWorkerPool). |
class CONTENT_EXPORT ServiceWorkerDatabase { |
public: |
// We do leveldb stuff in |path| or in memory if |path| is empty. |
explicit ServiceWorkerDatabase(const base::FilePath& path); |
~ServiceWorkerDatabase(); |
- struct RegistrationData { |
- // These values are immutable for the life of a registration. |
- int64 registration_id; |
- GURL scope; |
- GURL script; |
- |
- // Versions are first stored once they successfully install and become |
- // the waiting version. Then transition to the active version. The stored |
- // version may be in the ACTIVE state or in the INSTALLED state. |
- int64 version_id; |
- bool is_active; |
- bool has_fetch_handler; |
- base::Time last_update_check; |
- |
- ServiceWorkerVersion::Status GetVersionStatus() const { |
- if (is_active) |
- return ServiceWorkerVersion::ACTIVE; |
- return ServiceWorkerVersion::INSTALLED; |
- } |
- |
- RegistrationData(); |
- ~RegistrationData(); |
- }; |
- |
// 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<ServiceWorkerRegistrationData>* 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, |
+ ServiceWorkerRegistrationData* registration, |
+ std::vector<ServiceWorkerResourceRecord>* resources); |
+ bool WriteRegistration( |
+ const ServiceWorkerRegistrationData& registration, |
+ const std::vector<ServiceWorkerResourceRecord>& resources); |
+ |
+ bool UpdateVersionToActive(int64 registration_id); |
+ bool UpdateLastCheckTime(int64 registration_id, |
+ const base::Time& time); |
+ bool DeleteRegistration(int64 registration_id); |
+ |
+ // As new resources are put into the diskcache, they go into an uncommitted |
+ // list. When a registration is saved that refers to those ids, they're |
+ // removed from that list. When a resource no longer has any registrations or |
+ // caches referring to it, it's added to the unclaimed list. Periodically, |
+ // the unclaimed list can be purged from the diskcache. At system startup, all |
+ // uncommitted ids are moved to the purgeable list. |
+ |
+ // Reads uncommitted resource ids from the database. Returns true on success. |
+ // Otherwise clears |ids| and returns false. |
+ bool GetUncommittedResourceIds(std::set<int64>* ids); |
+ |
+ // Writes |ids| into the database as uncommitted resources. Returns true on |
+ // success. Otherwise writes nothing and returns false. |
+ bool WriteUncommittedResourceIds(const std::set<int64>& ids); |
+ |
+ // Deletes uncommitted resource ids specified by |ids| from the database. |
+ // Returns true on success. Otherwise deletes nothing and returns false. |
+ bool ClearUncommittedResourceIds(const std::set<int64>& ids); |
+ |
+ // Reads purgeable resource ids from the database. Returns true on success. |
+ // Otherwise clears |ids and returns false. |
+ bool GetPurgeableResourceIds(std::set<int64>* ids); |
+ |
+ // Writes |ids| into the database as purgeable resources. Returns true on |
+ // success. Otherwise writes nothing and returns false. |
+ bool WritePurgeableResourceIds(const std::set<int64>& ids); |
+ |
+ // Deletes purgeable resource ids specified by |ids| from the database. |
+ // Returns true on success. Otherwise deletes nothing and returns false. |
+ bool ClearPurgeableResourceIds(const std::set<int64>& ids); |
+ |
+ bool DeleteAllDataForOrigin(const GURL& origin); |
+ bool DeleteAllData(); |
bool is_disabled() const { return is_disabled_; } |
bool was_corruption_detected() const { return was_corruption_detected_; } |
@@ -77,12 +117,27 @@ class CONTENT_EXPORT ServiceWorkerDatabase { |
// and next available IDs. |
bool PopulateInitialData(); |
- bool ReadInt64(const leveldb::Slice& key, int64* value_out); |
- bool WriteBatch(scoped_ptr<leveldb::WriteBatch> batch); |
+ bool ReadNextAvailableId(const char* id_key, int64* next_avail_id); |
+ bool ReadRegistrationData( |
+ int64 registration_id, |
+ ServiceWorkerRegistrationData* registration); |
+ bool ReadResourceRecords( |
+ int64 version_id, |
+ std::vector<ServiceWorkerResourceRecord>* resources); |
+ bool WriteBatch(leveldb::WriteBatch* batch); |
+ |
+ // Bumps the next available id specified by |id_key| if |used_id| is greater |
+ // than or equal to the stored one. |
+ bool BumpNextAvailableIdIfNeeded(const char* id_key, |
+ int64 used_id, |
+ leveldb::WriteBatch* batch); |
bool IsOpen(); |
bool IsEmpty(); |
+ void HandleError(const tracked_objects::Location& from_here, |
+ const leveldb::Status& status); |
+ |
base::FilePath path_; |
scoped_ptr<leveldb::Env> env_; |
scoped_ptr<leveldb::DB> db_; |