Index: content/browser/service_worker/service_worker_database.cc |
diff --git a/content/browser/service_worker/service_worker_database.cc b/content/browser/service_worker/service_worker_database.cc |
index 856e30e8558d74fdd58495d4a04cbb69be20e490..fa355f48cd636e0f717e5cb2a8e1acfa7477c899 100644 |
--- a/content/browser/service_worker/service_worker_database.cc |
+++ b/content/browser/service_worker/service_worker_database.cc |
@@ -134,6 +134,7 @@ void PutRegistrationDataToBatch( |
data.set_is_active(input.is_active); |
data.set_has_fetch_handler(input.has_fetch_handler); |
data.set_last_update_check_time(input.last_update_check.ToInternalValue()); |
+ data.set_resources_total_size_bytes(input.resources_total_size_bytes); |
std::string value; |
bool success = data.SerializeToString(&value); |
@@ -147,11 +148,13 @@ void PutResourceRecordToBatch( |
int64 version_id, |
leveldb::WriteBatch* batch) { |
DCHECK(batch); |
+ DCHECK_GE(input.size_bytes, 0); |
// Convert ResourceRecord to ServiceWorkerResourceRecord. |
ServiceWorkerResourceRecord record; |
record.set_resource_id(input.resource_id); |
record.set_url(input.url.spec()); |
+ record.set_size_bytes(input.size_bytes); |
std::string value; |
bool success = record.SerializeToString(&value); |
@@ -227,6 +230,8 @@ ServiceWorkerDatabase::Status ParseRegistrationData( |
out->has_fetch_handler = data.has_fetch_handler(); |
out->last_update_check = |
base::Time::FromInternalValue(data.last_update_check_time()); |
+ out->resources_total_size_bytes = data.resources_total_size_bytes(); |
+ |
return ServiceWorkerDatabase::STATUS_OK; |
} |
@@ -245,6 +250,7 @@ ServiceWorkerDatabase::Status ParseResourceRecord( |
// Convert ServiceWorkerResourceRecord to ResourceRecord. |
out->resource_id = record.resource_id(); |
out->url = url; |
+ out->size_bytes = record.size_bytes(); |
return ServiceWorkerDatabase::STATUS_OK; |
} |
@@ -289,7 +295,8 @@ ServiceWorkerDatabase::RegistrationData::RegistrationData() |
: registration_id(kInvalidServiceWorkerRegistrationId), |
version_id(kInvalidServiceWorkerVersionId), |
is_active(false), |
- has_fetch_handler(false) { |
+ has_fetch_handler(false), |
+ resources_total_size_bytes(0) { |
} |
ServiceWorkerDatabase::RegistrationData::~RegistrationData() { |
@@ -495,6 +502,15 @@ ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration( |
BumpNextVersionIdIfNeeded(registration.version_id, &batch); |
PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); |
+#if DCHECK_IS_ON |
+ uint64 total_size_bytes = 0; |
+ for (const auto& resource : resources) { |
+ total_size_bytes += resource.size_bytes; |
+ } |
+ DCHECK_EQ(total_size_bytes, registration.resources_total_size_bytes) |
+ << "The total size in the registration must match the cumulative " |
+ << "sizes of the resources."; |
+#endif |
PutRegistrationDataToBatch(registration, &batch); |
// Used for avoiding multiple writes for the same resource id or url. |