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

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: 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..f22a604e9ef918acc5716a595b85d50a17da208e 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.cc
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc
@@ -7,6 +7,7 @@
#include <map>
#include "base/barrier_closure.h"
+#include "base/callback_helpers.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -160,6 +161,22 @@ void ServiceWorkerContextWrapper::Terminate() {
process_manager_->Shutdown();
}
+void ServiceWorkerContextWrapper::CombineUsageInfo(
+ std::vector<ServiceWorkerUsageInfo>* usage_info,
+ std::map<GURL, int64>* usage_map,
+ const GetUsageInfoCallback& callback) {
+ DCHECK(usage_info);
+ DCHECK(usage_map);
+ for (auto& info : *usage_info) {
+ auto it = usage_map->find(info.origin);
+ info.total_size_bytes = it != usage_map->end() ? it->second : 0;
+ }
+ // We own usage_info, so as soon as we go out of scope it will be destroyed.
+ // Since we are explicitly calling Run here, we should be good, as the
+ // usage callback will be fully run before this callback is destroyed.
+ callback.Run(*usage_info);
+}
+
void ServiceWorkerContextWrapper::GetAllOriginsInfo(
const GetUsageInfoCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -171,16 +188,34 @@ void ServiceWorkerContextWrapper::GetAllOriginsInfo(
base::Bind(callback, std::vector<ServiceWorkerUsageInfo>()));
return;
}
+ auto* info_out = new std::vector<ServiceWorkerUsageInfo>();
+ auto* usage_map_out = new std::map<GURL, int64>();
michaeln 2014/10/24 23:15:47 It took me a while to understand the reason for th
dmurph 2014/10/27 21:37:06 I talked to Josh about this for a while, and we de
michaeln 2014/10/28 22:00:40 There don't seem to be many places where these are
+ base::Closure barrier = base::BarrierClosure(
+ 2,
+ base::Bind(&ServiceWorkerContextWrapper::CombineUsageInfo,
+ this,
+ base::Owned(info_out),
+ base::Owned(usage_map_out),
+ callback));
context()->storage()->GetAllRegistrations(base::Bind(
&ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins,
this,
- callback));
+ barrier,
+ base::Unretained(info_out)));
+ context()->storage()->GetAllUsageByOrigin(
+ base::Bind(&ServiceWorkerContextWrapper::DidGetUsageForAllOrigins,
+ this,
+ barrier,
+ base::Unretained(usage_map_out)));
}
void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins(
- const GetUsageInfoCallback& callback,
+ const base::Closure& closure,
+ std::vector<ServiceWorkerUsageInfo>* registrations_out,
const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(registrations_out);
+ base::ScopedClosureRunner closureRunner(closure);
std::vector<ServiceWorkerUsageInfo> usage_infos;
std::map<GURL, ServiceWorkerUsageInfo> origins;
@@ -203,8 +238,18 @@ void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins(
++it) {
usage_infos.push_back(it->second);
}
+ usage_infos.swap(*registrations_out);
+}
- callback.Run(usage_infos);
+void ServiceWorkerContextWrapper::DidGetUsageForAllOrigins(
+ const base::Closure& closure,
+ std::map<GURL, int64>* usage_out,
+ const std::map<GURL, int64>& usage_map) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(usage_out);
+ base::ScopedClosureRunner closureRunner(closure);
+ usage_out->clear();
+ usage_out->insert(usage_map.begin(), usage_map.end());
}
namespace {

Powered by Google App Engine
This is Rietveld 408576698