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..9af690a61d256698fcebc8413e651ab790abe0c6 |
--- /dev/null |
+++ b/content/browser/service_worker/service_worker_quota_client.cc |
@@ -0,0 +1,112 @@ |
+#include "content/browser/service_worker/service_worker_quota_client.h" |
jsbell
2014/10/08 19:26:41
Needs copyright header
dmurph
2014/10/11 00:02:26
Done.
|
+ |
+#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 { |
jsbell
2014/10/08 19:26:41
nit: blanks inside namespace {} (I think)
dmurph
2014/10/11 00:02:26
clang format left it alone
|
+namespace { |
+void ReportOrigins(const QuotaClient::GetOriginsCallback& callback, |
+ bool restrict_on_host, const std::string host, |
+ const std::vector<ServiceWorkerUsageInfo>& usage_info) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ std::set<GURL> origins; |
+ for (const ServiceWorkerUsageInfo& info : usage_info) { |
+ if (restrict_on_host && info.origin.host() != host) { |
jsbell
2014/10/08 19:26:41
nit: don't need braces here
dmurph
2014/10/11 00:02:26
I would like to keep them
|
+ continue; |
+ } |
+ origins.insert(info.origin); |
+ } |
+ callback.Run(origins); |
+} |
+ |
+void ReportUsage(const QuotaClient::GetUsageCallback& callback, |
+ const GURL& origin, |
+ const std::vector<ServiceWorkerUsageInfo>& usage_info) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ int serviceworkers = 0; |
+ DLOG(ERROR) << "Getting origin " << origin.spec(); |
michaeln
2014/10/08 23:09:15
This and other in here aren't really error logging
dmurph
2014/10/11 00:02:26
Done.
|
+ for (const ServiceWorkerUsageInfo& info : usage_info) { |
+ DLOG(ERROR) << "Considering origin " << info.origin.spec(); |
+ if (info.origin == origin) { |
jsbell
2014/10/08 19:26:41
nit: don't need braces here
dmurph
2014/10/11 00:02:26
I would like to keep
|
+ serviceworkers++; |
+ } |
+ } |
+ // FIXME: Expose real usage numbers; |
jsbell
2014/10/08 19:26:41
Chromium style is: TODO(dmurph): ...
Can you docu
dmurph
2014/10/11 00:02:26
Done.
|
+ callback.Run(serviceworkers); |
michaeln
2014/10/08 23:09:15
Be careful with reporting bogus values to the quot
dmurph
2014/10/11 00:02:26
Cool, I changed this to always report 0, so having
|
+} |
+ |
+void ReportToQuotaStatus(const QuotaClient::DeletionCallback& callback, |
+ bool status) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ 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) { |
+ DLOG(ERROR) << "Usage called for type " << type << " and origin " << origin; |
+ if (type != storage::StorageType::kStorageTypePersistent) { |
jsbell
2014/10/08 19:26:41
My bad: should be kStorageTypeTemporary (here and
dmurph
2014/10/11 00:02:26
Done.
|
+ callback.Run(0); |
+ return; |
+ } |
+ context_->GetAllOriginsInfo(base::Bind(&ReportUsage, callback, origin)); |
michaeln
2014/10/08 23:09:15
Might be nice to have a more focused getter for a
dmurph
2014/10/11 00:02:26
Isn't that what this does?
|
+} |
+ |
+void ServiceWorkerQuotaClient::GetOriginsForType( |
+ storage::StorageType type, const GetOriginsCallback& callback) { |
+ DLOG(ERROR) << "origins for type called with storage type " << type; |
+ if (type != storage::StorageType::kStorageTypePersistent) { |
+ 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) { |
+ DLOG(ERROR) << "Origins for host " << type << " and host " << host; |
+ if (type != storage::StorageType::kStorageTypePersistent) { |
+ 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) { |
+ DLOG(ERROR) << "!!! Delete called for type " << type << " and origin " |
+ << origin; |
+ if (type != storage::StorageType::kStorageTypePersistent) { |
+ callback.Run(storage::QuotaStatusCode::kQuotaStatusOk); |
+ return; |
+ } |
+ context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); |
+} |
+ |
+bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { |
+ return type == storage::StorageType::kStorageTypePersistent; |
+} |
+ |
+ |
jsbell
2014/10/08 19:26:41
nit: remove extra blank line
dmurph
2014/10/11 00:02:26
Done.
|
+} // namespace content |