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

Unified Diff: content/browser/service_worker/service_worker_context_wrapper.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_context_wrapper.cc
diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc
index b135a85056b3bed00f969ae7059a047f2803fc7a..f1692359b97465bb3eab7c7312670835fe0e6775 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.cc
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc
@@ -23,6 +23,22 @@
#include "storage/browser/quota/special_storage_policy.h"
namespace content {
+namespace {
+
+size_t GetUsageIfValid(const ServiceWorkerVersionInfo& version_info) {
+ return version_info.version_id != kInvalidServiceWorkerVersionId
+ ? version_info.resources_total_size_bytes
+ : 0;
+}
+
+size_t GetTotalUsageForRegistrationInfo(
+ const ServiceWorkerRegistrationInfo& registration_info) {
+ return GetUsageIfValid(registration_info.active_version) +
+ GetUsageIfValid(registration_info.waiting_version) +
+ GetUsageIfValid(registration_info.installing_version);
michaeln 2014/10/30 01:32:27 Like we chatted about, going with a model where th
dmurph 2014/10/30 22:06:16 Done.
+}
+
+} // namespace
ServiceWorkerContextWrapper::ServiceWorkerContextWrapper(
BrowserContext* browser_context)
@@ -184,26 +200,20 @@ void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins(
std::vector<ServiceWorkerUsageInfo> usage_infos;
std::map<GURL, ServiceWorkerUsageInfo> origins;
- for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it =
- registrations.begin();
- it != registrations.end();
- ++it) {
- const ServiceWorkerRegistrationInfo& registration_info = *it;
+ for (const auto& registration_info : registrations) {
GURL origin = registration_info.pattern.GetOrigin();
ServiceWorkerUsageInfo& usage_info = origins[origin];
if (usage_info.origin.is_empty())
usage_info.origin = origin;
usage_info.scopes.push_back(registration_info.pattern);
+ usage_info.total_size_bytes +=
+ GetTotalUsageForRegistrationInfo(registration_info);
}
- for (std::map<GURL, ServiceWorkerUsageInfo>::const_iterator it =
- origins.begin();
- it != origins.end();
- ++it) {
- usage_infos.push_back(it->second);
+ for (const auto& origin_info_pair : origins) {
+ usage_infos.push_back(origin_info_pair.second);
}
-
callback.Run(usage_infos);
}

Powered by Google App Engine
This is Rietveld 408576698