OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 | 4 |
5 #include "storage/browser/quota/usage_tracker.h" | 5 #include "storage/browser/quota/usage_tracker.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 132 } |
133 | 133 |
134 void UsageTracker::UpdateUsageCache(QuotaClient::ID client_id, | 134 void UsageTracker::UpdateUsageCache(QuotaClient::ID client_id, |
135 const GURL& origin, | 135 const GURL& origin, |
136 int64_t delta) { | 136 int64_t delta) { |
137 ClientUsageTracker* client_tracker = GetClientTracker(client_id); | 137 ClientUsageTracker* client_tracker = GetClientTracker(client_id); |
138 DCHECK(client_tracker); | 138 DCHECK(client_tracker); |
139 client_tracker->UpdateUsageCache(origin, delta); | 139 client_tracker->UpdateUsageCache(origin, delta); |
140 } | 140 } |
141 | 141 |
| 142 int64_t UsageTracker::GetCachedUsage() const { |
| 143 int64_t usage = 0; |
| 144 for (const auto& client_id_and_tracker : client_tracker_map_) |
| 145 usage += client_id_and_tracker.second->GetCachedUsage(); |
| 146 return usage; |
| 147 } |
| 148 |
142 void UsageTracker::GetCachedHostsUsage( | 149 void UsageTracker::GetCachedHostsUsage( |
143 std::map<std::string, int64_t>* host_usage) const { | 150 std::map<std::string, int64_t>* host_usage) const { |
144 DCHECK(host_usage); | 151 DCHECK(host_usage); |
145 host_usage->clear(); | 152 host_usage->clear(); |
146 for (const auto& client_id_and_tracker : client_tracker_map_) | 153 for (const auto& client_id_and_tracker : client_tracker_map_) |
147 client_id_and_tracker.second->GetCachedHostsUsage(host_usage); | 154 client_id_and_tracker.second->GetCachedHostsUsage(host_usage); |
148 } | 155 } |
149 | 156 |
150 void UsageTracker::GetCachedOriginsUsage( | 157 void UsageTracker::GetCachedOriginsUsage( |
151 std::map<GURL, int64_t>* origin_usage) const { | 158 std::map<GURL, int64_t>* origin_usage) const { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // Defend against confusing inputs from clients. | 223 // Defend against confusing inputs from clients. |
217 if (info->usage < 0) | 224 if (info->usage < 0) |
218 info->usage = 0; | 225 info->usage = 0; |
219 | 226 |
220 // All the clients have returned their usage data. Dispatch the | 227 // All the clients have returned their usage data. Dispatch the |
221 // pending callbacks. | 228 // pending callbacks. |
222 host_usage_callbacks_.Run(host, info->usage); | 229 host_usage_callbacks_.Run(host, info->usage); |
223 } | 230 } |
224 | 231 |
225 } // namespace storage | 232 } // namespace storage |
OLD | NEW |