Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/quota/usage_tracker.h" | 5 #include "webkit/quota/usage_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 void UsageTracker::UpdateUsageCache( | 268 void UsageTracker::UpdateUsageCache( |
| 269 QuotaClient::ID client_id, const GURL& origin, int64 delta) { | 269 QuotaClient::ID client_id, const GURL& origin, int64 delta) { |
| 270 ClientUsageTracker* client_tracker = GetClientTracker(client_id); | 270 ClientUsageTracker* client_tracker = GetClientTracker(client_id); |
| 271 DCHECK(client_tracker); | 271 DCHECK(client_tracker); |
| 272 client_tracker->UpdateUsageCache(origin, delta); | 272 client_tracker->UpdateUsageCache(origin, delta); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void UsageTracker::GetCachedHostsUsage( | |
| 276 std::map<std::string, int64>* host_usage) const { | |
| 277 DCHECK(host_usage); | |
| 278 host_usage->clear(); | |
| 279 for (ClientTrackerMap::const_iterator iter = client_tracker_map_.begin(); | |
| 280 iter != client_tracker_map_.end(); ++iter) { | |
| 281 iter->second->GetCachedHostsUsage(host_usage); | |
| 282 } | |
| 283 } | |
| 284 | |
| 275 void UsageTracker::GetCachedOrigins(std::set<GURL>* origins) const { | 285 void UsageTracker::GetCachedOrigins(std::set<GURL>* origins) const { |
| 276 DCHECK(origins); | 286 DCHECK(origins); |
| 277 origins->clear(); | 287 origins->clear(); |
| 278 for (ClientTrackerMap::const_iterator iter = client_tracker_map_.begin(); | 288 for (ClientTrackerMap::const_iterator iter = client_tracker_map_.begin(); |
| 279 iter != client_tracker_map_.end(); ++iter) { | 289 iter != client_tracker_map_.end(); ++iter) { |
| 280 iter->second->GetCachedOrigins(origins); | 290 iter->second->GetCachedOrigins(origins); |
| 281 } | 291 } |
| 282 } | 292 } |
| 283 | 293 |
| 284 void UsageTracker::DidGetClientGlobalUsage(StorageType type, | 294 void UsageTracker::DidGetClientGlobalUsage(StorageType type, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 DCHECK_GE(cached_usage_[host][origin], 0); | 396 DCHECK_GE(cached_usage_[host][origin], 0); |
| 387 DCHECK_GE(global_usage_, 0); | 397 DCHECK_GE(global_usage_, 0); |
| 388 return; | 398 return; |
| 389 } | 399 } |
| 390 | 400 |
| 391 // We don't know about this host yet, so populate our cache for it. | 401 // We don't know about this host yet, so populate our cache for it. |
| 392 GetHostUsage(host, | 402 GetHostUsage(host, |
| 393 NewCallback(this, &ClientUsageTracker::NoopHostUsageCallback)); | 403 NewCallback(this, &ClientUsageTracker::NoopHostUsageCallback)); |
| 394 } | 404 } |
| 395 | 405 |
| 406 void ClientUsageTracker::GetCachedHostsUsage( | |
| 407 std::map<std::string, int64>* host_usage) const { | |
| 408 DCHECK(host_usage); | |
| 409 for (HostUsageMap::const_iterator host_iter = cached_usage_.begin(); | |
| 410 host_iter != cached_usage_.end(); host_iter++) { | |
| 411 host_usage->operator[](host_iter->first) += | |
| 412 GetCachedHostUsage(host_iter->first); | |
|
tzik
2013/05/24 12:03:29
I'm cleaning up around UsageTracker now.
Was there
mnaganov (inactive)
2013/05/24 12:06:58
I just didn't think about this possibility then. P
| |
| 413 } | |
| 414 } | |
| 415 | |
| 396 void ClientUsageTracker::GetCachedOrigins(std::set<GURL>* origins) const { | 416 void ClientUsageTracker::GetCachedOrigins(std::set<GURL>* origins) const { |
| 397 DCHECK(origins); | 417 DCHECK(origins); |
| 398 for (HostUsageMap::const_iterator host_iter = cached_usage_.begin(); | 418 for (HostUsageMap::const_iterator host_iter = cached_usage_.begin(); |
| 399 host_iter != cached_usage_.end(); host_iter++) { | 419 host_iter != cached_usage_.end(); host_iter++) { |
| 400 const UsageMap& origin_map = host_iter->second; | 420 const UsageMap& origin_map = host_iter->second; |
| 401 for (UsageMap::const_iterator origin_iter = origin_map.begin(); | 421 for (UsageMap::const_iterator origin_iter = origin_map.begin(); |
| 402 origin_iter != origin_map.end(); origin_iter++) { | 422 origin_iter != origin_map.end(); origin_iter++) { |
| 403 origins->insert(origin_iter->first); | 423 origins->insert(origin_iter->first); |
| 404 } | 424 } |
| 405 } | 425 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 } | 462 } |
| 443 host_usage_callbacks_.Clear(); | 463 host_usage_callbacks_.Clear(); |
| 444 } | 464 } |
| 445 | 465 |
| 446 void ClientUsageTracker::GatherHostUsageComplete(const std::string& host) { | 466 void ClientUsageTracker::GatherHostUsageComplete(const std::string& host) { |
| 447 DCHECK(host_usage_tasks_.find(host) != host_usage_tasks_.end()); | 467 DCHECK(host_usage_tasks_.find(host) != host_usage_tasks_.end()); |
| 448 host_usage_tasks_.erase(host); | 468 host_usage_tasks_.erase(host); |
| 449 host_usage_callbacks_.Run(host, host, type_, GetCachedHostUsage(host)); | 469 host_usage_callbacks_.Run(host, host, type_, GetCachedHostUsage(host)); |
| 450 } | 470 } |
| 451 | 471 |
| 452 int64 ClientUsageTracker::GetCachedHostUsage(const std::string& host) { | 472 int64 ClientUsageTracker::GetCachedHostUsage(const std::string& host) const { |
| 453 HostUsageMap::const_iterator found = cached_usage_.find(host); | 473 HostUsageMap::const_iterator found = cached_usage_.find(host); |
| 454 if (found == cached_usage_.end()) | 474 if (found == cached_usage_.end()) |
| 455 return 0; | 475 return 0; |
| 456 | 476 |
| 457 int64 usage = 0; | 477 int64 usage = 0; |
| 458 const UsageMap& map = found->second; | 478 const UsageMap& map = found->second; |
| 459 for (UsageMap::const_iterator iter = map.begin(); | 479 for (UsageMap::const_iterator iter = map.begin(); |
| 460 iter != map.end(); ++iter) { | 480 iter != map.end(); ++iter) { |
| 461 usage += iter->second; | 481 usage += iter->second; |
| 462 } | 482 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 488 void ClientUsageTracker::NoopHostUsageCallback( | 508 void ClientUsageTracker::NoopHostUsageCallback( |
| 489 const std::string& host, StorageType type, int64 usage) { | 509 const std::string& host, StorageType type, int64 usage) { |
| 490 } | 510 } |
| 491 | 511 |
| 492 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { | 512 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { |
| 493 return special_storage_policy_.get() && | 513 return special_storage_policy_.get() && |
| 494 special_storage_policy_->IsStorageUnlimited(origin); | 514 special_storage_policy_->IsStorageUnlimited(origin); |
| 495 } | 515 } |
| 496 | 516 |
| 497 } // namespace quota | 517 } // namespace quota |
| OLD | NEW |