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/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 | 442 |
443 origins->insert(origin); | 443 origins->insert(origin); |
444 } | 444 } |
445 | 445 |
446 HandleReadResult(FROM_HERE, status); | 446 HandleReadResult(FROM_HERE, status); |
447 return status; | 447 return status; |
448 } | 448 } |
449 | 449 |
450 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetRegistrationsForOrigin( | 450 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetRegistrationsForOrigin( |
451 const GURL& origin, | 451 const GURL& origin, |
452 std::vector<RegistrationData>* registrations) { | 452 std::vector<RegistrationData>* registrations, |
453 std::vector<std::vector<ResourceRecord>>* opt_resources_list) { | |
453 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 454 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
454 DCHECK(registrations->empty()); | 455 DCHECK(registrations->empty()); |
455 | 456 |
456 Status status = LazyOpen(false); | 457 Status status = LazyOpen(false); |
457 if (IsNewOrNonexistentDatabase(status)) | 458 if (IsNewOrNonexistentDatabase(status)) |
458 return STATUS_OK; | 459 return STATUS_OK; |
459 if (status != STATUS_OK) | 460 if (status != STATUS_OK) |
460 return status; | 461 return status; |
461 | 462 |
462 std::string prefix = CreateRegistrationKeyPrefix(origin); | 463 std::string prefix = CreateRegistrationKeyPrefix(origin); |
(...skipping 10 matching lines...) Expand all Loading... | |
473 break; | 474 break; |
474 | 475 |
475 RegistrationData registration; | 476 RegistrationData registration; |
476 status = ParseRegistrationData(itr->value().ToString(), ®istration); | 477 status = ParseRegistrationData(itr->value().ToString(), ®istration); |
477 if (status != STATUS_OK) { | 478 if (status != STATUS_OK) { |
478 HandleReadResult(FROM_HERE, status); | 479 HandleReadResult(FROM_HERE, status); |
479 registrations->clear(); | 480 registrations->clear(); |
480 return status; | 481 return status; |
481 } | 482 } |
482 registrations->push_back(registration); | 483 registrations->push_back(registration); |
484 | |
485 if (opt_resources_list) { | |
486 std::vector<ResourceRecord> resources; | |
487 status = ReadResourceRecords(registration.version_id, &resources); | |
488 if (status != STATUS_OK) { | |
489 HandleReadResult(FROM_HERE, status); | |
falken
2015/06/09 07:37:51
Maybe we should do registrations->clear() here als
| |
490 opt_resources_list->clear(); | |
491 return status; | |
492 } | |
493 opt_resources_list->push_back(resources); | |
494 } | |
483 } | 495 } |
484 | 496 |
485 HandleReadResult(FROM_HERE, status); | 497 HandleReadResult(FROM_HERE, status); |
486 return status; | 498 return status; |
487 } | 499 } |
488 | 500 |
489 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetAllRegistrations( | 501 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetAllRegistrations( |
490 std::vector<RegistrationData>* registrations) { | 502 std::vector<RegistrationData>* registrations) { |
491 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 503 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
492 DCHECK(registrations->empty()); | 504 DCHECK(registrations->empty()); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 return status; | 740 return status; |
729 if (!origin.is_valid()) | 741 if (!origin.is_valid()) |
730 return STATUS_ERROR_FAILED; | 742 return STATUS_ERROR_FAILED; |
731 | 743 |
732 leveldb::WriteBatch batch; | 744 leveldb::WriteBatch batch; |
733 | 745 |
734 // Remove |origin| from unique origins if a registration specified by | 746 // Remove |origin| from unique origins if a registration specified by |
735 // |registration_id| is the only one for |origin|. | 747 // |registration_id| is the only one for |origin|. |
736 // TODO(nhiroki): Check the uniqueness by more efficient way. | 748 // TODO(nhiroki): Check the uniqueness by more efficient way. |
737 std::vector<RegistrationData> registrations; | 749 std::vector<RegistrationData> registrations; |
738 status = GetRegistrationsForOrigin(origin, ®istrations); | 750 status = GetRegistrationsForOrigin(origin, ®istrations, nullptr); |
739 if (status != STATUS_OK) | 751 if (status != STATUS_OK) |
740 return status; | 752 return status; |
741 | 753 |
742 if (registrations.size() == 1 && | 754 if (registrations.size() == 1 && |
743 registrations[0].registration_id == registration_id) { | 755 registrations[0].registration_id == registration_id) { |
744 batch.Delete(CreateUniqueOriginKey(origin)); | 756 batch.Delete(CreateUniqueOriginKey(origin)); |
745 } | 757 } |
746 | 758 |
747 // Delete a registration specified by |registration_id|. | 759 // Delete a registration specified by |registration_id|. |
748 batch.Delete(CreateRegistrationKey(registration_id, origin)); | 760 batch.Delete(CreateRegistrationKey(registration_id, origin)); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 leveldb::WriteBatch batch; | 957 leveldb::WriteBatch batch; |
946 | 958 |
947 for (const GURL& origin : origins) { | 959 for (const GURL& origin : origins) { |
948 if (!origin.is_valid()) | 960 if (!origin.is_valid()) |
949 return STATUS_ERROR_FAILED; | 961 return STATUS_ERROR_FAILED; |
950 | 962 |
951 // Delete from the unique origin list. | 963 // Delete from the unique origin list. |
952 batch.Delete(CreateUniqueOriginKey(origin)); | 964 batch.Delete(CreateUniqueOriginKey(origin)); |
953 | 965 |
954 std::vector<RegistrationData> registrations; | 966 std::vector<RegistrationData> registrations; |
955 status = GetRegistrationsForOrigin(origin, ®istrations); | 967 status = GetRegistrationsForOrigin(origin, ®istrations, nullptr); |
956 if (status != STATUS_OK) | 968 if (status != STATUS_OK) |
957 return status; | 969 return status; |
958 | 970 |
959 // Delete registrations, resource records and user data. | 971 // Delete registrations, resource records and user data. |
960 for (const RegistrationData& data : registrations) { | 972 for (const RegistrationData& data : registrations) { |
961 batch.Delete(CreateRegistrationKey(data.registration_id, origin)); | 973 batch.Delete(CreateRegistrationKey(data.registration_id, origin)); |
962 batch.Delete(CreateRegistrationIdToOriginKey(data.registration_id)); | 974 batch.Delete(CreateRegistrationIdToOriginKey(data.registration_id)); |
963 | 975 |
964 status = DeleteResourceRecords( | 976 status = DeleteResourceRecords( |
965 data.version_id, newly_purgeable_resources, &batch); | 977 data.version_id, newly_purgeable_resources, &batch); |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1466 | 1478 |
1467 void ServiceWorkerDatabase::HandleWriteResult( | 1479 void ServiceWorkerDatabase::HandleWriteResult( |
1468 const tracked_objects::Location& from_here, | 1480 const tracked_objects::Location& from_here, |
1469 Status status) { | 1481 Status status) { |
1470 if (status != STATUS_OK) | 1482 if (status != STATUS_OK) |
1471 Disable(from_here, status); | 1483 Disable(from_here, status); |
1472 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1484 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1473 } | 1485 } |
1474 | 1486 |
1475 } // namespace content | 1487 } // namespace content |
OLD | NEW |