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..2eaf82bb571bac8f3b0330e63b7cbd0c9f42230f |
--- /dev/null |
+++ b/content/browser/service_worker/service_worker_quota_client.cc |
@@ -0,0 +1,101 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// 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 || |
+ !context_->IsAlive()) { |
michaeln
2014/10/20 20:08:22
Wdyt about putting this test into wrapper class di
dmurph
2014/10/20 21:34:18
I'm good with that.
|
+ 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 || |
+ !context_->IsAlive()) { |
+ 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; |
+ } |
+ if (!context_->IsAlive()) { |
+ callback.Run(storage::QuotaStatusCode::kQuotaStatusUnknown); |
+ return; |
+ } |
+ context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); |
+} |
+ |
+bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { |
+ return type == storage::StorageType::kStorageTypeTemporary; |
+} |
+ |
+} // namespace content |