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 4561bf678dfd6428eebafbb43f07e199e5f9182d..db2d331be8ffc2e1b04e1a19890c1678061199fe 100644 |
| --- a/content/browser/service_worker/service_worker_database.cc |
| +++ b/content/browser/service_worker/service_worker_database.cc |
| @@ -499,6 +499,60 @@ bool ServiceWorkerDatabase::ClearPurgeableResourceIds( |
| return DeleteResourceIds(kPurgeableResIdKeyPrefix, ids); |
| } |
| +bool ServiceWorkerDatabase::DeleteAllDataForOrigin(const GURL& origin) { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + if (!LazyOpen(true) || is_disabled_ || !origin.is_valid()) |
| + return false; |
| + |
| + leveldb::WriteBatch batch; |
| + |
| + // Delete from the unique origin list. |
| + batch.Delete(CreateUniqueOriginKey(origin)); |
| + |
| + std::vector<RegistrationData> registrations; |
| + if (!GetRegistrationsForOrigin(origin, ®istrations)) |
| + return false; |
| + |
| + // Delete registrations and resource records. |
| + for (std::vector<RegistrationData>::const_iterator itr = |
| + registrations.begin(); itr != registrations.end(); ++itr) { |
| + batch.Delete(CreateRegistrationKey(itr->registration_id, origin)); |
| + if (!DeleteResourceRecords(itr->version_id, &batch)) |
| + return false; |
| + } |
| + |
| + return WriteBatch(&batch); |
| +} |
| + |
| +bool ServiceWorkerDatabase::DeleteAllData() { |
| + DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| + if (!LazyOpen(true) || is_disabled_) |
| + return false; |
| + |
| + leveldb::WriteBatch batch; |
| + |
| + // Delete until the iterator reaches the end of records. |
|
nhiroki
2014/05/02 16:28:04
Is this expected behavior? I wonder if you want to
jsbell
2014/05/02 17:32:56
If we're going to delete everything, why not just
michaeln
2014/05/05 21:46:36
Right, we probably don't need this method at all.
nhiroki
2014/05/06 15:11:32
Okay, removed.
|
| + scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions())); |
| + for (itr->SeekToFirst(); itr->Valid(); itr->Next()) { |
| + if (!itr->status().ok()) { |
| + HandleError(FROM_HERE, itr->status()); |
| + return false; |
| + } |
| + batch.Delete(itr->key()); |
| + } |
| + |
| + if (!WriteBatch(&batch)) |
| + return false; |
| + |
| + // Initialize on-memory data. |
| + next_avail_registration_id_ = 0; |
| + next_avail_resource_id_ = 0; |
| + next_avail_version_id_ = 0; |
| + is_initialized_ = false; |
| + |
| + return false; |
| +} |
| + |
| bool ServiceWorkerDatabase::LazyOpen(bool create_if_needed) { |
| DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| if (IsOpen()) |