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

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: Rebase 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 ec33d565410d429dd706f4f7339a31dc7a81ef30..b135a85056b3bed00f969ae7059a047f2803fc7a 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"
@@ -101,7 +103,14 @@ void ServiceWorkerContextWrapper::RegisterServiceWorker(
continuation));
return;
}
-
+ if (!context_core_.get()) {
+ LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(continuation, false));
+ return;
+ }
context()->RegisterServiceWorker(
pattern,
script_url,
@@ -132,6 +141,14 @@ void ServiceWorkerContextWrapper::UnregisterServiceWorker(
continuation));
return;
}
+ if (!context_core_.get()) {
+ LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(continuation, false));
+ return;
+ }
context()->UnregisterServiceWorker(
pattern,
@@ -146,7 +163,15 @@ void ServiceWorkerContextWrapper::Terminate() {
void ServiceWorkerContextWrapper::GetAllOriginsInfo(
const GetUsageInfoCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- context_core_->storage()->GetAllRegistrations(base::Bind(
+ if (!context_core_.get()) {
+ LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(callback, std::vector<ServiceWorkerUsageInfo>()));
+ return;
+ }
+ context()->storage()->GetAllRegistrations(base::Bind(
&ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins,
this,
callback));
@@ -183,35 +208,34 @@ void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins(
}
namespace {
+void StatusCodeToBoolCallbackAdapter(
+ const ServiceWorkerContext::ResultCallback& callback,
+ ServiceWorkerStatusCode code) {
+ callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK);
+}
void EmptySuccessCallback(bool success) {
}
-
} // namespace
-void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) {
+void ServiceWorkerContextWrapper::DeleteForOrigin(
+ const GURL& origin_url,
+ const ResultCallback& result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- context_core_->storage()->GetAllRegistrations(base::Bind(
- &ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin,
- this,
- origin_url));
+ if (!context_core_.get()) {
+ LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(result, false));
+ return;
+ }
+ context()->UnregisterServiceWorkers(
+ origin_url, base::Bind(&StatusCodeToBoolCallbackAdapter, result));
}
-void ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin(
- const GURL& origin,
- const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it =
- registrations.begin();
- it != registrations.end();
- ++it) {
- const ServiceWorkerRegistrationInfo& registration_info = *it;
- if (origin == registration_info.pattern.GetOrigin()) {
- UnregisterServiceWorker(registration_info.pattern,
- base::Bind(&EmptySuccessCallback));
- }
- }
+void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) {
+ DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback));
}
void ServiceWorkerContextWrapper::AddObserver(
@@ -258,6 +282,9 @@ void ServiceWorkerContextWrapper::InitInternal(
return;
}
DCHECK(!context_core_);
+ if (quota_manager_proxy) {
+ quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this));
+ }
context_core_.reset(new ServiceWorkerContextCore(user_data_directory,
stores_task_runner,
database_task_manager.Pass(),

Powered by Google App Engine
This is Rietveld 408576698