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

Unified Diff: content/browser/service_worker/service_worker_context_core.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: Logic to Core 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_core.cc
diff --git a/content/browser/service_worker/service_worker_context_core.cc b/content/browser/service_worker/service_worker_context_core.cc
index a5abf968b70cd1ccec54445659d6c09802916e8c..2dbe9bbb6be2a777d91134ee91a3b7169ed2306d 100644
--- a/content/browser/service_worker/service_worker_context_core.cc
+++ b/content/browser/service_worker/service_worker_context_core.cc
@@ -4,6 +4,9 @@
#include "content/browser/service_worker/service_worker_context_core.h"
+#include "base/barrier_closure.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/files/file_path.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
@@ -211,6 +214,76 @@ void ServiceWorkerContextCore::UnregisterServiceWorker(
callback));
}
+void ServiceWorkerContextCore::UnregisterServiceWorkers(
+ const GURL& origin,
+ const UnregistrationCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (storage()->IsDisabled()) {
+ callback.Run(SERVICE_WORKER_ERROR_ABORT);
jsbell 2014/10/13 20:54:25 Should this be posted instead of running synchrono
dmurph 2014/10/14 00:16:31 Not changing to match implementations above, as di
+ return;
+ }
+
+ storage()->GetAllRegistrations(base::Bind(
+ &ServiceWorkerContextCore::DidGetAllRegistrationsForUnregisterForOrigin,
+ AsWeakPtr(),
+ callback,
+ origin));
+}
+
+namespace {
michaeln 2014/10/14 00:50:31 please put the anon namespace helpers up at the to
dmurph 2014/10/14 21:04:50 Done.
+void SuccessCollectorCallback(const base::Closure& done_closure,
+ bool* overall_success,
+ ServiceWorkerStatusCode status) {
+ if (status != ServiceWorkerStatusCode::SERVICE_WORKER_OK) {
+ *overall_success = false;
+ }
+ done_closure.Run();
+}
+
+void SuccessReportingCallback(
+ const bool* success,
+ const ServiceWorkerContextCore::UnregistrationCallback& callback) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
michaeln 2014/10/14 00:50:31 You should be able to DCHECK_CURRENTLY_ON(IO) righ
dmurph 2014/10/14 21:04:50 It's a bug then. This callback is called from the
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&SuccessReportingCallback, success, callback));
+ return;
+ }
+
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ bool result = *success;
+ callback.Run(result ? ServiceWorkerStatusCode::SERVICE_WORKER_OK
+ : ServiceWorkerStatusCode::SERVICE_WORKER_ERROR_FAILED);
+}
+} // namespace
+
+void ServiceWorkerContextCore::DidGetAllRegistrationsForUnregisterForOrigin(
+ const UnregistrationCallback& result,
+ const GURL& origin,
+ const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
+ std::set<GURL> scopes;
+ for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it =
jsbell 2014/10/13 20:54:25 This looks like a great place to use range-based f
dmurph 2014/10/14 00:16:31 Done.
+ registrations.begin();
+ it != registrations.end();
+ ++it) {
+ const ServiceWorkerRegistrationInfo& registration_info = *it;
+ if (origin == registration_info.pattern.GetOrigin()) {
+ scopes.insert(registration_info.pattern);
+ }
+ }
+ bool* overall_success = new bool(true);
+ base::Closure barrier = base::BarrierClosure(
+ scopes.size(),
+ base::Bind(
+ &SuccessReportingCallback, base::Owned(overall_success), result));
+
+ for (const GURL& scope : scopes) {
+ job_coordinator_->Unregister(
michaeln 2014/10/14 00:50:31 The core::unreg() method does some work upon compl
dmurph 2014/10/14 21:04:50 Done.
+ scope, base::Bind(&SuccessCollectorCallback, barrier, overall_success));
+ }
+}
+
void ServiceWorkerContextCore::UpdateServiceWorker(
ServiceWorkerRegistration* registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

Powered by Google App Engine
This is Rietveld 408576698