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

Unified Diff: content/browser/service_worker/service_worker_storage.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: addressed last comment 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_storage.cc
diff --git a/content/browser/service_worker/service_worker_storage.cc b/content/browser/service_worker/service_worker_storage.cc
index b0cfe30899555d00f5ab85e8ded16a9d3d163346..e2d9441d2541ef36221ff09c5c4ff67531a6896f 100644
--- a/content/browser/service_worker/service_worker_storage.cc
+++ b/content/browser/service_worker/service_worker_storage.cc
@@ -470,6 +470,8 @@ void ServiceWorkerStorage::StoreRegistration(
resources_total_size_bytes += resource.size_bytes;
}
data.resources_total_size_bytes = resources_total_size_bytes;
+ registration->set_resources_total_size_bytes(resources_total_size_bytes);
michaeln 2014/10/30 01:32:27 I think this should happen in DidStoreRegistration
dmurph 2014/10/30 22:06:16 Done.
+ version->set_resources_total_size_bytes(resources_total_size_bytes);
if (!has_checked_for_stale_resources_)
DeleteStaleResources();
@@ -479,22 +481,14 @@ void ServiceWorkerStorage::StoreRegistration(
base::Bind(&WriteRegistrationInDB,
database_.get(),
base::MessageLoopProxy::current(),
- data, resources,
+ data,
+ resources,
base::Bind(&ServiceWorkerStorage::DidStoreRegistration,
weak_factory_.GetWeakPtr(),
- callback)));
+ callback,
+ data)));
registration->set_is_deleted(false);
-
- // TODO(dmurph): Add correct byte delta.
- if (quota_manager_proxy_.get()) {
- // Can be nullptr in tests.
- quota_manager_proxy_->NotifyStorageModified(
- storage::QuotaClient::kServiceWorker,
- registration->pattern().GetOrigin(),
- storage::StorageType::kStorageTypeTemporary,
- 0);
- }
}
void ServiceWorkerStorage::UpdateToActiveState(
@@ -978,8 +972,9 @@ void ServiceWorkerStorage::DidGetAllRegistrations(
void ServiceWorkerStorage::DidStoreRegistration(
const StatusCallback& callback,
+ const ServiceWorkerDatabase::RegistrationData& new_version,
const GURL& origin,
- int64 deleted_version_id,
+ const ServiceWorkerDatabase::RegistrationData& deleted_version,
const std::vector<int64>& newly_purgeable_resources,
ServiceWorkerDatabase::Status status) {
if (status != ServiceWorkerDatabase::STATUS_OK) {
@@ -987,10 +982,19 @@ void ServiceWorkerStorage::DidStoreRegistration(
callback.Run(DatabaseStatusToStatusCode(status));
return;
}
+ if (quota_manager_proxy_.get()) {
+ // Can be nullptr in tests.
+ quota_manager_proxy_->NotifyStorageModified(
+ storage::QuotaClient::kServiceWorker,
+ origin,
+ storage::StorageType::kStorageTypeTemporary,
+ new_version.resources_total_size_bytes -
+ deleted_version.resources_total_size_bytes);
+ }
registered_origins_.insert(origin);
callback.Run(SERVICE_WORKER_OK);
- if (!context_ || !context_->GetLiveVersion(deleted_version_id))
+ if (!context_ || !context_->GetLiveVersion(deleted_version.version_id))
StartPurgingResources(newly_purgeable_resources);
}
@@ -1007,7 +1011,7 @@ void ServiceWorkerStorage::DidUpdateToActiveState(
void ServiceWorkerStorage::DidDeleteRegistration(
const DidDeleteRegistrationParams& params,
bool origin_is_deletable,
- int64 version_id,
+ const ServiceWorkerDatabase::RegistrationData& deleted_version,
const std::vector<int64>& newly_purgeable_resources,
ServiceWorkerDatabase::Status status) {
pending_deletions_.erase(params.registration_id);
@@ -1016,11 +1020,19 @@ void ServiceWorkerStorage::DidDeleteRegistration(
params.callback.Run(DatabaseStatusToStatusCode(status));
return;
}
+ if (quota_manager_proxy_.get()) {
+ // Can be nullptr in tests.
+ quota_manager_proxy_->NotifyStorageModified(
+ storage::QuotaClient::kServiceWorker,
+ params.origin,
+ storage::StorageType::kStorageTypeTemporary,
+ -deleted_version.resources_total_size_bytes);
+ }
if (origin_is_deletable)
registered_origins_.erase(params.origin);
params.callback.Run(SERVICE_WORKER_OK);
- if (!context_ || !context_->GetLiveVersion(version_id))
+ if (!context_ || !context_->GetLiveVersion(deleted_version.version_id))
StartPurgingResources(newly_purgeable_resources);
}
@@ -1035,6 +1047,7 @@ ServiceWorkerStorage::GetOrCreateRegistration(
registration = new ServiceWorkerRegistration(
data.scope, data.registration_id, context_);
+ registration->set_resources_total_size_bytes(data.resources_total_size_bytes);
registration->set_last_update_check(data.last_update_check);
if (pending_deletions_.find(data.registration_id) !=
pending_deletions_.end()) {
@@ -1294,17 +1307,16 @@ void ServiceWorkerStorage::DeleteRegistrationFromDB(
const DeleteRegistrationCallback& callback) {
DCHECK(database);
- int64 version_id = kInvalidServiceWorkerVersionId;
+ ServiceWorkerDatabase::RegistrationData deleted_version;
+ deleted_version.version_id = kInvalidServiceWorkerVersionId;
std::vector<int64> newly_purgeable_resources;
ServiceWorkerDatabase::Status status = database->DeleteRegistration(
- registration_id, origin, &version_id, &newly_purgeable_resources);
+ registration_id, origin, &deleted_version, &newly_purgeable_resources);
if (status != ServiceWorkerDatabase::STATUS_OK) {
- original_task_runner->PostTask(FROM_HERE,
- base::Bind(callback,
- false,
- kInvalidServiceWorkerVersionId,
- std::vector<int64>(),
- status));
+ original_task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(
+ callback, false, deleted_version, std::vector<int64>(), status));
return;
}
@@ -1313,20 +1325,20 @@ void ServiceWorkerStorage::DeleteRegistrationFromDB(
std::vector<ServiceWorkerDatabase::RegistrationData> registrations;
status = database->GetRegistrationsForOrigin(origin, &registrations);
if (status != ServiceWorkerDatabase::STATUS_OK) {
- original_task_runner->PostTask(FROM_HERE,
- base::Bind(callback,
- false,
- kInvalidServiceWorkerVersionId,
- std::vector<int64>(),
- status));
+ original_task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(
+ callback, false, deleted_version, std::vector<int64>(), status));
return;
}
bool deletable = registrations.empty();
- original_task_runner->PostTask(
- FROM_HERE,
- base::Bind(
- callback, deletable, version_id, newly_purgeable_resources, status));
+ original_task_runner->PostTask(FROM_HERE,
+ base::Bind(callback,
+ deletable,
+ deleted_version,
+ newly_purgeable_resources,
+ status));
}
void ServiceWorkerStorage::WriteRegistrationInDB(
@@ -1336,14 +1348,15 @@ void ServiceWorkerStorage::WriteRegistrationInDB(
const ResourceList& resources,
const WriteRegistrationCallback& callback) {
DCHECK(database);
- int64 deleted_version_id = kInvalidServiceWorkerVersionId;
+ ServiceWorkerDatabase::RegistrationData deleted_version;
+ deleted_version.registration_id = kInvalidServiceWorkerVersionId;
std::vector<int64> newly_purgeable_resources;
ServiceWorkerDatabase::Status status = database->WriteRegistration(
- data, resources, &deleted_version_id, &newly_purgeable_resources);
+ data, resources, &deleted_version, &newly_purgeable_resources);
original_task_runner->PostTask(FROM_HERE,
base::Bind(callback,
data.script.GetOrigin(),
- deleted_version_id,
+ deleted_version,
newly_purgeable_resources,
status));
}

Powered by Google App Engine
This is Rietveld 408576698