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

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: 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;
499 Status status = LazyOpen(true); 498 Status status = LazyOpen(true);
499 if (old_registration) {
michaeln 2014/10/24 23:15:47 do we have a usage that passes in null? if not, le
dmurph 2014/10/27 21:37:06 Done.
500 old_registration->version_id = kInvalidServiceWorkerVersionId;
501 }
500 if (status != STATUS_OK) 502 if (status != STATUS_OK)
501 return status; 503 return status;
502 504
503 leveldb::WriteBatch batch; 505 leveldb::WriteBatch batch;
504 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); 506 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch);
505 BumpNextVersionIdIfNeeded(registration.version_id, &batch); 507 BumpNextVersionIdIfNeeded(registration.version_id, &batch);
506 508
507 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); 509 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch);
508 #if DCHECK_IS_ON 510 #if DCHECK_IS_ON
509 uint64 total_size_bytes = 0; 511 uint64 total_size_bytes = 0;
(...skipping 21 matching lines...) Expand all
531 PutResourceRecordToBatch(*itr, registration.version_id, &batch); 533 PutResourceRecordToBatch(*itr, registration.version_id, &batch);
532 534
533 // Delete a resource from the uncommitted list. 535 // Delete a resource from the uncommitted list.
534 batch.Delete(CreateResourceIdKey( 536 batch.Delete(CreateResourceIdKey(
535 kUncommittedResIdKeyPrefix, itr->resource_id)); 537 kUncommittedResIdKeyPrefix, itr->resource_id));
536 // Delete from the purgeable list in case this version was once deleted. 538 // Delete from the purgeable list in case this version was once deleted.
537 batch.Delete( 539 batch.Delete(
538 CreateResourceIdKey(kPurgeableResIdKeyPrefix, itr->resource_id)); 540 CreateResourceIdKey(kPurgeableResIdKeyPrefix, itr->resource_id));
539 } 541 }
540 542
543 RegistrationData old_registration_on_stack;
544 if (!old_registration) {
545 old_registration = &old_registration_on_stack;
546 }
541 // Retrieve a previous version to sweep purgeable resources. 547 // Retrieve a previous version to sweep purgeable resources.
542 RegistrationData old_registration;
543 status = ReadRegistrationData(registration.registration_id, 548 status = ReadRegistrationData(registration.registration_id,
544 registration.scope.GetOrigin(), 549 registration.scope.GetOrigin(),
545 &old_registration); 550 old_registration);
546 if (status != STATUS_OK && status != STATUS_ERROR_NOT_FOUND) 551 if (status != STATUS_OK && status != STATUS_ERROR_NOT_FOUND)
547 return status; 552 return status;
548 if (status == STATUS_OK) { 553 if (status == STATUS_OK) {
549 DCHECK_LT(old_registration.version_id, registration.version_id); 554 DCHECK_LT(old_registration->version_id, registration.version_id);
550 *deleted_version_id = old_registration.version_id;
551 status = DeleteResourceRecords( 555 status = DeleteResourceRecords(
552 old_registration.version_id, newly_purgeable_resources, &batch); 556 old_registration->version_id, newly_purgeable_resources, &batch);
553 if (status != STATUS_OK) 557 if (status != STATUS_OK)
554 return status; 558 return status;
555 559
556 // Currently resource sharing across versions and registrations is not 560 // Currently resource sharing across versions and registrations is not
557 // supported, so resource ids should not be overlapped between 561 // supported, so resource ids should not be overlapped between
558 // |registration| and |old_registration|. 562 // |registration| and |old_registration|.
559 std::set<int64> deleted_resources(newly_purgeable_resources->begin(), 563 std::set<int64> deleted_resources(newly_purgeable_resources->begin(),
560 newly_purgeable_resources->end()); 564 newly_purgeable_resources->end());
561 DCHECK(base::STLSetIntersection<std::set<int64> >( 565 DCHECK(base::STLSetIntersection<std::set<int64> >(
562 pushed_resources, deleted_resources).empty()); 566 pushed_resources, deleted_resources).empty());
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 1149
1146 void ServiceWorkerDatabase::HandleWriteResult( 1150 void ServiceWorkerDatabase::HandleWriteResult(
1147 const tracked_objects::Location& from_here, 1151 const tracked_objects::Location& from_here,
1148 Status status) { 1152 Status status) {
1149 if (status != STATUS_OK) 1153 if (status != STATUS_OK)
1150 Disable(from_here, status); 1154 Disable(from_here, status);
1151 ServiceWorkerMetrics::CountWriteDatabaseResult(status); 1155 ServiceWorkerMetrics::CountWriteDatabaseResult(status);
1152 } 1156 }
1153 1157
1154 } // namespace content 1158 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698