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

Unified Diff: content/browser/service_worker/service_worker_quota_client.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_quota_client.cc
diff --git a/content/browser/service_worker/service_worker_quota_client.cc b/content/browser/service_worker/service_worker_quota_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2ea5ba091f314f9cd2f77da65c82f83806dcfd3
--- /dev/null
+++ b/content/browser/service_worker/service_worker_quota_client.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
jsbell 2014/10/13 20:54:25 Per http://www.chromium.org/developers/coding-styl
dmurph 2014/10/14 00:16:31 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include "content/browser/service_worker/service_worker_quota_client.h"
+
+#include "base/bind.h"
+#include "content/browser/service_worker/service_worker_context_wrapper.h"
+#include "content/public/browser/browser_thread.h"
+
+using storage::QuotaClient;
+
+namespace content {
+namespace {
+void ReportOrigins(const QuotaClient::GetOriginsCallback& callback,
+ bool restrict_on_host,
+ const std::string host,
+ const std::vector<ServiceWorkerUsageInfo>& usage_info) {
+ std::set<GURL> origins;
+ for (const ServiceWorkerUsageInfo& info : usage_info) {
+ if (restrict_on_host && info.origin.host() != host) {
+ continue;
+ }
+ origins.insert(info.origin);
+ }
+ callback.Run(origins);
+}
+
+void ReportToQuotaStatus(const QuotaClient::DeletionCallback& callback,
+ bool status) {
+ callback.Run(status ? storage::QuotaStatusCode::kQuotaStatusOk
+ : storage::QuotaStatusCode::kQuotaStatusUnknown);
+}
+} // namespace
+
+ServiceWorkerQuotaClient::ServiceWorkerQuotaClient(
+ ServiceWorkerContextWrapper* context)
+ : context_(context) {
+}
+
+ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() {
+}
+
+QuotaClient::ID ServiceWorkerQuotaClient::id() const {
+ return QuotaClient::kServiceWorker;
+}
+
+void ServiceWorkerQuotaClient::OnQuotaManagerDestroyed() {
+ delete this;
+}
+
+void ServiceWorkerQuotaClient::GetOriginUsage(
+ const GURL& origin,
+ storage::StorageType type,
+ const GetUsageCallback& callback) {
+ // TODO(dmurph): Add usage fetching when information is available.
+ callback.Run(0);
+}
+
+void ServiceWorkerQuotaClient::GetOriginsForType(
+ storage::StorageType type,
+ const GetOriginsCallback& callback) {
+ if (type != storage::StorageType::kStorageTypeTemporary) {
+ callback.Run(std::set<GURL>());
+ return;
+ }
+ context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, ""));
+}
+
+void ServiceWorkerQuotaClient::GetOriginsForHost(
+ storage::StorageType type,
+ const std::string& host,
+ const GetOriginsCallback& callback) {
+ if (type != storage::StorageType::kStorageTypeTemporary) {
+ callback.Run(std::set<GURL>());
+ return;
+ }
+ context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, true, host));
+}
+
+void ServiceWorkerQuotaClient::DeleteOriginData(
+ const GURL& origin,
+ storage::StorageType type,
+ const DeletionCallback& callback) {
+ if (type != storage::StorageType::kStorageTypeTemporary) {
+ callback.Run(storage::QuotaStatusCode::kQuotaStatusOk);
+ return;
+ }
+ context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback));
+}
+
+bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const {
+ return type == storage::StorageType::kStorageTypeTemporary;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698