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

Unified Diff: content/browser/service_worker/service_worker_database.cc

Issue 647953003: Service Worker script sizes in database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Fixed crash where writer_ was null Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
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.
« no previous file with comments | « content/browser/service_worker/service_worker_database.h ('k') | content/browser/service_worker/service_worker_database.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698