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

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

Issue 633273002: Added quota client for serviceworker. Enables 'clear past <time> data'. (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 5298a24f7a823fa3f444f8e0969e074d601158d5..c5aae6de5c58a9d950f6969c2cd72773cedc9f19 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.cc
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc
@@ -6,6 +6,7 @@
#include <map>
+#include "base/barrier_closure.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -13,6 +14,7 @@
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_observer.h"
#include "content/browser/service_worker/service_worker_process_manager.h"
+#include "content/browser/service_worker/service_worker_quota_client.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "net/url_request/url_request_context_getter.h"
@@ -53,6 +55,9 @@ void ServiceWorkerContextWrapper::Init(
database_task_runner,
disk_cache_thread,
quota_manager_proxy);
+ if (quota_manager_proxy) {
jsbell 2014/10/08 19:26:41 When is this NULL?
dmurph 2014/10/11 00:02:25 Other classes checked if the proxy was null, but i
+ quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this));
+ }
}
void ServiceWorkerContextWrapper::Shutdown() {
@@ -183,35 +188,71 @@ void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins(
}
namespace {
jsbell 2014/10/08 19:26:41 nit: I think we like having blank lines inside at
dmurph 2014/10/11 00:02:25 clang-format didn't change it
+void SuccessCollectorCallback(const base::Closure& done_closure,
+ bool* overall_success, bool success) {
+ if (!success) {
michaeln 2014/10/08 23:09:15 nit: {}'s not needed
dmurph 2014/10/11 00:02:25 I would like them
+ *overall_success = false;
+ }
+ done_closure.Run();
+}
+
+void SuccessReportingCallback(
+ const bool* success, const ServiceWorkerContext::ResultCallback& callback) {
jsbell 2014/10/08 19:26:40 nit: Per chromium style, put each arg on a separat
dmurph 2014/10/11 00:02:25 Done.
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
michaeln 2014/10/08 23:09:15 Do you ever expect this to be called on some other
dmurph 2014/10/11 00:02:25 Yes, this comes from the database runner, so I nee
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&SuccessReportingCallback, success, callback));
+ return;
+ }
-void EmptySuccessCallback(bool success) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ bool result = *success;
+ delete success;
michaeln 2014/10/08 23:09:15 I'm not sure it's safe to assume that the final ca
dmurph 2014/10/11 00:02:25 Done.
+ callback.Run(result);
}
+void EmptySuccessCallback(bool success) {}
jsbell 2014/10/08 19:26:41 nit: leave this with { } wrapped to minimize diff
dmurph 2014/10/11 00:02:25 Done.
} // namespace
-void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) {
+void ServiceWorkerContextWrapper::DeleteForOrigin(
+ const GURL& origin_url, const ResultCallback& done) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
context_core_->storage()->GetAllRegistrations(base::Bind(
&ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin,
this,
- origin_url));
+ origin_url,
+ done));
+}
+
+void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) {
+ DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback));
}
void ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin(
const GURL& origin,
+ const ResultCallback& done,
const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ std::set<GURL> applicable_patterns;
jsbell 2014/10/08 19:26:40 For brevity, how about just 'scopes' ? (We'll pro
dmurph 2014/10/11 00:02:25 Done.
for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it =
registrations.begin();
it != registrations.end();
++it) {
const ServiceWorkerRegistrationInfo& registration_info = *it;
if (origin == registration_info.pattern.GetOrigin()) {
jsbell 2014/10/08 19:26:41 nit: can drop the braces here
dmurph 2014/10/11 00:02:25 I would rather keep them :)
- UnregisterServiceWorker(registration_info.pattern,
- base::Bind(&EmptySuccessCallback));
+ applicable_patterns.insert(registration_info.pattern);
}
}
+ bool *success = new bool(true);
michaeln 2014/10/08 23:09:15 maybe call this overall_success for clarity throug
dmurph 2014/10/11 00:02:25 Done.
+ base::Closure barrier = base::BarrierClosure(
michaeln 2014/10/08 23:09:15 neat, hadn't seen barrier closure before
dmurph 2014/10/11 00:02:25 Acknowledged.
+ applicable_patterns.size(),
+ base::Bind(&SuccessReportingCallback, success, done));
michaeln 2014/10/08 23:09:15 base::Owned(overall_success) here or maybe base::P
dmurph 2014/10/11 00:02:25 Done.
+
+ for (const GURL& pattern : applicable_patterns) {
+ UnregisterServiceWorker(
+ pattern, base::Bind(&SuccessCollectorCallback, barrier, success));
michaeln 2014/10/08 23:09:15 base::Unretained(overall_success) here?
dmurph 2014/10/11 00:02:25 Unneeded. Only applicable to refcounted objects o
+ }
}
void ServiceWorkerContextWrapper::AddObserver(

Powered by Google App Engine
This is Rietveld 408576698