| 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 | 4 |
| 5 #include "storage/browser/quota/client_usage_tracker.h" | 5 #include "storage/browser/quota/client_usage_tracker.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 storage_monitor_->NotifyUsageChange(filter, delta); | 158 storage_monitor_->NotifyUsageChange(filter, delta); |
| 159 } | 159 } |
| 160 return; | 160 return; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // We don't know about this host yet, so populate our cache for it. | 163 // We don't know about this host yet, so populate our cache for it. |
| 164 GetHostUsage(host, base::Bind(&ClientUsageTracker::DidGetHostUsageAfterUpdate, | 164 GetHostUsage(host, base::Bind(&ClientUsageTracker::DidGetHostUsageAfterUpdate, |
| 165 AsWeakPtr(), origin)); | 165 AsWeakPtr(), origin)); |
| 166 } | 166 } |
| 167 | 167 |
| 168 int64_t ClientUsageTracker::GetCachedUsage() const { | |
| 169 int64_t usage = 0; | |
| 170 for (const auto& host_and_usage_map : cached_usage_by_host_) { | |
| 171 for (const auto& origin_and_usage : host_and_usage_map.second) | |
| 172 usage += origin_and_usage.second; | |
| 173 } | |
| 174 return usage; | |
| 175 } | |
| 176 | |
| 177 void ClientUsageTracker::GetCachedHostsUsage( | 168 void ClientUsageTracker::GetCachedHostsUsage( |
| 178 std::map<std::string, int64_t>* host_usage) const { | 169 std::map<std::string, int64_t>* host_usage) const { |
| 179 DCHECK(host_usage); | 170 DCHECK(host_usage); |
| 180 for (const auto& host_and_usage_map : cached_usage_by_host_) { | 171 for (const auto& host_and_usage_map : cached_usage_by_host_) { |
| 181 const std::string& host = host_and_usage_map.first; | 172 const std::string& host = host_and_usage_map.first; |
| 182 (*host_usage)[host] += GetCachedHostUsage(host); | 173 (*host_usage)[host] += GetCachedHostUsage(host); |
| 183 } | 174 } |
| 184 } | 175 } |
| 185 | 176 |
| 186 void ClientUsageTracker::GetCachedOriginsUsage( | 177 void ClientUsageTracker::GetCachedOriginsUsage( |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 460 } |
| 470 | 461 |
| 471 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { | 462 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { |
| 472 if (type_ == kStorageTypeSyncable) | 463 if (type_ == kStorageTypeSyncable) |
| 473 return false; | 464 return false; |
| 474 return special_storage_policy_.get() && | 465 return special_storage_policy_.get() && |
| 475 special_storage_policy_->IsStorageUnlimited(origin); | 466 special_storage_policy_->IsStorageUnlimited(origin); |
| 476 } | 467 } |
| 477 | 468 |
| 478 } // namespace storage | 469 } // namespace storage |
| OLD | NEW |