Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include "content/browser/service_worker/service_worker_quota_client.h" | 4 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 5 | 5 |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 7 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 | 9 |
| 10 using storage::QuotaClient; | 10 using storage::QuotaClient; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 origins.insert(info.origin); | 23 origins.insert(info.origin); |
| 24 } | 24 } |
| 25 callback.Run(origins); | 25 callback.Run(origins); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void ReportToQuotaStatus(const QuotaClient::DeletionCallback& callback, | 28 void ReportToQuotaStatus(const QuotaClient::DeletionCallback& callback, |
| 29 bool status) { | 29 bool status) { |
| 30 callback.Run(status ? storage::QuotaStatusCode::kQuotaStatusOk | 30 callback.Run(status ? storage::QuotaStatusCode::kQuotaStatusOk |
| 31 : storage::QuotaStatusCode::kQuotaStatusUnknown); | 31 : storage::QuotaStatusCode::kQuotaStatusUnknown); |
| 32 } | 32 } |
| 33 | |
| 34 void AccumulateUsage(const QuotaClient::GetUsageCallback& callback, | |
|
michaeln
2014/10/30 23:32:24
oh, the name of this method doesn't fit since its
dmurph
2014/10/31 19:10:49
Done.
| |
| 35 const GURL& origin, | |
| 36 const std::vector<ServiceWorkerUsageInfo>& usage_info) { | |
| 37 for (const auto& info : usage_info) { | |
| 38 if (info.origin == origin) { | |
| 39 callback.Run(info.total_size_bytes); | |
| 40 return; | |
| 41 } | |
| 42 } | |
| 43 callback.Run(0); | |
| 44 } | |
| 33 } // namespace | 45 } // namespace |
| 34 | 46 |
| 35 ServiceWorkerQuotaClient::ServiceWorkerQuotaClient( | 47 ServiceWorkerQuotaClient::ServiceWorkerQuotaClient( |
| 36 ServiceWorkerContextWrapper* context) | 48 ServiceWorkerContextWrapper* context) |
| 37 : context_(context) { | 49 : context_(context) { |
| 38 } | 50 } |
| 39 | 51 |
| 40 ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() { | 52 ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() { |
| 41 } | 53 } |
| 42 | 54 |
| 43 QuotaClient::ID ServiceWorkerQuotaClient::id() const { | 55 QuotaClient::ID ServiceWorkerQuotaClient::id() const { |
| 44 return QuotaClient::kServiceWorker; | 56 return QuotaClient::kServiceWorker; |
| 45 } | 57 } |
| 46 | 58 |
| 47 void ServiceWorkerQuotaClient::OnQuotaManagerDestroyed() { | 59 void ServiceWorkerQuotaClient::OnQuotaManagerDestroyed() { |
| 48 delete this; | 60 delete this; |
| 49 } | 61 } |
| 50 | 62 |
| 51 void ServiceWorkerQuotaClient::GetOriginUsage( | 63 void ServiceWorkerQuotaClient::GetOriginUsage( |
| 52 const GURL& origin, | 64 const GURL& origin, |
| 53 storage::StorageType type, | 65 storage::StorageType type, |
| 54 const GetUsageCallback& callback) { | 66 const GetUsageCallback& callback) { |
| 55 // TODO(dmurph): Add usage fetching when information is available. | 67 if (type != storage::StorageType::kStorageTypeTemporary) { |
| 56 callback.Run(0); | 68 callback.Run(0); |
| 69 return; | |
| 70 } | |
| 71 context_->GetAllOriginsInfo(base::Bind(&AccumulateUsage, callback, origin)); | |
| 57 } | 72 } |
| 58 | 73 |
| 59 void ServiceWorkerQuotaClient::GetOriginsForType( | 74 void ServiceWorkerQuotaClient::GetOriginsForType( |
| 60 storage::StorageType type, | 75 storage::StorageType type, |
| 61 const GetOriginsCallback& callback) { | 76 const GetOriginsCallback& callback) { |
| 62 if (type != storage::StorageType::kStorageTypeTemporary) { | 77 if (type != storage::StorageType::kStorageTypeTemporary) { |
| 63 callback.Run(std::set<GURL>()); | 78 callback.Run(std::set<GURL>()); |
| 64 return; | 79 return; |
| 65 } | 80 } |
| 66 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); | 81 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 86 return; | 101 return; |
| 87 } | 102 } |
| 88 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); | 103 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); |
| 89 } | 104 } |
| 90 | 105 |
| 91 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { | 106 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { |
| 92 return type == storage::StorageType::kStorageTypeTemporary; | 107 return type == storage::StorageType::kStorageTypeTemporary; |
| 93 } | 108 } |
| 94 | 109 |
| 95 } // namespace content | 110 } // namespace content |
| OLD | NEW |