OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 return true; | 53 return true; |
54 } | 54 } |
55 | 55 |
56 bool OriginSetContainsOrigin(const OriginSetByHost& origins, | 56 bool OriginSetContainsOrigin(const OriginSetByHost& origins, |
57 const std::string& host, | 57 const std::string& host, |
58 const GURL& origin) { | 58 const GURL& origin) { |
59 OriginSetByHost::const_iterator itr = origins.find(host); | 59 OriginSetByHost::const_iterator itr = origins.find(host); |
60 return itr != origins.end() && ContainsKey(itr->second, origin); | 60 return itr != origins.end() && ContainsKey(itr->second, origin); |
61 } | 61 } |
62 | 62 |
| 63 void DidGetGlobalUsageForLimitedGlobalUsage(const UsageCallback& callback, |
| 64 int64 total_global_usage, |
| 65 int64 global_unlimited_usage) { |
| 66 callback.Run(total_global_usage - global_unlimited_usage); |
| 67 } |
| 68 |
63 } // namespace | 69 } // namespace |
64 | 70 |
65 // UsageTracker ---------------------------------------------------------- | 71 // UsageTracker ---------------------------------------------------------- |
66 | 72 |
67 UsageTracker::UsageTracker(const QuotaClientList& clients, | 73 UsageTracker::UsageTracker(const QuotaClientList& clients, |
68 StorageType type, | 74 StorageType type, |
69 SpecialStoragePolicy* special_storage_policy) | 75 SpecialStoragePolicy* special_storage_policy) |
70 : type_(type), | 76 : type_(type), |
71 weak_factory_(this) { | 77 weak_factory_(this) { |
72 for (QuotaClientList::const_iterator iter = clients.begin(); | 78 for (QuotaClientList::const_iterator iter = clients.begin(); |
73 iter != clients.end(); | 79 iter != clients.end(); |
74 ++iter) { | 80 ++iter) { |
75 client_tracker_map_[(*iter)->id()] = | 81 client_tracker_map_[(*iter)->id()] = |
76 new ClientUsageTracker(this, *iter, type, special_storage_policy); | 82 new ClientUsageTracker(this, *iter, type, special_storage_policy); |
77 } | 83 } |
78 } | 84 } |
79 | 85 |
80 UsageTracker::~UsageTracker() { | 86 UsageTracker::~UsageTracker() { |
81 STLDeleteValues(&client_tracker_map_); | 87 STLDeleteValues(&client_tracker_map_); |
82 } | 88 } |
83 | 89 |
84 ClientUsageTracker* UsageTracker::GetClientTracker(QuotaClient::ID client_id) { | 90 ClientUsageTracker* UsageTracker::GetClientTracker(QuotaClient::ID client_id) { |
85 ClientTrackerMap::iterator found = client_tracker_map_.find(client_id); | 91 ClientTrackerMap::iterator found = client_tracker_map_.find(client_id); |
86 if (found != client_tracker_map_.end()) | 92 if (found != client_tracker_map_.end()) |
87 return found->second; | 93 return found->second; |
88 return NULL; | 94 return NULL; |
89 } | 95 } |
90 | 96 |
| 97 void UsageTracker::GetGlobalLimitedUsage(const UsageCallback& callback) { |
| 98 GetGlobalUsage(base::Bind(&DidGetGlobalUsageForLimitedGlobalUsage, callback)); |
| 99 } |
| 100 |
91 void UsageTracker::GetGlobalUsage(const GlobalUsageCallback& callback) { | 101 void UsageTracker::GetGlobalUsage(const GlobalUsageCallback& callback) { |
92 if (!global_usage_callbacks_.Add(callback)) | 102 if (!global_usage_callbacks_.Add(callback)) |
93 return; | 103 return; |
94 | 104 |
95 AccumulateInfo* info = new AccumulateInfo; | 105 AccumulateInfo* info = new AccumulateInfo; |
96 // Calling GetGlobalUsage(accumulator) may synchronously | 106 // Calling GetGlobalUsage(accumulator) may synchronously |
97 // return if the usage is cached, which may in turn dispatch | 107 // return if the usage is cached, which may in turn dispatch |
98 // the completion callback before we finish looping over | 108 // the completion callback before we finish looping over |
99 // all clients (because info->pending_clients may reach 0 | 109 // all clients (because info->pending_clients may reach 0 |
100 // during the loop). | 110 // during the loop). |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 } | 589 } |
580 | 590 |
581 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { | 591 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { |
582 if (type_ == kStorageTypeSyncable) | 592 if (type_ == kStorageTypeSyncable) |
583 return false; | 593 return false; |
584 return special_storage_policy_.get() && | 594 return special_storage_policy_.get() && |
585 special_storage_policy_->IsStorageUnlimited(origin); | 595 special_storage_policy_->IsStorageUnlimited(origin); |
586 } | 596 } |
587 | 597 |
588 } // namespace quota | 598 } // namespace quota |
OLD | NEW |