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, | |
35 const std::vector<ServiceWorkerUsageInfo>& usage_info) { | |
36 int64 usage_total = 0; | |
37 for (const auto& info : usage_info) { | |
38 usage_total += info.total_size_bytes; | |
39 } | |
40 callback.Run(usage_total); | |
41 } | |
33 } // namespace | 42 } // namespace |
34 | 43 |
35 ServiceWorkerQuotaClient::ServiceWorkerQuotaClient( | 44 ServiceWorkerQuotaClient::ServiceWorkerQuotaClient( |
36 ServiceWorkerContextWrapper* context) | 45 ServiceWorkerContextWrapper* context) |
37 : context_(context) { | 46 : context_(context) { |
38 } | 47 } |
39 | 48 |
40 ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() { | 49 ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() { |
41 } | 50 } |
42 | 51 |
43 QuotaClient::ID ServiceWorkerQuotaClient::id() const { | 52 QuotaClient::ID ServiceWorkerQuotaClient::id() const { |
44 return QuotaClient::kServiceWorker; | 53 return QuotaClient::kServiceWorker; |
45 } | 54 } |
46 | 55 |
47 void ServiceWorkerQuotaClient::OnQuotaManagerDestroyed() { | 56 void ServiceWorkerQuotaClient::OnQuotaManagerDestroyed() { |
48 delete this; | 57 delete this; |
49 } | 58 } |
50 | 59 |
51 void ServiceWorkerQuotaClient::GetOriginUsage( | 60 void ServiceWorkerQuotaClient::GetOriginUsage( |
52 const GURL& origin, | 61 const GURL& origin, |
53 storage::StorageType type, | 62 storage::StorageType type, |
54 const GetUsageCallback& callback) { | 63 const GetUsageCallback& callback) { |
55 // TODO(dmurph): Add usage fetching when information is available. | 64 if (type != storage::StorageType::kStorageTypeTemporary) { |
56 callback.Run(0); | 65 callback.Run(0); |
66 return; | |
67 } | |
68 context_->GetAllOriginsInfo(base::Bind(&AccumulateUsage, callback)); | |
michaeln
2014/10/24 23:15:47
The method is supposed to return the amount of dat
dmurph
2014/10/27 21:37:06
Done.
| |
57 } | 69 } |
58 | 70 |
59 void ServiceWorkerQuotaClient::GetOriginsForType( | 71 void ServiceWorkerQuotaClient::GetOriginsForType( |
60 storage::StorageType type, | 72 storage::StorageType type, |
61 const GetOriginsCallback& callback) { | 73 const GetOriginsCallback& callback) { |
62 if (type != storage::StorageType::kStorageTypeTemporary) { | 74 if (type != storage::StorageType::kStorageTypeTemporary) { |
63 callback.Run(std::set<GURL>()); | 75 callback.Run(std::set<GURL>()); |
64 return; | 76 return; |
65 } | 77 } |
66 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); | 78 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); |
(...skipping 19 matching lines...) Expand all Loading... | |
86 return; | 98 return; |
87 } | 99 } |
88 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); | 100 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); |
89 } | 101 } |
90 | 102 |
91 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { | 103 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { |
92 return type == storage::StorageType::kStorageTypeTemporary; | 104 return type == storage::StorageType::kStorageTypeTemporary; |
93 } | 105 } |
94 | 106 |
95 } // namespace content | 107 } // namespace content |
OLD | NEW |