Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Unified Diff: content/browser/service_worker/service_worker_database.cc

Issue 1221643014: Service Worker: Migrate to version_uuid and surface ServiceWorker.id. (Chromium 2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_database.cc
diff --git a/content/browser/service_worker/service_worker_database.cc b/content/browser/service_worker/service_worker_database.cc
index 8e3c99a42a8dbcbd645727fdd8b111e031d0d2fa..5f05ab9bf2c669c998b6d796bc25d69f0f08a4b0 100644
--- a/content/browser/service_worker/service_worker_database.cc
+++ b/content/browser/service_worker/service_worker_database.cc
@@ -83,6 +83,17 @@
// value: <empty>
// - This entry represents that the old BlockFile diskcache was deleted
// after diskcache migration (http://crbug.com/487482).
+//
+// Version 3
+//
+// Deprecate
+// key: "INITDATA_NEXT_VERSION_ID"
+// value: <int64 'next_available_version_id'>
+//
+// Data type change
+// key: "RES:" + <std::string 'version_uuid'> + '\x00' + <int64 'resource_id'>
+// (ex. "RES:123456\x00654321")
+// value: <ServiceWorkerResourceRecord serialized as a string>
namespace content {
namespace {
@@ -90,7 +101,6 @@ namespace {
const char kDatabaseVersionKey[] = "INITDATA_DB_VERSION";
const char kNextRegIdKey[] = "INITDATA_NEXT_REGISTRATION_ID";
const char kNextResIdKey[] = "INITDATA_NEXT_RESOURCE_ID";
-const char kNextVerIdKey[] = "INITDATA_NEXT_VERSION_ID";
const char kUniqueOriginKey[] = "INITDATA_UNIQUE_ORIGIN:";
const char kDiskCacheMigrationNotNeededKey[] =
"INITDATA_DISKCACHE_MIGRATION_NOT_NEEDED";
@@ -140,17 +150,15 @@ std::string CreateRegistrationKey(int64 registration_id,
.append(base::Int64ToString(registration_id));
}
-std::string CreateResourceRecordKeyPrefix(int64 version_id) {
- return base::StringPrintf("%s%s%c",
- kResKeyPrefix,
- base::Int64ToString(version_id).c_str(),
+std::string CreateResourceRecordKeyPrefix(std::string version_uuid) {
+ return base::StringPrintf("%s%s%c", kResKeyPrefix, version_uuid.c_str(),
kKeySeparator);
}
-std::string CreateResourceRecordKey(int64 version_id,
+std::string CreateResourceRecordKey(std::string version_uuid,
int64 resource_id) {
- return CreateResourceRecordKeyPrefix(version_id).append(
- base::Int64ToString(resource_id));
+ return CreateResourceRecordKeyPrefix(version_uuid)
+ .append(base::Int64ToString(resource_id));
}
std::string CreateUniqueOriginKey(const GURL& origin) {
@@ -201,7 +209,7 @@ void PutRegistrationDataToBatch(
data.set_registration_id(input.registration_id);
data.set_scope_url(input.scope.spec());
data.set_script_url(input.script.spec());
- data.set_version_id(input.version_id);
+ data.set_version_uuid(input.version_uuid);
data.set_is_active(input.is_active);
data.set_has_fetch_handler(input.has_fetch_handler);
data.set_last_update_check_time(input.last_update_check.ToInternalValue());
@@ -216,7 +224,7 @@ void PutRegistrationDataToBatch(
void PutResourceRecordToBatch(
const ServiceWorkerDatabase::ResourceRecord& input,
- int64 version_id,
+ std::string version_uuid,
leveldb::WriteBatch* batch) {
DCHECK(batch);
DCHECK_GE(input.size_bytes, 0);
@@ -230,7 +238,7 @@ void PutResourceRecordToBatch(
std::string value;
bool success = record.SerializeToString(&value);
DCHECK(success);
- batch->Put(CreateResourceRecordKey(version_id, input.resource_id), value);
+ batch->Put(CreateResourceRecordKey(version_uuid, input.resource_id), value);
}
void PutUniqueOriginToBatch(const GURL& origin,
@@ -299,7 +307,7 @@ ServiceWorkerDatabase::Status ParseRegistrationData(
out->registration_id = data.registration_id();
out->scope = scope_url;
out->script = script_url;
- out->version_id = data.version_id();
+ out->version_uuid = data.version_uuid();
out->is_active = data.is_active();
out->has_fetch_handler = data.has_fetch_handler();
out->last_update_check =
@@ -375,7 +383,7 @@ const char* ServiceWorkerDatabase::StatusToString(
ServiceWorkerDatabase::RegistrationData::RegistrationData()
: registration_id(kInvalidServiceWorkerRegistrationId),
- version_id(kInvalidServiceWorkerVersionId),
+ version_uuid(std::string()),
is_active(false),
has_fetch_handler(false),
resources_total_size_bytes(0) {
@@ -388,7 +396,6 @@ ServiceWorkerDatabase::ServiceWorkerDatabase(const base::FilePath& path)
: path_(path),
next_avail_registration_id_(0),
next_avail_resource_id_(0),
- next_avail_version_id_(0),
state_(UNINITIALIZED),
skip_writing_diskcache_migration_state_on_init_for_testing_(false) {
sequence_checker_.DetachFromSequence();
@@ -401,17 +408,14 @@ ServiceWorkerDatabase::~ServiceWorkerDatabase() {
ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetNextAvailableIds(
int64* next_avail_registration_id,
- int64* next_avail_version_id,
int64* next_avail_resource_id) {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
DCHECK(next_avail_registration_id);
- DCHECK(next_avail_version_id);
DCHECK(next_avail_resource_id);
Status status = LazyOpen(false);
if (IsNewOrNonexistentDatabase(status)) {
*next_avail_registration_id = 0;
- *next_avail_version_id = 0;
*next_avail_resource_id = 0;
return STATUS_OK;
}
@@ -421,15 +425,11 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetNextAvailableIds(
status = ReadNextAvailableId(kNextRegIdKey, &next_avail_registration_id_);
if (status != STATUS_OK)
return status;
- status = ReadNextAvailableId(kNextVerIdKey, &next_avail_version_id_);
- if (status != STATUS_OK)
- return status;
status = ReadNextAvailableId(kNextResIdKey, &next_avail_resource_id_);
if (status != STATUS_OK)
return status;
*next_avail_registration_id = next_avail_registration_id_;
- *next_avail_version_id = next_avail_version_id_;
*next_avail_resource_id = next_avail_resource_id_;
return STATUS_OK;
}
@@ -600,7 +600,7 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetRegistrationsForOrigin(
if (opt_resources_list) {
std::vector<ResourceRecord> resources;
- status = ReadResourceRecords(registration.version_id, &resources);
+ status = ReadResourceRecords(registration.version_uuid, &resources);
if (status != STATUS_OK) {
HandleReadResult(FROM_HERE, status);
registrations->clear();
@@ -672,7 +672,7 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadRegistration(
if (status != STATUS_OK)
return status;
- status = ReadResourceRecords(value.version_id, resources);
+ status = ReadResourceRecords(value.version_uuid, resources);
if (status != STATUS_OK)
return status;
@@ -727,13 +727,13 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration(
DCHECK(old_registration);
DCHECK(!resources.empty());
Status status = LazyOpen(true);
- old_registration->version_id = kInvalidServiceWorkerVersionId;
+ old_registration->version_uuid = std::string();
if (status != STATUS_OK)
return status;
leveldb::WriteBatch batch;
BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch);
- BumpNextVersionIdIfNeeded(registration.version_id, &batch);
+ // BumpNextVersionIdIfNeeded(registration.version_uuid, &batch);
PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch);
@@ -758,7 +758,7 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration(
DCHECK(pushed_resources.insert(itr->resource_id).second);
DCHECK(pushed_urls.insert(itr->url).second);
- PutResourceRecordToBatch(*itr, registration.version_id, &batch);
+ PutResourceRecordToBatch(*itr, registration.version_uuid, &batch);
// Delete a resource from the uncommitted list.
batch.Delete(CreateResourceIdKey(
@@ -775,9 +775,9 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration(
if (status != STATUS_OK && status != STATUS_ERROR_NOT_FOUND)
return status;
if (status == STATUS_OK) {
- DCHECK_LT(old_registration->version_id, registration.version_id);
- status = DeleteResourceRecords(
- old_registration->version_id, newly_purgeable_resources, &batch);
+ DCHECK_NE(old_registration->version_uuid, registration.version_uuid);
+ status = DeleteResourceRecords(old_registration->version_uuid,
+ newly_purgeable_resources, &batch);
if (status != STATUS_OK)
return status;
@@ -849,7 +849,7 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteRegistration(
std::vector<int64>* newly_purgeable_resources) {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
DCHECK(deleted_version);
- deleted_version->version_id = kInvalidServiceWorkerVersionId;
+ deleted_version->version_uuid = std::string();
Status status = LazyOpen(false);
if (IsNewOrNonexistentDatabase(status))
return STATUS_OK;
@@ -881,8 +881,8 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteRegistration(
for (const auto& registration : registrations) {
if (registration.registration_id == registration_id) {
*deleted_version = registration;
- status = DeleteResourceRecords(
- registration.version_id, newly_purgeable_resources, &batch);
+ status = DeleteResourceRecords(registration.version_uuid,
+ newly_purgeable_resources, &batch);
if (status != STATUS_OK)
return status;
@@ -1090,8 +1090,8 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteAllDataForOrigins(
batch.Delete(CreateRegistrationKey(data.registration_id, origin));
batch.Delete(CreateRegistrationIdToOriginKey(data.registration_id));
- status = DeleteResourceRecords(
- data.version_id, newly_purgeable_resources, &batch);
+ status = DeleteResourceRecords(data.version_uuid,
+ newly_purgeable_resources, &batch);
if (status != STATUS_OK)
return status;
@@ -1288,12 +1288,12 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadRegistrationData(
}
ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords(
- int64 version_id,
+ std::string version_uuid,
std::vector<ResourceRecord>* resources) {
DCHECK(resources->empty());
Status status = STATUS_OK;
- const std::string prefix = CreateResourceRecordKeyPrefix(version_id);
+ const std::string prefix = CreateResourceRecordKeyPrefix(version_uuid);
scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions()));
for (itr->Seek(prefix); itr->Valid(); itr->Next()) {
@@ -1322,13 +1322,13 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords(
}
ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteResourceRecords(
- int64 version_id,
+ std::string version_uuid,
std::vector<int64>* newly_purgeable_resources,
leveldb::WriteBatch* batch) {
DCHECK(batch);
Status status = STATUS_OK;
- const std::string prefix = CreateResourceRecordKeyPrefix(version_id);
+ const std::string prefix = CreateResourceRecordKeyPrefix(version_uuid);
scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions()));
for (itr->Seek(prefix); itr->Valid(); itr->Next()) {
@@ -1551,15 +1551,6 @@ void ServiceWorkerDatabase::BumpNextResourceIdIfNeeded(
}
}
-void ServiceWorkerDatabase::BumpNextVersionIdIfNeeded(
- int64 used_id, leveldb::WriteBatch* batch) {
- DCHECK(batch);
- if (next_avail_version_id_ <= used_id) {
- next_avail_version_id_ = used_id + 1;
- batch->Put(kNextVerIdKey, base::Int64ToString(next_avail_version_id_));
- }
-}
-
bool ServiceWorkerDatabase::IsOpen() {
return db_ != NULL;
}
« no previous file with comments | « content/browser/service_worker/service_worker_database.h ('k') | content/browser/service_worker/service_worker_database.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698