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 FindUsageForOrigin(const QuotaClient::GetUsageCallback& callback, |
| 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( |
| 72 base::Bind(&FindUsageForOrigin, callback, origin)); |
57 } | 73 } |
58 | 74 |
59 void ServiceWorkerQuotaClient::GetOriginsForType( | 75 void ServiceWorkerQuotaClient::GetOriginsForType( |
60 storage::StorageType type, | 76 storage::StorageType type, |
61 const GetOriginsCallback& callback) { | 77 const GetOriginsCallback& callback) { |
62 if (type != storage::StorageType::kStorageTypeTemporary) { | 78 if (type != storage::StorageType::kStorageTypeTemporary) { |
63 callback.Run(std::set<GURL>()); | 79 callback.Run(std::set<GURL>()); |
64 return; | 80 return; |
65 } | 81 } |
66 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); | 82 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); |
(...skipping 19 matching lines...) Expand all Loading... |
86 return; | 102 return; |
87 } | 103 } |
88 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); | 104 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); |
89 } | 105 } |
90 | 106 |
91 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { | 107 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { |
92 return type == storage::StorageType::kStorageTypeTemporary; | 108 return type == storage::StorageType::kStorageTypeTemporary; |
93 } | 109 } |
94 | 110 |
95 } // namespace content | 111 } // namespace content |
OLD | NEW |