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

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

Issue 355163003: Don't prematurely delete script resources when registration is deleted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months 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 | Annotate | Revision Log
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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 590
591 registration.last_update_check = time; 591 registration.last_update_check = time;
592 592
593 leveldb::WriteBatch batch; 593 leveldb::WriteBatch batch;
594 PutRegistrationDataToBatch(registration, &batch); 594 PutRegistrationDataToBatch(registration, &batch);
595 return WriteBatch(&batch); 595 return WriteBatch(&batch);
596 } 596 }
597 597
598 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteRegistration( 598 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteRegistration(
599 int64 registration_id, 599 int64 registration_id,
600 const GURL& origin, 600 const GURL& origin) {
601 std::vector<int64>* newly_purgeable_resources) {
602 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 601 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
603 Status status = LazyOpen(false); 602 Status status = LazyOpen(false);
604 if (IsNewOrNonexistentDatabase(status)) 603 if (IsNewOrNonexistentDatabase(status))
605 return STATUS_OK; 604 return STATUS_OK;
606 if (status != STATUS_OK) 605 if (status != STATUS_OK)
607 return status; 606 return status;
608 if (!origin.is_valid()) 607 if (!origin.is_valid())
609 return STATUS_ERROR_FAILED; 608 return STATUS_ERROR_FAILED;
610 609
611 leveldb::WriteBatch batch; 610 leveldb::WriteBatch batch;
612 611
613 // Remove |origin| from unique origins if a registration specified by 612 // Remove |origin| from unique origins if a registration specified by
614 // |registration_id| is the only one for |origin|. 613 // |registration_id| is the only one for |origin|.
615 // TODO(nhiroki): Check the uniqueness by more efficient way. 614 // TODO(nhiroki): Check the uniqueness by more efficient way.
616 std::vector<RegistrationData> registrations; 615 std::vector<RegistrationData> registrations;
617 status = GetRegistrationsForOrigin(origin, &registrations); 616 status = GetRegistrationsForOrigin(origin, &registrations);
618 if (status != STATUS_OK) 617 if (status != STATUS_OK)
619 return status; 618 return status;
620 619
621 if (registrations.size() == 1 && 620 if (registrations.size() == 1 &&
622 registrations[0].registration_id == registration_id) { 621 registrations[0].registration_id == registration_id) {
623 batch.Delete(CreateUniqueOriginKey(origin)); 622 batch.Delete(CreateUniqueOriginKey(origin));
624 } 623 }
625 624
626 // Delete a registration specified by |registration_id|. 625 // Delete a registration specified by |registration_id|.
627 batch.Delete(CreateRegistrationKey(registration_id, origin)); 626 batch.Delete(CreateRegistrationKey(registration_id, origin));
628 627
629 // Delete resource records associated with the registration. 628 return WriteBatch(&batch);
michaeln 2014/06/28 02:29:31 We do want to delete the records from the 'resourc
630 for (std::vector<RegistrationData>::const_iterator itr = 629 }
631 registrations.begin(); itr != registrations.end(); ++itr) { 630
632 if (itr->registration_id == registration_id) { 631 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteVersionResources(
633 status = DeleteResourceRecords( 632 int64 version_id,
634 itr->version_id, newly_purgeable_resources, &batch); 633 std::vector<int64>* newly_purgeable_resources) {
635 if (status != STATUS_OK) 634 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
636 return status; 635 Status status = LazyOpen(false);
637 break; 636 if (IsNewOrNonexistentDatabase(status))
638 } 637 return STATUS_OK;
639 } 638 if (status != STATUS_OK)
639 return status;
640
641 leveldb::WriteBatch batch;
642
643 status = DeleteResourceRecords(version_id, newly_purgeable_resources, &batch);
644 if (status != STATUS_OK)
645 return status;
640 646
641 return WriteBatch(&batch); 647 return WriteBatch(&batch);
642 } 648 }
643 649
644 ServiceWorkerDatabase::Status 650 ServiceWorkerDatabase::Status
645 ServiceWorkerDatabase::GetUncommittedResourceIds(std::set<int64>* ids) { 651 ServiceWorkerDatabase::GetUncommittedResourceIds(std::set<int64>* ids) {
646 return ReadResourceIds(kUncommittedResIdKeyPrefix, ids); 652 return ReadResourceIds(kUncommittedResIdKeyPrefix, ids);
647 } 653 }
648 654
649 ServiceWorkerDatabase::Status 655 ServiceWorkerDatabase::Status
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698