| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 void UsageTracker::UpdateUsageCache(QuotaClient::ID client_id, | 131 void UsageTracker::UpdateUsageCache(QuotaClient::ID client_id, |
| 132 const GURL& origin, | 132 const GURL& origin, |
| 133 int64_t delta) { | 133 int64_t delta) { |
| 134 ClientUsageTracker* client_tracker = GetClientTracker(client_id); | 134 ClientUsageTracker* client_tracker = GetClientTracker(client_id); |
| 135 DCHECK(client_tracker); | 135 DCHECK(client_tracker); |
| 136 client_tracker->UpdateUsageCache(origin, delta); | 136 client_tracker->UpdateUsageCache(origin, delta); |
| 137 } | 137 } |
| 138 | 138 |
| 139 int64_t UsageTracker::GetCachedUsage() const { |
| 140 int64_t usage = 0; |
| 141 for (const auto& client_id_and_tracker : client_tracker_map_) |
| 142 usage += client_id_and_tracker.second->GetCachedUsage(); |
| 143 return usage; |
| 144 } |
| 145 |
| 139 void UsageTracker::GetCachedHostsUsage( | 146 void UsageTracker::GetCachedHostsUsage( |
| 140 std::map<std::string, int64_t>* host_usage) const { | 147 std::map<std::string, int64_t>* host_usage) const { |
| 141 DCHECK(host_usage); | 148 DCHECK(host_usage); |
| 142 host_usage->clear(); | 149 host_usage->clear(); |
| 143 for (const auto& client_id_and_tracker : client_tracker_map_) | 150 for (const auto& client_id_and_tracker : client_tracker_map_) |
| 144 client_id_and_tracker.second->GetCachedHostsUsage(host_usage); | 151 client_id_and_tracker.second->GetCachedHostsUsage(host_usage); |
| 145 } | 152 } |
| 146 | 153 |
| 147 void UsageTracker::GetCachedOriginsUsage( | 154 void UsageTracker::GetCachedOriginsUsage( |
| 148 std::map<GURL, int64_t>* origin_usage) const { | 155 std::map<GURL, int64_t>* origin_usage) const { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // Defend against confusing inputs from clients. | 220 // Defend against confusing inputs from clients. |
| 214 if (info->usage < 0) | 221 if (info->usage < 0) |
| 215 info->usage = 0; | 222 info->usage = 0; |
| 216 | 223 |
| 217 // All the clients have returned their usage data. Dispatch the | 224 // All the clients have returned their usage data. Dispatch the |
| 218 // pending callbacks. | 225 // pending callbacks. |
| 219 host_usage_callbacks_.Run(host, info->usage); | 226 host_usage_callbacks_.Run(host, info->usage); |
| 220 } | 227 } |
| 221 | 228 |
| 222 } // namespace storage | 229 } // namespace storage |
| OLD | NEW |