| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 if (status != STATUS_OK) | 481 if (status != STATUS_OK) |
| 482 return status; | 482 return status; |
| 483 | 483 |
| 484 *registration = value; | 484 *registration = value; |
| 485 return STATUS_OK; | 485 return STATUS_OK; |
| 486 } | 486 } |
| 487 | 487 |
| 488 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration( | 488 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration( |
| 489 const RegistrationData& registration, | 489 const RegistrationData& registration, |
| 490 const std::vector<ResourceRecord>& resources, | 490 const std::vector<ResourceRecord>& resources, |
| 491 int64* deleted_version_id, |
| 491 std::vector<int64>* newly_purgeable_resources) { | 492 std::vector<int64>* newly_purgeable_resources) { |
| 492 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 493 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 494 *deleted_version_id = kInvalidServiceWorkerVersionId; |
| 493 Status status = LazyOpen(true); | 495 Status status = LazyOpen(true); |
| 494 if (status != STATUS_OK) | 496 if (status != STATUS_OK) |
| 495 return status; | 497 return status; |
| 496 | 498 |
| 497 leveldb::WriteBatch batch; | 499 leveldb::WriteBatch batch; |
| 498 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); | 500 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); |
| 499 BumpNextVersionIdIfNeeded(registration.version_id, &batch); | 501 BumpNextVersionIdIfNeeded(registration.version_id, &batch); |
| 500 | 502 |
| 501 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); | 503 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); |
| 502 PutRegistrationDataToBatch(registration, &batch); | 504 PutRegistrationDataToBatch(registration, &batch); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 522 | 524 |
| 523 // Retrieve a previous version to sweep purgeable resources. | 525 // Retrieve a previous version to sweep purgeable resources. |
| 524 RegistrationData old_registration; | 526 RegistrationData old_registration; |
| 525 status = ReadRegistrationData(registration.registration_id, | 527 status = ReadRegistrationData(registration.registration_id, |
| 526 registration.scope.GetOrigin(), | 528 registration.scope.GetOrigin(), |
| 527 &old_registration); | 529 &old_registration); |
| 528 if (status != STATUS_OK && status != STATUS_ERROR_NOT_FOUND) | 530 if (status != STATUS_OK && status != STATUS_ERROR_NOT_FOUND) |
| 529 return status; | 531 return status; |
| 530 if (status == STATUS_OK) { | 532 if (status == STATUS_OK) { |
| 531 DCHECK_LT(old_registration.version_id, registration.version_id); | 533 DCHECK_LT(old_registration.version_id, registration.version_id); |
| 534 *deleted_version_id = old_registration.version_id; |
| 532 status = DeleteResourceRecords( | 535 status = DeleteResourceRecords( |
| 533 old_registration.version_id, newly_purgeable_resources, &batch); | 536 old_registration.version_id, newly_purgeable_resources, &batch); |
| 534 if (status != STATUS_OK) | 537 if (status != STATUS_OK) |
| 535 return status; | 538 return status; |
| 536 | 539 |
| 537 // Currently resource sharing across versions and registrations is not | 540 // Currently resource sharing across versions and registrations is not |
| 538 // supported, so resource ids should not be overlapped between | 541 // supported, so resource ids should not be overlapped between |
| 539 // |registration| and |old_registration|. | 542 // |registration| and |old_registration|. |
| 540 std::set<int64> deleted_resources(newly_purgeable_resources->begin(), | 543 std::set<int64> deleted_resources(newly_purgeable_resources->begin(), |
| 541 newly_purgeable_resources->end()); | 544 newly_purgeable_resources->end()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 registration.last_update_check = time; | 594 registration.last_update_check = time; |
| 592 | 595 |
| 593 leveldb::WriteBatch batch; | 596 leveldb::WriteBatch batch; |
| 594 PutRegistrationDataToBatch(registration, &batch); | 597 PutRegistrationDataToBatch(registration, &batch); |
| 595 return WriteBatch(&batch); | 598 return WriteBatch(&batch); |
| 596 } | 599 } |
| 597 | 600 |
| 598 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteRegistration( | 601 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteRegistration( |
| 599 int64 registration_id, | 602 int64 registration_id, |
| 600 const GURL& origin, | 603 const GURL& origin, |
| 604 int64* version_id, |
| 601 std::vector<int64>* newly_purgeable_resources) { | 605 std::vector<int64>* newly_purgeable_resources) { |
| 602 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 606 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 607 *version_id = kInvalidServiceWorkerVersionId; |
| 603 Status status = LazyOpen(false); | 608 Status status = LazyOpen(false); |
| 604 if (IsNewOrNonexistentDatabase(status)) | 609 if (IsNewOrNonexistentDatabase(status)) |
| 605 return STATUS_OK; | 610 return STATUS_OK; |
| 606 if (status != STATUS_OK) | 611 if (status != STATUS_OK) |
| 607 return status; | 612 return status; |
| 608 if (!origin.is_valid()) | 613 if (!origin.is_valid()) |
| 609 return STATUS_ERROR_FAILED; | 614 return STATUS_ERROR_FAILED; |
| 610 | 615 |
| 611 leveldb::WriteBatch batch; | 616 leveldb::WriteBatch batch; |
| 612 | 617 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 623 batch.Delete(CreateUniqueOriginKey(origin)); | 628 batch.Delete(CreateUniqueOriginKey(origin)); |
| 624 } | 629 } |
| 625 | 630 |
| 626 // Delete a registration specified by |registration_id|. | 631 // Delete a registration specified by |registration_id|. |
| 627 batch.Delete(CreateRegistrationKey(registration_id, origin)); | 632 batch.Delete(CreateRegistrationKey(registration_id, origin)); |
| 628 | 633 |
| 629 // Delete resource records associated with the registration. | 634 // Delete resource records associated with the registration. |
| 630 for (std::vector<RegistrationData>::const_iterator itr = | 635 for (std::vector<RegistrationData>::const_iterator itr = |
| 631 registrations.begin(); itr != registrations.end(); ++itr) { | 636 registrations.begin(); itr != registrations.end(); ++itr) { |
| 632 if (itr->registration_id == registration_id) { | 637 if (itr->registration_id == registration_id) { |
| 638 *version_id = itr->version_id; |
| 633 status = DeleteResourceRecords( | 639 status = DeleteResourceRecords( |
| 634 itr->version_id, newly_purgeable_resources, &batch); | 640 itr->version_id, newly_purgeable_resources, &batch); |
| 635 if (status != STATUS_OK) | 641 if (status != STATUS_OK) |
| 636 return status; | 642 return status; |
| 637 break; | 643 break; |
| 638 } | 644 } |
| 639 } | 645 } |
| 640 | 646 |
| 641 return WriteBatch(&batch); | 647 return WriteBatch(&batch); |
| 642 } | 648 } |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 const tracked_objects::Location& from_here, | 1110 const tracked_objects::Location& from_here, |
| 1105 Status status) { | 1111 Status status) { |
| 1106 if (status != ServiceWorkerDatabase::STATUS_OK) | 1112 if (status != ServiceWorkerDatabase::STATUS_OK) |
| 1107 Disable(from_here, status); | 1113 Disable(from_here, status); |
| 1108 UMA_HISTOGRAM_ENUMERATION(kWriteResultHistogramLabel, | 1114 UMA_HISTOGRAM_ENUMERATION(kWriteResultHistogramLabel, |
| 1109 status, | 1115 status, |
| 1110 ServiceWorkerDatabase::STATUS_ERROR_MAX); | 1116 ServiceWorkerDatabase::STATUS_ERROR_MAX); |
| 1111 } | 1117 } |
| 1112 | 1118 |
| 1113 } // namespace content | 1119 } // namespace content |
| OLD | NEW |