| 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 7822191dfe5e76ad4022a6be80cc2b5562646aba..c467a9108d7c55af36d576a8134d3312f101da89 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"
|
| @@ -23,6 +26,25 @@
|
| #include "url/gurl.h"
|
|
|
| namespace content {
|
| +namespace {
|
| +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) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + bool result = *success;
|
| + callback.Run(result ? ServiceWorkerStatusCode::SERVICE_WORKER_OK
|
| + : ServiceWorkerStatusCode::SERVICE_WORKER_ERROR_FAILED);
|
| +}
|
| +} // namespace
|
|
|
| const base::FilePath::CharType
|
| ServiceWorkerContextCore::kServiceWorkerDirectory[] =
|
| @@ -215,6 +237,45 @@ void ServiceWorkerContextCore::UnregisterServiceWorker(
|
| callback));
|
| }
|
|
|
| +void ServiceWorkerContextCore::UnregisterServiceWorkers(
|
| + const GURL& origin,
|
| + const UnregistrationCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + if (storage()->IsDisabled()) {
|
| + // Not posting as new task to match implementations above.
|
| + callback.Run(SERVICE_WORKER_ERROR_ABORT);
|
| + return;
|
| + }
|
| +
|
| + storage()->GetAllRegistrations(base::Bind(
|
| + &ServiceWorkerContextCore::DidGetAllRegistrationsForUnregisterForOrigin,
|
| + AsWeakPtr(),
|
| + callback,
|
| + origin));
|
| +}
|
| +
|
| +void ServiceWorkerContextCore::DidGetAllRegistrationsForUnregisterForOrigin(
|
| + const UnregistrationCallback& result,
|
| + const GURL& origin,
|
| + const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
|
| + std::set<GURL> scopes;
|
| + for (const auto& registration_info : registrations) {
|
| + 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) {
|
| + UnregisterServiceWorker(
|
| + scope, base::Bind(&SuccessCollectorCallback, barrier, overall_success));
|
| + }
|
| +}
|
| +
|
| void ServiceWorkerContextCore::UpdateServiceWorker(
|
| ServiceWorkerRegistration* registration) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|