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

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

Powered by Google App Engine
This is Rietveld 408576698