Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: content/browser/service_worker/service_worker_database.cc

Issue 672813002: [ServiceWorker] Added size deltas and total size computation for QuotaM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RegistrationData output for Delete Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (status != STATUS_OK) 485 if (status != STATUS_OK)
486 return status; 486 return status;
487 487
488 *registration = value; 488 *registration = value;
489 return STATUS_OK; 489 return STATUS_OK;
490 } 490 }
491 491
492 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration( 492 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration(
493 const RegistrationData& registration, 493 const RegistrationData& registration,
494 const std::vector<ResourceRecord>& resources, 494 const std::vector<ResourceRecord>& resources,
495 int64* deleted_version_id, 495 RegistrationData* old_registration,
496 std::vector<int64>* newly_purgeable_resources) { 496 std::vector<int64>* newly_purgeable_resources) {
497 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 497 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
498 *deleted_version_id = kInvalidServiceWorkerVersionId; 498 DCHECK(old_registration);
499 Status status = LazyOpen(true); 499 Status status = LazyOpen(true);
500 old_registration->version_id = kInvalidServiceWorkerVersionId;
500 if (status != STATUS_OK) 501 if (status != STATUS_OK)
501 return status; 502 return status;
502 503
503 leveldb::WriteBatch batch; 504 leveldb::WriteBatch batch;
504 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); 505 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch);
505 BumpNextVersionIdIfNeeded(registration.version_id, &batch); 506 BumpNextVersionIdIfNeeded(registration.version_id, &batch);
506 507
507 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); 508 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch);
508 #if DCHECK_IS_ON 509 #if DCHECK_IS_ON
509 uint64 total_size_bytes = 0; 510 uint64 total_size_bytes = 0;
(...skipping 21 matching lines...) Expand all
531 PutResourceRecordToBatch(*itr, registration.version_id, &batch); 532 PutResourceRecordToBatch(*itr, registration.version_id, &batch);
532 533
533 // Delete a resource from the uncommitted list. 534 // Delete a resource from the uncommitted list.
534 batch.Delete(CreateResourceIdKey( 535 batch.Delete(CreateResourceIdKey(
535 kUncommittedResIdKeyPrefix, itr->resource_id)); 536 kUncommittedResIdKeyPrefix, itr->resource_id));
536 // Delete from the purgeable list in case this version was once deleted. 537 // Delete from the purgeable list in case this version was once deleted.
537 batch.Delete( 538 batch.Delete(
538 CreateResourceIdKey(kPurgeableResIdKeyPrefix, itr->resource_id)); 539 CreateResourceIdKey(kPurgeableResIdKeyPrefix, itr->resource_id));
539 } 540 }
540 541
542 RegistrationData old_registration_on_stack;
michaeln 2014/10/28 22:00:40 is this still needed given DCHECK(old_registration
dmurph 2014/10/29 22:18:25 Done.
543 if (!old_registration) {
544 old_registration = &old_registration_on_stack;
545 }
541 // Retrieve a previous version to sweep purgeable resources. 546 // Retrieve a previous version to sweep purgeable resources.
542 RegistrationData old_registration;
543 status = ReadRegistrationData(registration.registration_id, 547 status = ReadRegistrationData(registration.registration_id,
544 registration.scope.GetOrigin(), 548 registration.scope.GetOrigin(),
545 &old_registration); 549 old_registration);
546 if (status != STATUS_OK && status != STATUS_ERROR_NOT_FOUND) 550 if (status != STATUS_OK && status != STATUS_ERROR_NOT_FOUND)
547 return status; 551 return status;
548 if (status == STATUS_OK) { 552 if (status == STATUS_OK) {
549 DCHECK_LT(old_registration.version_id, registration.version_id); 553 DCHECK_LT(old_registration->version_id, registration.version_id);
550 *deleted_version_id = old_registration.version_id;
551 status = DeleteResourceRecords( 554 status = DeleteResourceRecords(
552 old_registration.version_id, newly_purgeable_resources, &batch); 555 old_registration->version_id, newly_purgeable_resources, &batch);
553 if (status != STATUS_OK) 556 if (status != STATUS_OK)
554 return status; 557 return status;
555 558
556 // Currently resource sharing across versions and registrations is not 559 // Currently resource sharing across versions and registrations is not
557 // supported, so resource ids should not be overlapped between 560 // supported, so resource ids should not be overlapped between
558 // |registration| and |old_registration|. 561 // |registration| and |old_registration|.
559 std::set<int64> deleted_resources(newly_purgeable_resources->begin(), 562 std::set<int64> deleted_resources(newly_purgeable_resources->begin(),
560 newly_purgeable_resources->end()); 563 newly_purgeable_resources->end());
561 DCHECK(base::STLSetIntersection<std::set<int64> >( 564 DCHECK(base::STLSetIntersection<std::set<int64> >(
562 pushed_resources, deleted_resources).empty()); 565 pushed_resources, deleted_resources).empty());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 registration.last_update_check = time; 613 registration.last_update_check = time;
611 614
612 leveldb::WriteBatch batch; 615 leveldb::WriteBatch batch;
613 PutRegistrationDataToBatch(registration, &batch); 616 PutRegistrationDataToBatch(registration, &batch);
614 return WriteBatch(&batch); 617 return WriteBatch(&batch);
615 } 618 }
616 619
617 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteRegistration( 620 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteRegistration(
618 int64 registration_id, 621 int64 registration_id,
619 const GURL& origin, 622 const GURL& origin,
620 int64* version_id, 623 RegistrationData* deleted_version,
621 std::vector<int64>* newly_purgeable_resources) { 624 std::vector<int64>* newly_purgeable_resources) {
622 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 625 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
623 *version_id = kInvalidServiceWorkerVersionId; 626 DCHECK(deleted_version);
627 deleted_version->version_id = kInvalidServiceWorkerVersionId;
624 Status status = LazyOpen(false); 628 Status status = LazyOpen(false);
625 if (IsNewOrNonexistentDatabase(status)) 629 if (IsNewOrNonexistentDatabase(status))
626 return STATUS_OK; 630 return STATUS_OK;
627 if (status != STATUS_OK) 631 if (status != STATUS_OK)
628 return status; 632 return status;
629 if (!origin.is_valid()) 633 if (!origin.is_valid())
630 return STATUS_ERROR_FAILED; 634 return STATUS_ERROR_FAILED;
631 635
632 leveldb::WriteBatch batch; 636 leveldb::WriteBatch batch;
633 637
634 // Remove |origin| from unique origins if a registration specified by 638 // Remove |origin| from unique origins if a registration specified by
635 // |registration_id| is the only one for |origin|. 639 // |registration_id| is the only one for |origin|.
636 // TODO(nhiroki): Check the uniqueness by more efficient way. 640 // TODO(nhiroki): Check the uniqueness by more efficient way.
637 std::vector<RegistrationData> registrations; 641 std::vector<RegistrationData> registrations;
638 status = GetRegistrationsForOrigin(origin, &registrations); 642 status = GetRegistrationsForOrigin(origin, &registrations);
639 if (status != STATUS_OK) 643 if (status != STATUS_OK)
640 return status; 644 return status;
641 645
642 if (registrations.size() == 1 && 646 if (registrations.size() == 1 &&
643 registrations[0].registration_id == registration_id) { 647 registrations[0].registration_id == registration_id) {
644 batch.Delete(CreateUniqueOriginKey(origin)); 648 batch.Delete(CreateUniqueOriginKey(origin));
645 } 649 }
646 650
647 // Delete a registration specified by |registration_id|. 651 // Delete a registration specified by |registration_id|.
648 batch.Delete(CreateRegistrationKey(registration_id, origin)); 652 batch.Delete(CreateRegistrationKey(registration_id, origin));
649 653
650 // Delete resource records associated with the registration. 654 // Delete resource records associated with the registration.
651 for (std::vector<RegistrationData>::const_iterator itr = 655 for (const auto& registration : registrations) {
652 registrations.begin(); itr != registrations.end(); ++itr) { 656 if (registration.registration_id == registration_id) {
653 if (itr->registration_id == registration_id) { 657 deleted_version->version_id = registration.version_id;
michaeln 2014/10/28 22:00:40 should we assign the entire struct here instead of
dmurph 2014/10/29 22:18:25 Done.
654 *version_id = itr->version_id;
655 status = DeleteResourceRecords( 658 status = DeleteResourceRecords(
656 itr->version_id, newly_purgeable_resources, &batch); 659 registration.version_id, newly_purgeable_resources, &batch);
657 if (status != STATUS_OK) 660 if (status != STATUS_OK)
658 return status; 661 return status;
659 break; 662 break;
660 } 663 }
661 } 664 }
662 665
663 return WriteBatch(&batch); 666 return WriteBatch(&batch);
664 } 667 }
665 668
666 ServiceWorkerDatabase::Status 669 ServiceWorkerDatabase::Status
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 1148
1146 void ServiceWorkerDatabase::HandleWriteResult( 1149 void ServiceWorkerDatabase::HandleWriteResult(
1147 const tracked_objects::Location& from_here, 1150 const tracked_objects::Location& from_here,
1148 Status status) { 1151 Status status) {
1149 if (status != STATUS_OK) 1152 if (status != STATUS_OK)
1150 Disable(from_here, status); 1153 Disable(from_here, status);
1151 ServiceWorkerMetrics::CountWriteDatabaseResult(status); 1154 ServiceWorkerMetrics::CountWriteDatabaseResult(status);
1152 } 1155 }
1153 1156
1154 } // namespace content 1157 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698