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 4da2ca77aa7de0fda7db944507d15f7e467bc4e5..7c5d352695d9004f1aa178d91038d2322468dfef 100644 |
| --- a/content/browser/service_worker/service_worker_database.cc |
| +++ b/content/browser/service_worker/service_worker_database.cc |
| @@ -72,6 +72,12 @@ |
| // |
| // key: "REGID_TO_ORIGIN:" + <int64 'registration_id'> |
| // value: <GURL 'origin'> |
| +// |
| +// key: "INITDATA_DISKCACHE_VERSION" |
|
michaeln
2015/06/11 00:52:38
It feels a little early to generalize a diskcache
nhiroki
2015/06/11 21:04:50
I was thinking to keep these fields after migratio
|
| +// value: <int64 'current_disk_cache_version'> |
| +// |
| +// key: "INITDATA_PURGEABLE_FILE:" + <string 'filename'> |
| +// value: <empty> |
| namespace content { |
| namespace { |
| @@ -81,6 +87,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 kDiskCacheVersionKey[] = "INITDATA_DISKCACHE_VERSION"; |
| +const char kPurgeableFileKey[] = "INITDATA_PURGEABLE_FILE:"; |
| const char kRegKeyPrefix[] = "REG:"; |
| const char kRegUserDataKeyPrefix[] = "REG_USER_DATA:"; |
| @@ -88,6 +96,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:"; |
| @@ -408,6 +417,50 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetNextAvailableIds( |
| return STATUS_OK; |
| } |
| +ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadDiskCacheVersion( |
| + int64* disk_cache_version) { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + |
| + Status status = LazyOpen(false); |
| + if (IsNewOrNonexistentDatabase(status)) { |
| + *disk_cache_version = 0; |
|
michaeln
2015/06/11 00:52:38
should this be kCurrentDiskCacheVersion?
nhiroki
2015/06/11 21:04:50
(This code is gone)
|
| + return STATUS_OK; |
| + } |
| + if (status != STATUS_OK) |
| + return status; |
| + |
| + std::string value; |
| + status = LevelDBStatusToStatus( |
| + db_->Get(leveldb::ReadOptions(), kDiskCacheVersionKey, &value)); |
| + if (status == STATUS_ERROR_NOT_FOUND) { |
| + *disk_cache_version = 0; |
| + HandleReadResult(FROM_HERE, STATUS_OK); |
| + return STATUS_OK; |
| + } |
| + |
| + if (status != STATUS_OK) { |
| + HandleReadResult(FROM_HERE, status); |
| + return status; |
| + } |
| + |
| + status = ParseId(value, disk_cache_version); |
| + HandleReadResult(FROM_HERE, status); |
| + return status; |
| +} |
| + |
| +ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteDiskCacheVersion( |
| + int64 disk_cache_version) { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + |
| + Status status = LazyOpen(false); |
| + if (status != STATUS_OK) |
| + return status; |
| + |
| + leveldb::WriteBatch batch; |
| + batch.Put(kDiskCacheVersionKey, base::Int64ToString(disk_cache_version)); |
| + return WriteBatch(&batch); |
| +} |
| + |
| ServiceWorkerDatabase::Status |
| ServiceWorkerDatabase::GetOriginsWithRegistrations(std::set<GURL>* origins) { |
| DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| @@ -933,6 +986,74 @@ ServiceWorkerDatabase::PurgeUncommittedResourceIds( |
| return WriteBatch(&batch); |
| } |
| +ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetPurgeableFiles( |
| + std::vector<std::string>* filenames) { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + DCHECK(filenames->empty()); |
| + |
| + Status status = LazyOpen(false); |
| + if (IsNewOrNonexistentDatabase(status)) |
| + return STATUS_OK; |
| + if (status != STATUS_OK) |
| + return status; |
| + |
| + scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions())); |
| + for (itr->Seek(kPurgeableFileKey); itr->Valid(); itr->Next()) { |
| + status = LevelDBStatusToStatus(itr->status()); |
| + if (status != STATUS_OK) { |
| + HandleReadResult(FROM_HERE, status); |
| + filenames->clear(); |
| + return status; |
| + } |
| + |
| + std::string filename; |
| + if (!RemovePrefix(itr->key().ToString(), kPurgeableFileKey, &filename)) |
| + break; |
| + |
| + if (filename.empty()) { |
| + HandleReadResult(FROM_HERE, STATUS_ERROR_CORRUPTED); |
| + filenames->clear(); |
| + return status; |
| + } |
| + filenames->push_back(filename); |
| + } |
| + |
| + HandleReadResult(FROM_HERE, status); |
| + return status; |
| +} |
| + |
| +ServiceWorkerDatabase::Status ServiceWorkerDatabase::WritePurgeableFile( |
| + const std::string& filename) { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + if (filename.empty()) |
|
michaeln
2015/06/11 00:52:38
when would we ever expect empty names here?
nhiroki
2015/06/11 21:04:50
(This code is gone)
|
| + return ServiceWorkerDatabase::STATUS_OK; |
| + |
| + Status status = LazyOpen(true); |
| + if (status != STATUS_OK) |
| + return status; |
| + |
| + leveldb::WriteBatch batch; |
| + batch.Put(std::string(kPurgeableFileKey).append(filename), kEmptyValue); |
| + return WriteBatch(&batch); |
| +} |
| + |
| +ServiceWorkerDatabase::Status ServiceWorkerDatabase::ClearPurgeableFile( |
| + const std::string& filename) { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + if (filename.empty()) |
| + return ServiceWorkerDatabase::STATUS_OK; |
| + |
| + Status status = LazyOpen(false); |
| + if (IsNewOrNonexistentDatabase(status)) |
| + return STATUS_OK; |
| + if (status != STATUS_OK) |
| + return status; |
| + |
| + leveldb::WriteBatch batch; |
| + batch.Delete(std::string(kPurgeableFileKey).append(filename)); |
| + return WriteBatch(&batch); |
| +} |
| + |
| ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteAllDataForOrigins( |
| const std::set<GURL>& origins, |
| std::vector<int64>* newly_purgeable_resources) { |