OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 5 |
| 6 #include "base/bind.h" |
| 7 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 |
| 10 using storage::QuotaClient; |
| 11 |
| 12 namespace content { |
| 13 namespace { |
| 14 void ReportOrigins(const QuotaClient::GetOriginsCallback& callback, |
| 15 bool restrict_on_host, |
| 16 const std::string host, |
| 17 const std::vector<ServiceWorkerUsageInfo>& usage_info) { |
| 18 std::set<GURL> origins; |
| 19 for (const ServiceWorkerUsageInfo& info : usage_info) { |
| 20 if (restrict_on_host && info.origin.host() != host) { |
| 21 continue; |
| 22 } |
| 23 origins.insert(info.origin); |
| 24 } |
| 25 callback.Run(origins); |
| 26 } |
| 27 |
| 28 void ReportToQuotaStatus(const QuotaClient::DeletionCallback& callback, |
| 29 bool status) { |
| 30 callback.Run(status ? storage::QuotaStatusCode::kQuotaStatusOk |
| 31 : storage::QuotaStatusCode::kQuotaStatusUnknown); |
| 32 } |
| 33 } // namespace |
| 34 |
| 35 ServiceWorkerQuotaClient::ServiceWorkerQuotaClient( |
| 36 ServiceWorkerContextWrapper* context) |
| 37 : context_(context) { |
| 38 } |
| 39 |
| 40 ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() { |
| 41 } |
| 42 |
| 43 QuotaClient::ID ServiceWorkerQuotaClient::id() const { |
| 44 return QuotaClient::kServiceWorker; |
| 45 } |
| 46 |
| 47 void ServiceWorkerQuotaClient::OnQuotaManagerDestroyed() { |
| 48 delete this; |
| 49 } |
| 50 |
| 51 void ServiceWorkerQuotaClient::GetOriginUsage( |
| 52 const GURL& origin, |
| 53 storage::StorageType type, |
| 54 const GetUsageCallback& callback) { |
| 55 // TODO(dmurph): Add usage fetching when information is available. |
| 56 callback.Run(0); |
| 57 } |
| 58 |
| 59 void ServiceWorkerQuotaClient::GetOriginsForType( |
| 60 storage::StorageType type, |
| 61 const GetOriginsCallback& callback) { |
| 62 if (type != storage::StorageType::kStorageTypeTemporary) { |
| 63 callback.Run(std::set<GURL>()); |
| 64 return; |
| 65 } |
| 66 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); |
| 67 } |
| 68 |
| 69 void ServiceWorkerQuotaClient::GetOriginsForHost( |
| 70 storage::StorageType type, |
| 71 const std::string& host, |
| 72 const GetOriginsCallback& callback) { |
| 73 if (type != storage::StorageType::kStorageTypeTemporary) { |
| 74 callback.Run(std::set<GURL>()); |
| 75 return; |
| 76 } |
| 77 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, true, host)); |
| 78 } |
| 79 |
| 80 void ServiceWorkerQuotaClient::DeleteOriginData( |
| 81 const GURL& origin, |
| 82 storage::StorageType type, |
| 83 const DeletionCallback& callback) { |
| 84 if (type != storage::StorageType::kStorageTypeTemporary) { |
| 85 callback.Run(storage::QuotaStatusCode::kQuotaStatusOk); |
| 86 return; |
| 87 } |
| 88 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); |
| 89 } |
| 90 |
| 91 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { |
| 92 return type == storage::StorageType::kStorageTypeTemporary; |
| 93 } |
| 94 |
| 95 } // namespace content |
OLD | NEW |