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 #ifndef WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ | 5 #ifndef WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ |
6 #define WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ | 6 #define WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 #include "webkit/browser/quota/quota_callbacks.h" | 18 #include "storage/browser/quota/quota_callbacks.h" |
19 #include "webkit/browser/quota/quota_client.h" | 19 #include "storage/browser/quota/quota_client.h" |
20 #include "webkit/browser/quota/quota_task.h" | 20 #include "storage/browser/quota/quota_task.h" |
21 #include "webkit/browser/quota/special_storage_policy.h" | 21 #include "storage/browser/quota/special_storage_policy.h" |
22 #include "webkit/browser/webkit_storage_browser_export.h" | 22 #include "storage/common/storage_export.h" |
23 #include "webkit/common/quota/quota_types.h" | 23 #include "storage/common/quota/quota_types.h" |
24 | 24 |
25 namespace quota { | 25 namespace quota { |
26 | 26 |
27 class ClientUsageTracker; | 27 class ClientUsageTracker; |
28 class StorageMonitor; | 28 class StorageMonitor; |
29 | 29 |
30 // A helper class that gathers and tracks the amount of data stored in | 30 // A helper class that gathers and tracks the amount of data stored in |
31 // all quota clients. | 31 // all quota clients. |
32 // An instance of this class is created per storage type. | 32 // An instance of this class is created per storage type. |
33 class WEBKIT_STORAGE_BROWSER_EXPORT UsageTracker : public QuotaTaskObserver { | 33 class STORAGE_EXPORT UsageTracker : public QuotaTaskObserver { |
34 public: | 34 public: |
35 UsageTracker(const QuotaClientList& clients, StorageType type, | 35 UsageTracker(const QuotaClientList& clients, |
| 36 StorageType type, |
36 SpecialStoragePolicy* special_storage_policy, | 37 SpecialStoragePolicy* special_storage_policy, |
37 StorageMonitor* storage_monitor); | 38 StorageMonitor* storage_monitor); |
38 virtual ~UsageTracker(); | 39 virtual ~UsageTracker(); |
39 | 40 |
40 StorageType type() const { return type_; } | 41 StorageType type() const { return type_; } |
41 ClientUsageTracker* GetClientTracker(QuotaClient::ID client_id); | 42 ClientUsageTracker* GetClientTracker(QuotaClient::ID client_id); |
42 | 43 |
43 void GetGlobalLimitedUsage(const UsageCallback& callback); | 44 void GetGlobalLimitedUsage(const UsageCallback& callback); |
44 void GetGlobalUsage(const GlobalUsageCallback& callback); | 45 void GetGlobalUsage(const GlobalUsageCallback& callback); |
45 void GetHostUsage(const std::string& host, const UsageCallback& callback); | 46 void GetHostUsage(const std::string& host, const UsageCallback& callback); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 base::WeakPtrFactory<UsageTracker> weak_factory_; | 90 base::WeakPtrFactory<UsageTracker> weak_factory_; |
90 DISALLOW_COPY_AND_ASSIGN(UsageTracker); | 91 DISALLOW_COPY_AND_ASSIGN(UsageTracker); |
91 }; | 92 }; |
92 | 93 |
93 // This class holds per-client usage tracking information and caches per-host | 94 // This class holds per-client usage tracking information and caches per-host |
94 // usage data. An instance of this class is created per client. | 95 // usage data. An instance of this class is created per client. |
95 class ClientUsageTracker : public SpecialStoragePolicy::Observer, | 96 class ClientUsageTracker : public SpecialStoragePolicy::Observer, |
96 public base::NonThreadSafe, | 97 public base::NonThreadSafe, |
97 public base::SupportsWeakPtr<ClientUsageTracker> { | 98 public base::SupportsWeakPtr<ClientUsageTracker> { |
98 public: | 99 public: |
99 typedef base::Callback<void(int64 limited_usage, | 100 typedef base::Callback<void(int64 limited_usage, int64 unlimited_usage)> |
100 int64 unlimited_usage)> HostUsageAccumulator; | 101 HostUsageAccumulator; |
101 typedef base::Callback<void(const GURL& origin, | 102 typedef base::Callback<void(const GURL& origin, int64 usage)> |
102 int64 usage)> OriginUsageAccumulator; | 103 OriginUsageAccumulator; |
103 typedef std::map<std::string, std::set<GURL> > OriginSetByHost; | 104 typedef std::map<std::string, std::set<GURL> > OriginSetByHost; |
104 | 105 |
105 ClientUsageTracker(UsageTracker* tracker, | 106 ClientUsageTracker(UsageTracker* tracker, |
106 QuotaClient* client, | 107 QuotaClient* client, |
107 StorageType type, | 108 StorageType type, |
108 SpecialStoragePolicy* special_storage_policy, | 109 SpecialStoragePolicy* special_storage_policy, |
109 StorageMonitor* storage_monitor); | 110 StorageMonitor* storage_monitor); |
110 virtual ~ClientUsageTracker(); | 111 virtual ~ClientUsageTracker(); |
111 | 112 |
112 void GetGlobalLimitedUsage(const UsageCallback& callback); | 113 void GetGlobalLimitedUsage(const UsageCallback& callback); |
113 void GetGlobalUsage(const GlobalUsageCallback& callback); | 114 void GetGlobalUsage(const GlobalUsageCallback& callback); |
114 void GetHostUsage(const std::string& host, const UsageCallback& callback); | 115 void GetHostUsage(const std::string& host, const UsageCallback& callback); |
115 void UpdateUsageCache(const GURL& origin, int64 delta); | 116 void UpdateUsageCache(const GURL& origin, int64 delta); |
116 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; | 117 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; |
117 void GetCachedOrigins(std::set<GURL>* origins) const; | 118 void GetCachedOrigins(std::set<GURL>* origins) const; |
118 int64 GetCachedOriginsUsage(const std::set<GURL>& origins, | 119 int64 GetCachedOriginsUsage(const std::set<GURL>& origins, |
119 std::vector<GURL>* origins_not_in_cache); | 120 std::vector<GURL>* origins_not_in_cache); |
120 bool IsUsageCacheEnabledForOrigin(const GURL& origin) const; | 121 bool IsUsageCacheEnabledForOrigin(const GURL& origin) const; |
121 void SetUsageCacheEnabled(const GURL& origin, bool enabled); | 122 void SetUsageCacheEnabled(const GURL& origin, bool enabled); |
122 | 123 |
123 private: | 124 private: |
124 typedef CallbackQueueMap<HostUsageAccumulator, std::string, | 125 typedef CallbackQueueMap<HostUsageAccumulator, |
| 126 std::string, |
125 Tuple2<int64, int64> > HostUsageAccumulatorMap; | 127 Tuple2<int64, int64> > HostUsageAccumulatorMap; |
126 | 128 |
127 typedef std::set<std::string> HostSet; | 129 typedef std::set<std::string> HostSet; |
128 typedef std::map<GURL, int64> UsageMap; | 130 typedef std::map<GURL, int64> UsageMap; |
129 typedef std::map<std::string, UsageMap> HostUsageMap; | 131 typedef std::map<std::string, UsageMap> HostUsageMap; |
130 | 132 |
131 struct AccumulateInfo { | 133 struct AccumulateInfo { |
132 int pending_jobs; | 134 int pending_jobs; |
133 int64 limited_usage; | 135 int64 limited_usage; |
134 int64 unlimited_usage; | 136 int64 unlimited_usage; |
135 | 137 |
136 AccumulateInfo() | 138 AccumulateInfo() : pending_jobs(0), limited_usage(0), unlimited_usage(0) {} |
137 : pending_jobs(0), limited_usage(0), unlimited_usage(0) {} | |
138 }; | 139 }; |
139 | 140 |
140 void AccumulateLimitedOriginUsage(AccumulateInfo* info, | 141 void AccumulateLimitedOriginUsage(AccumulateInfo* info, |
141 const UsageCallback& callback, | 142 const UsageCallback& callback, |
142 int64 usage); | 143 int64 usage); |
143 void DidGetOriginsForGlobalUsage(const GlobalUsageCallback& callback, | 144 void DidGetOriginsForGlobalUsage(const GlobalUsageCallback& callback, |
144 const std::set<GURL>& origins); | 145 const std::set<GURL>& origins); |
145 void AccumulateHostUsage(AccumulateInfo* info, | 146 void AccumulateHostUsage(AccumulateInfo* info, |
146 const GlobalUsageCallback& callback, | 147 const GlobalUsageCallback& callback, |
147 int64 limited_usage, | 148 int64 limited_usage, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 HostUsageAccumulatorMap host_usage_accumulators_; | 194 HostUsageAccumulatorMap host_usage_accumulators_; |
194 | 195 |
195 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 196 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
196 | 197 |
197 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); | 198 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); |
198 }; | 199 }; |
199 | 200 |
200 } // namespace quota | 201 } // namespace quota |
201 | 202 |
202 #endif // WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ | 203 #endif // WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ |
OLD | NEW |