Chromium Code Reviews| 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 842080ac0bb624840707d4b0ef28cac5beb3f94f..d328e9689afd2f7485c19c01f71c9a28bced02f1 100644 |
| --- a/content/browser/service_worker/service_worker_database.cc |
| +++ b/content/browser/service_worker/service_worker_database.cc |
| @@ -73,6 +73,16 @@ |
| // |
| // key: "REGID_TO_ORIGIN:" + <int64 'registration_id'> |
| // value: <GURL 'origin'> |
| +// |
| +// key: "INITDATA_DISKCACHE_MIGRATED" |
| +// value: <empty> |
| +// - This entry represents that the diskcache was migrated from BlockFile |
| +// backend to Simple backend (http://crbug.com/487482). |
| +// |
| +// key: "INITDATA_OLD_DISKCACHE_EXISTS" |
| +// value: <empty> |
| +// - This entry represents that the diskcahes was migrate, but the old |
| +// BlockFile diskcache still exists (http://crbug.com/487482). |
| namespace content { |
| namespace { |
| @@ -82,6 +92,8 @@ 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 kDiskCacheMigratedKey[] = "INITDATA_DISKCACHE_MIGRATED"; |
|
michaeln
2015/06/12 20:47:58
kDiskCacheMigrationNotNeededKey = "INITDATA_DISKCA
nhiroki
2015/06/15 16:43:27
Done.
|
| +const char kOldDiskCacheExistsKey[] = "INITDATA_OLD_DISKCACHE_EXISTS"; |
|
michaeln
2015/06/12 20:47:57
INITDATA_OLD_DISKCACHE_DELETION_NOT_NEEDED
nhiroki
2015/06/15 16:43:26
Done.
|
| const char kRegKeyPrefix[] = "REG:"; |
| const char kRegUserDataKeyPrefix[] = "REG_USER_DATA:"; |
| @@ -89,6 +101,7 @@ const char kRegHasUserDataKeyPrefix[] = "REG_HAS_USER_DATA:"; |
| const char kRegIdToOriginKeyPrefix[] = "REGID_TO_ORIGIN:"; |
| const char kResKeyPrefix[] = "RES:"; |
| const char kKeySeparator = '\x00'; |
| +const char kEmptyValue[] = ""; |
| const char kUncommittedResIdKeyPrefix[] = "URES:"; |
| const char kPurgeableResIdKeyPrefix[] = "PRES:"; |
| @@ -419,6 +432,65 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetNextAvailableIds( |
| } |
| ServiceWorkerDatabase::Status |
| +ServiceWorkerDatabase::ReadDiskCacheMigrationState( |
|
michaeln
2015/06/12 20:47:58
The simple ReadX and WriteX names are misleading.
nhiroki
2015/06/15 16:43:27
Thank you for the detailed explanation. This looks
|
| + DiskCacheMigrationState* state) { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + |
| + Status status = LazyOpen(false); |
| + if (IsNewOrNonexistentDatabase(status)) { |
| + *state = DISKCACHE_NOT_USED; |
| + return STATUS_OK; |
| + } |
| + if (status != STATUS_OK) |
| + return status; |
| + |
| + std::string value; |
| + status = LevelDBStatusToStatus( |
| + db_->Get(leveldb::ReadOptions(), kDiskCacheMigratedKey, &value)); |
| + if (status != STATUS_ERROR_NOT_FOUND) { |
| + if (status == STATUS_OK) |
| + *state = DISKCACHE_MIGRATED; |
| + HandleReadResult(FROM_HERE, status); |
| + return status; |
| + } |
| + HandleReadResult(FROM_HERE, STATUS_OK); |
| + |
| + status = LevelDBStatusToStatus( |
| + db_->Get(leveldb::ReadOptions(), kOldDiskCacheExistsKey, &value)); |
| + if (status != STATUS_ERROR_NOT_FOUND) { |
| + if (status == STATUS_OK) |
| + *state = DISKCACHE_NEEDS_TO_DELETE_OLD; |
| + HandleReadResult(FROM_HERE, status); |
| + return status; |
| + } |
| + |
| + *state = DISKCACHE_NEEDS_TO_MIGRATE; |
| + HandleReadResult(FROM_HERE, STATUS_OK); |
| + return STATUS_OK; |
| +} |
| + |
| +ServiceWorkerDatabase::Status |
| +ServiceWorkerDatabase::WriteDiskCacheMigrationState( |
| + DiskCacheMigrationState state) { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + DCHECK(state == DISKCACHE_MIGRATED || state == DISKCACHE_NEEDS_TO_DELETE_OLD) |
| + << state; |
| + |
| + Status status = LazyOpen(true); |
| + if (status != STATUS_OK) |
| + return status; |
| + |
| + leveldb::WriteBatch batch; |
| + if (state == DISKCACHE_MIGRATED) { |
| + batch.Put(kDiskCacheMigratedKey, kEmptyValue); |
| + batch.Delete(kOldDiskCacheExistsKey); |
| + } else if (state == DISKCACHE_NEEDS_TO_DELETE_OLD) { |
| + batch.Put(kOldDiskCacheExistsKey, kEmptyValue); |
| + } |
| + return WriteBatch(&batch); |
| +} |
| + |
| +ServiceWorkerDatabase::Status |
| ServiceWorkerDatabase::GetOriginsWithRegistrations(std::set<GURL>* origins) { |
| DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| DCHECK(origins->empty()); |