Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/service_worker/service_worker_database.h" | 5 #include "content/browser/service_worker/service_worker_database.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 // | 76 // |
| 77 // key: "INITDATA_DISKCACHE_MIGRATION_NOT_NEEDED" | 77 // key: "INITDATA_DISKCACHE_MIGRATION_NOT_NEEDED" |
| 78 // value: <empty> | 78 // value: <empty> |
| 79 // - This entry represents that the diskcache uses the Simple backend and | 79 // - This entry represents that the diskcache uses the Simple backend and |
| 80 // does not have to do diskcache migration (http://crbug.com/487482). | 80 // does not have to do diskcache migration (http://crbug.com/487482). |
| 81 // | 81 // |
| 82 // key: "INITDATA_OLD_DISKCACHE_DELETION_NOT_NEEDED" | 82 // key: "INITDATA_OLD_DISKCACHE_DELETION_NOT_NEEDED" |
| 83 // value: <empty> | 83 // value: <empty> |
| 84 // - This entry represents that the old BlockFile diskcache was deleted | 84 // - This entry represents that the old BlockFile diskcache was deleted |
| 85 // after diskcache migration (http://crbug.com/487482). | 85 // after diskcache migration (http://crbug.com/487482). |
| 86 // | |
| 87 // key: "INITDATA_FOREIGN_FETCH_ORIGIN:" + <GURL 'origin'> | |
| 88 // value: <empty> | |
| 86 namespace content { | 89 namespace content { |
| 87 | 90 |
| 88 namespace { | 91 namespace { |
| 89 | 92 |
| 90 const char kDatabaseVersionKey[] = "INITDATA_DB_VERSION"; | 93 const char kDatabaseVersionKey[] = "INITDATA_DB_VERSION"; |
| 91 const char kNextRegIdKey[] = "INITDATA_NEXT_REGISTRATION_ID"; | 94 const char kNextRegIdKey[] = "INITDATA_NEXT_REGISTRATION_ID"; |
| 92 const char kNextResIdKey[] = "INITDATA_NEXT_RESOURCE_ID"; | 95 const char kNextResIdKey[] = "INITDATA_NEXT_RESOURCE_ID"; |
| 93 const char kNextVerIdKey[] = "INITDATA_NEXT_VERSION_ID"; | 96 const char kNextVerIdKey[] = "INITDATA_NEXT_VERSION_ID"; |
| 94 const char kUniqueOriginKey[] = "INITDATA_UNIQUE_ORIGIN:"; | 97 const char kUniqueOriginKey[] = "INITDATA_UNIQUE_ORIGIN:"; |
| 95 const char kDiskCacheMigrationNotNeededKey[] = | 98 const char kDiskCacheMigrationNotNeededKey[] = |
| 96 "INITDATA_DISKCACHE_MIGRATION_NOT_NEEDED"; | 99 "INITDATA_DISKCACHE_MIGRATION_NOT_NEEDED"; |
| 97 const char kOldDiskCacheDeletionNotNeededKey[] = | 100 const char kOldDiskCacheDeletionNotNeededKey[] = |
| 98 "INITDATA_OLD_DISKCACHE_DELETION_NOT_NEEDED"; | 101 "INITDATA_OLD_DISKCACHE_DELETION_NOT_NEEDED"; |
| 102 const char kForeignFetchOriginKey[] = "INITDATA_FOREIGN_FETCH_ORIGIN:"; | |
| 99 | 103 |
| 100 const char kRegKeyPrefix[] = "REG:"; | 104 const char kRegKeyPrefix[] = "REG:"; |
| 101 const char kRegUserDataKeyPrefix[] = "REG_USER_DATA:"; | 105 const char kRegUserDataKeyPrefix[] = "REG_USER_DATA:"; |
| 102 const char kRegHasUserDataKeyPrefix[] = "REG_HAS_USER_DATA:"; | 106 const char kRegHasUserDataKeyPrefix[] = "REG_HAS_USER_DATA:"; |
| 103 const char kRegIdToOriginKeyPrefix[] = "REGID_TO_ORIGIN:"; | 107 const char kRegIdToOriginKeyPrefix[] = "REGID_TO_ORIGIN:"; |
| 104 const char kResKeyPrefix[] = "RES:"; | 108 const char kResKeyPrefix[] = "RES:"; |
| 105 const char kKeySeparator = '\x00'; | 109 const char kKeySeparator = '\x00'; |
| 106 const char kEmptyValue[] = ""; | 110 const char kEmptyValue[] = ""; |
| 107 | 111 |
| 108 const char kUncommittedResIdKeyPrefix[] = "URES:"; | 112 const char kUncommittedResIdKeyPrefix[] = "URES:"; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 int64 resource_id) { | 155 int64 resource_id) { |
| 152 return CreateResourceRecordKeyPrefix(version_id).append( | 156 return CreateResourceRecordKeyPrefix(version_id).append( |
| 153 base::Int64ToString(resource_id)); | 157 base::Int64ToString(resource_id)); |
| 154 } | 158 } |
| 155 | 159 |
| 156 std::string CreateUniqueOriginKey(const GURL& origin) { | 160 std::string CreateUniqueOriginKey(const GURL& origin) { |
| 157 return base::StringPrintf("%s%s", kUniqueOriginKey, | 161 return base::StringPrintf("%s%s", kUniqueOriginKey, |
| 158 origin.GetOrigin().spec().c_str()); | 162 origin.GetOrigin().spec().c_str()); |
| 159 } | 163 } |
| 160 | 164 |
| 165 std::string CreateForeignFetchOriginKey(const GURL& origin) { | |
| 166 return base::StringPrintf("%s%s", kForeignFetchOriginKey, | |
| 167 origin.GetOrigin().spec().c_str()); | |
| 168 } | |
| 169 | |
| 161 std::string CreateResourceIdKey(const char* key_prefix, int64 resource_id) { | 170 std::string CreateResourceIdKey(const char* key_prefix, int64 resource_id) { |
| 162 return base::StringPrintf( | 171 return base::StringPrintf( |
| 163 "%s%s", key_prefix, base::Int64ToString(resource_id).c_str()); | 172 "%s%s", key_prefix, base::Int64ToString(resource_id).c_str()); |
| 164 } | 173 } |
| 165 | 174 |
| 166 std::string CreateUserDataKeyPrefix(int64 registration_id) { | 175 std::string CreateUserDataKeyPrefix(int64 registration_id) { |
| 167 return base::StringPrintf("%s%s%c", | 176 return base::StringPrintf("%s%s%c", |
| 168 kRegUserDataKeyPrefix, | 177 kRegUserDataKeyPrefix, |
| 169 base::Int64ToString(registration_id).c_str(), | 178 base::Int64ToString(registration_id).c_str(), |
| 170 kKeySeparator); | 179 kKeySeparator); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 199 // Convert RegistrationData to ServiceWorkerRegistrationData. | 208 // Convert RegistrationData to ServiceWorkerRegistrationData. |
| 200 ServiceWorkerRegistrationData data; | 209 ServiceWorkerRegistrationData data; |
| 201 data.set_registration_id(input.registration_id); | 210 data.set_registration_id(input.registration_id); |
| 202 data.set_scope_url(input.scope.spec()); | 211 data.set_scope_url(input.scope.spec()); |
| 203 data.set_script_url(input.script.spec()); | 212 data.set_script_url(input.script.spec()); |
| 204 data.set_version_id(input.version_id); | 213 data.set_version_id(input.version_id); |
| 205 data.set_is_active(input.is_active); | 214 data.set_is_active(input.is_active); |
| 206 data.set_has_fetch_handler(input.has_fetch_handler); | 215 data.set_has_fetch_handler(input.has_fetch_handler); |
| 207 data.set_last_update_check_time(input.last_update_check.ToInternalValue()); | 216 data.set_last_update_check_time(input.last_update_check.ToInternalValue()); |
| 208 data.set_resources_total_size_bytes(input.resources_total_size_bytes); | 217 data.set_resources_total_size_bytes(input.resources_total_size_bytes); |
| 218 for (const GURL& url : input.foreign_fetch_scopes) { | |
|
nhiroki
2015/10/21 05:42:54
Can you add DCHECK to check if |url| is a subscope
Marijn Kruisselbrink
2015/10/21 20:33:46
Done
| |
| 219 data.add_foreign_fetch_scope(url.spec()); | |
| 220 } | |
| 209 | 221 |
| 210 std::string value; | 222 std::string value; |
| 211 bool success = data.SerializeToString(&value); | 223 bool success = data.SerializeToString(&value); |
| 212 DCHECK(success); | 224 DCHECK(success); |
| 213 GURL origin = input.scope.GetOrigin(); | 225 GURL origin = input.scope.GetOrigin(); |
| 214 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); | 226 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); |
| 215 } | 227 } |
| 216 | 228 |
| 217 void PutResourceRecordToBatch( | 229 void PutResourceRecordToBatch( |
| 218 const ServiceWorkerDatabase::ResourceRecord& input, | 230 const ServiceWorkerDatabase::ResourceRecord& input, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 238 // Value should be empty. | 250 // Value should be empty. |
| 239 batch->Put(CreateUniqueOriginKey(origin), ""); | 251 batch->Put(CreateUniqueOriginKey(origin), ""); |
| 240 } | 252 } |
| 241 | 253 |
| 242 void PutPurgeableResourceIdToBatch(int64 resource_id, | 254 void PutPurgeableResourceIdToBatch(int64 resource_id, |
| 243 leveldb::WriteBatch* batch) { | 255 leveldb::WriteBatch* batch) { |
| 244 // Value should be empty. | 256 // Value should be empty. |
| 245 batch->Put(CreateResourceIdKey(kPurgeableResIdKeyPrefix, resource_id), ""); | 257 batch->Put(CreateResourceIdKey(kPurgeableResIdKeyPrefix, resource_id), ""); |
| 246 } | 258 } |
| 247 | 259 |
| 260 void PutForeignFetchOriginToBatch(const GURL& origin, | |
| 261 leveldb::WriteBatch* batch) { | |
| 262 // Value should be empty. | |
| 263 batch->Put(CreateForeignFetchOriginKey(origin), ""); | |
| 264 } | |
| 265 | |
| 248 ServiceWorkerDatabase::Status ParseId( | 266 ServiceWorkerDatabase::Status ParseId( |
| 249 const std::string& serialized, | 267 const std::string& serialized, |
| 250 int64* out) { | 268 int64* out) { |
| 251 DCHECK(out); | 269 DCHECK(out); |
| 252 int64 id; | 270 int64 id; |
| 253 if (!base::StringToInt64(serialized, &id) || id < 0) | 271 if (!base::StringToInt64(serialized, &id) || id < 0) |
| 254 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; | 272 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; |
| 255 *out = id; | 273 *out = id; |
| 256 return ServiceWorkerDatabase::STATUS_OK; | 274 return ServiceWorkerDatabase::STATUS_OK; |
| 257 } | 275 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 // Convert ServiceWorkerRegistrationData to RegistrationData. | 316 // Convert ServiceWorkerRegistrationData to RegistrationData. |
| 299 out->registration_id = data.registration_id(); | 317 out->registration_id = data.registration_id(); |
| 300 out->scope = scope_url; | 318 out->scope = scope_url; |
| 301 out->script = script_url; | 319 out->script = script_url; |
| 302 out->version_id = data.version_id(); | 320 out->version_id = data.version_id(); |
| 303 out->is_active = data.is_active(); | 321 out->is_active = data.is_active(); |
| 304 out->has_fetch_handler = data.has_fetch_handler(); | 322 out->has_fetch_handler = data.has_fetch_handler(); |
| 305 out->last_update_check = | 323 out->last_update_check = |
| 306 base::Time::FromInternalValue(data.last_update_check_time()); | 324 base::Time::FromInternalValue(data.last_update_check_time()); |
| 307 out->resources_total_size_bytes = data.resources_total_size_bytes(); | 325 out->resources_total_size_bytes = data.resources_total_size_bytes(); |
| 326 for (int i = 0; i < data.foreign_fetch_scope_size(); ++i) { | |
| 327 out->foreign_fetch_scopes.push_back(GURL(data.foreign_fetch_scope(i))); | |
|
nhiroki
2015/10/21 05:42:54
Can you check if |foreign_fetch_scope| is a subsco
Marijn Kruisselbrink
2015/10/21 20:33:46
Done
| |
| 328 } | |
| 308 | 329 |
| 309 return ServiceWorkerDatabase::STATUS_OK; | 330 return ServiceWorkerDatabase::STATUS_OK; |
| 310 } | 331 } |
| 311 | 332 |
| 312 ServiceWorkerDatabase::Status ParseResourceRecord( | 333 ServiceWorkerDatabase::Status ParseResourceRecord( |
| 313 const std::string& serialized, | 334 const std::string& serialized, |
| 314 ServiceWorkerDatabase::ResourceRecord* out) { | 335 ServiceWorkerDatabase::ResourceRecord* out) { |
| 315 DCHECK(out); | 336 DCHECK(out); |
| 316 ServiceWorkerResourceRecord record; | 337 ServiceWorkerResourceRecord record; |
| 317 if (!record.ParseFromString(serialized)) | 338 if (!record.ParseFromString(serialized)) |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 return status; | 573 return status; |
| 553 } | 574 } |
| 554 | 575 |
| 555 origins->insert(origin); | 576 origins->insert(origin); |
| 556 } | 577 } |
| 557 | 578 |
| 558 HandleReadResult(FROM_HERE, status); | 579 HandleReadResult(FROM_HERE, status); |
| 559 return status; | 580 return status; |
| 560 } | 581 } |
| 561 | 582 |
| 583 ServiceWorkerDatabase::Status | |
| 584 ServiceWorkerDatabase::GetOriginsWithForeignFetchRegistrations( | |
| 585 std::set<GURL>* origins) { | |
| 586 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | |
| 587 DCHECK(origins->empty()); | |
| 588 | |
| 589 Status status = LazyOpen(false); | |
| 590 if (IsNewOrNonexistentDatabase(status)) | |
| 591 return STATUS_OK; | |
| 592 if (status != STATUS_OK) | |
| 593 return status; | |
| 594 | |
| 595 scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions())); | |
| 596 for (itr->Seek(kForeignFetchOriginKey); itr->Valid(); itr->Next()) { | |
| 597 status = LevelDBStatusToStatus(itr->status()); | |
| 598 if (status != STATUS_OK) { | |
| 599 HandleReadResult(FROM_HERE, status); | |
| 600 origins->clear(); | |
| 601 return status; | |
| 602 } | |
| 603 | |
| 604 std::string origin_str; | |
| 605 if (!RemovePrefix(itr->key().ToString(), kForeignFetchOriginKey, | |
| 606 &origin_str)) | |
| 607 break; | |
| 608 | |
| 609 GURL origin(origin_str); | |
| 610 if (!origin.is_valid()) { | |
| 611 status = STATUS_ERROR_CORRUPTED; | |
| 612 HandleReadResult(FROM_HERE, status); | |
| 613 origins->clear(); | |
| 614 return status; | |
| 615 } | |
| 616 | |
| 617 origins->insert(origin); | |
| 618 } | |
| 619 | |
| 620 HandleReadResult(FROM_HERE, status); | |
| 621 return status; | |
| 622 } | |
| 623 | |
| 562 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetRegistrationsForOrigin( | 624 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetRegistrationsForOrigin( |
| 563 const GURL& origin, | 625 const GURL& origin, |
| 564 std::vector<RegistrationData>* registrations, | 626 std::vector<RegistrationData>* registrations, |
| 565 std::vector<std::vector<ResourceRecord>>* opt_resources_list) { | 627 std::vector<std::vector<ResourceRecord>>* opt_resources_list) { |
| 566 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 628 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 567 DCHECK(registrations->empty()); | 629 DCHECK(registrations->empty()); |
| 568 | 630 |
| 569 Status status = LazyOpen(false); | 631 Status status = LazyOpen(false); |
| 570 if (IsNewOrNonexistentDatabase(status)) | 632 if (IsNewOrNonexistentDatabase(status)) |
| 571 return STATUS_OK; | 633 return STATUS_OK; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 old_registration->version_id = kInvalidServiceWorkerVersionId; | 792 old_registration->version_id = kInvalidServiceWorkerVersionId; |
| 731 if (status != STATUS_OK) | 793 if (status != STATUS_OK) |
| 732 return status; | 794 return status; |
| 733 | 795 |
| 734 leveldb::WriteBatch batch; | 796 leveldb::WriteBatch batch; |
| 735 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); | 797 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); |
| 736 BumpNextVersionIdIfNeeded(registration.version_id, &batch); | 798 BumpNextVersionIdIfNeeded(registration.version_id, &batch); |
| 737 | 799 |
| 738 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); | 800 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); |
| 739 | 801 |
| 802 if (!registration.foreign_fetch_scopes.empty()) | |
| 803 PutForeignFetchOriginToBatch(registration.scope.GetOrigin(), &batch); | |
| 804 | |
| 740 DCHECK_EQ(AccumulateResourceSizeInBytes(resources), | 805 DCHECK_EQ(AccumulateResourceSizeInBytes(resources), |
| 741 registration.resources_total_size_bytes) | 806 registration.resources_total_size_bytes) |
| 742 << "The total size in the registration must match the cumulative " | 807 << "The total size in the registration must match the cumulative " |
| 743 << "sizes of the resources."; | 808 << "sizes of the resources."; |
| 744 | 809 |
| 745 PutRegistrationDataToBatch(registration, &batch); | 810 PutRegistrationDataToBatch(registration, &batch); |
| 746 batch.Put(CreateRegistrationIdToOriginKey(registration.registration_id), | 811 batch.Put(CreateRegistrationIdToOriginKey(registration.registration_id), |
| 747 registration.scope.GetOrigin().spec()); | 812 registration.scope.GetOrigin().spec()); |
| 748 | 813 |
| 749 // Used for avoiding multiple writes for the same resource id or url. | 814 // Used for avoiding multiple writes for the same resource id or url. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 if (status != STATUS_OK) | 846 if (status != STATUS_OK) |
| 782 return status; | 847 return status; |
| 783 | 848 |
| 784 // Currently resource sharing across versions and registrations is not | 849 // Currently resource sharing across versions and registrations is not |
| 785 // supported, so resource ids should not be overlapped between | 850 // supported, so resource ids should not be overlapped between |
| 786 // |registration| and |old_registration|. | 851 // |registration| and |old_registration|. |
| 787 std::set<int64> deleted_resources(newly_purgeable_resources->begin(), | 852 std::set<int64> deleted_resources(newly_purgeable_resources->begin(), |
| 788 newly_purgeable_resources->end()); | 853 newly_purgeable_resources->end()); |
| 789 DCHECK(base::STLSetIntersection<std::set<int64> >( | 854 DCHECK(base::STLSetIntersection<std::set<int64> >( |
| 790 pushed_resources, deleted_resources).empty()); | 855 pushed_resources, deleted_resources).empty()); |
| 856 | |
| 857 // If old registration had foreign fetch scopes, but new registration | |
| 858 // doesn't, the origin might have to be removed from the list of origins | |
| 859 // with foreign fetch scopes. | |
| 860 // TODO(mek): Like the similar check in DeleteRegistration, ideally this | |
| 861 // could be done more efficiently. | |
| 862 if (!old_registration->foreign_fetch_scopes.empty() && | |
| 863 registration.foreign_fetch_scopes.empty()) { | |
| 864 std::vector<RegistrationData> registrations; | |
| 865 status = GetRegistrationsForOrigin(registration.scope.GetOrigin(), | |
| 866 ®istrations, nullptr); | |
| 867 if (status != STATUS_OK) | |
| 868 return status; | |
| 869 bool remaining_ff_scopes = false; | |
| 870 for (const auto& existing_reg : registrations) { | |
| 871 if (existing_reg.registration_id != registration.registration_id && | |
| 872 !existing_reg.foreign_fetch_scopes.empty()) { | |
| 873 remaining_ff_scopes = true; | |
| 874 break; | |
| 875 } | |
| 876 } | |
| 877 if (!remaining_ff_scopes) | |
| 878 batch.Delete( | |
| 879 CreateForeignFetchOriginKey(registration.scope.GetOrigin())); | |
| 880 } | |
| 791 } | 881 } |
| 792 | 882 |
| 793 return WriteBatch(&batch); | 883 return WriteBatch(&batch); |
| 794 } | 884 } |
| 795 | 885 |
| 796 ServiceWorkerDatabase::Status ServiceWorkerDatabase::UpdateVersionToActive( | 886 ServiceWorkerDatabase::Status ServiceWorkerDatabase::UpdateVersionToActive( |
| 797 int64 registration_id, | 887 int64 registration_id, |
| 798 const GURL& origin) { | 888 const GURL& origin) { |
| 799 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 889 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 800 Status status = LazyOpen(false); | 890 Status status = LazyOpen(false); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 866 std::vector<RegistrationData> registrations; | 956 std::vector<RegistrationData> registrations; |
| 867 status = GetRegistrationsForOrigin(origin, ®istrations, nullptr); | 957 status = GetRegistrationsForOrigin(origin, ®istrations, nullptr); |
| 868 if (status != STATUS_OK) | 958 if (status != STATUS_OK) |
| 869 return status; | 959 return status; |
| 870 | 960 |
| 871 if (registrations.size() == 1 && | 961 if (registrations.size() == 1 && |
| 872 registrations[0].registration_id == registration_id) { | 962 registrations[0].registration_id == registration_id) { |
| 873 batch.Delete(CreateUniqueOriginKey(origin)); | 963 batch.Delete(CreateUniqueOriginKey(origin)); |
| 874 } | 964 } |
| 875 | 965 |
| 966 // Remove |origin| from foreign fetch origins if a registration specified by | |
| 967 // |registration_id| is the only one with foreign fetch scopes for |origin|. | |
| 968 bool remaining_ff_scopes = false; | |
| 969 for (const auto& registration : registrations) { | |
| 970 if (registration.registration_id != registration_id && | |
| 971 !registration.foreign_fetch_scopes.empty()) { | |
| 972 remaining_ff_scopes = true; | |
| 973 break; | |
| 974 } | |
| 975 } | |
| 976 if (!remaining_ff_scopes) | |
| 977 batch.Delete(CreateForeignFetchOriginKey(origin)); | |
| 978 | |
| 876 // Delete a registration specified by |registration_id|. | 979 // Delete a registration specified by |registration_id|. |
| 877 batch.Delete(CreateRegistrationKey(registration_id, origin)); | 980 batch.Delete(CreateRegistrationKey(registration_id, origin)); |
| 878 batch.Delete(CreateRegistrationIdToOriginKey(registration_id)); | 981 batch.Delete(CreateRegistrationIdToOriginKey(registration_id)); |
| 879 | 982 |
| 880 // Delete resource records and user data associated with the registration. | 983 // Delete resource records and user data associated with the registration. |
| 881 for (const auto& registration : registrations) { | 984 for (const auto& registration : registrations) { |
| 882 if (registration.registration_id == registration_id) { | 985 if (registration.registration_id == registration_id) { |
| 883 *deleted_version = registration; | 986 *deleted_version = registration; |
| 884 status = DeleteResourceRecords( | 987 status = DeleteResourceRecords( |
| 885 registration.version_id, newly_purgeable_resources, &batch); | 988 registration.version_id, newly_purgeable_resources, &batch); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 return status; | 1176 return status; |
| 1074 leveldb::WriteBatch batch; | 1177 leveldb::WriteBatch batch; |
| 1075 | 1178 |
| 1076 for (const GURL& origin : origins) { | 1179 for (const GURL& origin : origins) { |
| 1077 if (!origin.is_valid()) | 1180 if (!origin.is_valid()) |
| 1078 return STATUS_ERROR_FAILED; | 1181 return STATUS_ERROR_FAILED; |
| 1079 | 1182 |
| 1080 // Delete from the unique origin list. | 1183 // Delete from the unique origin list. |
| 1081 batch.Delete(CreateUniqueOriginKey(origin)); | 1184 batch.Delete(CreateUniqueOriginKey(origin)); |
| 1082 | 1185 |
| 1186 // Delete from the foreign fetch origin list. | |
| 1187 batch.Delete(CreateForeignFetchOriginKey(origin)); | |
| 1188 | |
| 1083 std::vector<RegistrationData> registrations; | 1189 std::vector<RegistrationData> registrations; |
| 1084 status = GetRegistrationsForOrigin(origin, ®istrations, nullptr); | 1190 status = GetRegistrationsForOrigin(origin, ®istrations, nullptr); |
| 1085 if (status != STATUS_OK) | 1191 if (status != STATUS_OK) |
| 1086 return status; | 1192 return status; |
| 1087 | 1193 |
| 1088 // Delete registrations, resource records and user data. | 1194 // Delete registrations, resource records and user data. |
| 1089 for (const RegistrationData& data : registrations) { | 1195 for (const RegistrationData& data : registrations) { |
| 1090 batch.Delete(CreateRegistrationKey(data.registration_id, origin)); | 1196 batch.Delete(CreateRegistrationKey(data.registration_id, origin)); |
| 1091 batch.Delete(CreateRegistrationIdToOriginKey(data.registration_id)); | 1197 batch.Delete(CreateRegistrationIdToOriginKey(data.registration_id)); |
| 1092 | 1198 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1579 if (status != STATUS_OK) | 1685 if (status != STATUS_OK) |
| 1580 Disable(from_here, status); | 1686 Disable(from_here, status); |
| 1581 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1687 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1582 } | 1688 } |
| 1583 | 1689 |
| 1584 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1690 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
| 1585 return path_.empty(); | 1691 return path_.empty(); |
| 1586 } | 1692 } |
| 1587 | 1693 |
| 1588 } // namespace content | 1694 } // namespace content |
| OLD | NEW |