Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: webkit/browser/quota/usage_tracker.h

Issue 218793002: Provide monitoring of usage for a storage type and origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failures Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webkit/browser/quota/storage_observer.cc ('k') | webkit/browser/quota/usage_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "webkit/browser/quota/quota_callbacks.h"
19 #include "webkit/browser/quota/quota_client.h" 19 #include "webkit/browser/quota/quota_client.h"
20 #include "webkit/browser/quota/quota_task.h" 20 #include "webkit/browser/quota/quota_task.h"
21 #include "webkit/browser/quota/special_storage_policy.h" 21 #include "webkit/browser/quota/special_storage_policy.h"
22 #include "webkit/browser/webkit_storage_browser_export.h" 22 #include "webkit/browser/webkit_storage_browser_export.h"
23 #include "webkit/common/quota/quota_types.h" 23 #include "webkit/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 29
29 // 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
30 // all quota clients. 31 // all quota clients.
31 // An instance of this class is created per storage type. 32 // An instance of this class is created per storage type.
32 class WEBKIT_STORAGE_BROWSER_EXPORT UsageTracker : public QuotaTaskObserver { 33 class WEBKIT_STORAGE_BROWSER_EXPORT UsageTracker : public QuotaTaskObserver {
33 public: 34 public:
34 UsageTracker(const QuotaClientList& clients, StorageType type, 35 UsageTracker(const QuotaClientList& clients, StorageType type,
35 SpecialStoragePolicy* special_storage_policy); 36 SpecialStoragePolicy* special_storage_policy,
37 StorageMonitor* storage_monitor);
36 virtual ~UsageTracker(); 38 virtual ~UsageTracker();
37 39
38 StorageType type() const { return type_; } 40 StorageType type() const { return type_; }
39 ClientUsageTracker* GetClientTracker(QuotaClient::ID client_id); 41 ClientUsageTracker* GetClientTracker(QuotaClient::ID client_id);
40 42
41 void GetGlobalLimitedUsage(const UsageCallback& callback); 43 void GetGlobalLimitedUsage(const UsageCallback& callback);
42 void GetGlobalUsage(const GlobalUsageCallback& callback); 44 void GetGlobalUsage(const GlobalUsageCallback& callback);
43 void GetHostUsage(const std::string& host, const UsageCallback& callback); 45 void GetHostUsage(const std::string& host, const UsageCallback& callback);
44 void UpdateUsageCache(QuotaClient::ID client_id, 46 void UpdateUsageCache(QuotaClient::ID client_id,
45 const GURL& origin, 47 const GURL& origin,
(...skipping 29 matching lines...) Expand all
75 const std::string& host, 77 const std::string& host,
76 int64 usage); 78 int64 usage);
77 79
78 const StorageType type_; 80 const StorageType type_;
79 ClientTrackerMap client_tracker_map_; 81 ClientTrackerMap client_tracker_map_;
80 82
81 UsageCallbackQueue global_limited_usage_callbacks_; 83 UsageCallbackQueue global_limited_usage_callbacks_;
82 GlobalUsageCallbackQueue global_usage_callbacks_; 84 GlobalUsageCallbackQueue global_usage_callbacks_;
83 HostUsageCallbackMap host_usage_callbacks_; 85 HostUsageCallbackMap host_usage_callbacks_;
84 86
87 StorageMonitor* storage_monitor_;
88
85 base::WeakPtrFactory<UsageTracker> weak_factory_; 89 base::WeakPtrFactory<UsageTracker> weak_factory_;
86 DISALLOW_COPY_AND_ASSIGN(UsageTracker); 90 DISALLOW_COPY_AND_ASSIGN(UsageTracker);
87 }; 91 };
88 92
89 // This class holds per-client usage tracking information and caches per-host 93 // This class holds per-client usage tracking information and caches per-host
90 // usage data. An instance of this class is created per client. 94 // usage data. An instance of this class is created per client.
91 class ClientUsageTracker : public SpecialStoragePolicy::Observer, 95 class ClientUsageTracker : public SpecialStoragePolicy::Observer,
92 public base::NonThreadSafe, 96 public base::NonThreadSafe,
93 public base::SupportsWeakPtr<ClientUsageTracker> { 97 public base::SupportsWeakPtr<ClientUsageTracker> {
94 public: 98 public:
95 typedef base::Callback<void(int64 limited_usage, 99 typedef base::Callback<void(int64 limited_usage,
96 int64 unlimited_usage)> HostUsageAccumulator; 100 int64 unlimited_usage)> HostUsageAccumulator;
97 typedef base::Callback<void(const GURL& origin, 101 typedef base::Callback<void(const GURL& origin,
98 int64 usage)> OriginUsageAccumulator; 102 int64 usage)> OriginUsageAccumulator;
99 typedef std::map<std::string, std::set<GURL> > OriginSetByHost; 103 typedef std::map<std::string, std::set<GURL> > OriginSetByHost;
100 104
101 ClientUsageTracker(UsageTracker* tracker, 105 ClientUsageTracker(UsageTracker* tracker,
102 QuotaClient* client, 106 QuotaClient* client,
103 StorageType type, 107 StorageType type,
104 SpecialStoragePolicy* special_storage_policy); 108 SpecialStoragePolicy* special_storage_policy,
109 StorageMonitor* storage_monitor);
105 virtual ~ClientUsageTracker(); 110 virtual ~ClientUsageTracker();
106 111
107 void GetGlobalLimitedUsage(const UsageCallback& callback); 112 void GetGlobalLimitedUsage(const UsageCallback& callback);
108 void GetGlobalUsage(const GlobalUsageCallback& callback); 113 void GetGlobalUsage(const GlobalUsageCallback& callback);
109 void GetHostUsage(const std::string& host, const UsageCallback& callback); 114 void GetHostUsage(const std::string& host, const UsageCallback& callback);
110 void UpdateUsageCache(const GURL& origin, int64 delta); 115 void UpdateUsageCache(const GURL& origin, int64 delta);
111 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; 116 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const;
112 void GetCachedOrigins(std::set<GURL>* origins) const; 117 void GetCachedOrigins(std::set<GURL>* origins) const;
113 int64 GetCachedOriginsUsage(const std::set<GURL>& origins, 118 int64 GetCachedOriginsUsage(const std::set<GURL>& origins,
114 std::vector<GURL>* origins_not_in_cache); 119 std::vector<GURL>* origins_not_in_cache);
(...skipping 30 matching lines...) Expand all
145 void DidGetOriginsForHostUsage(const std::string& host, 150 void DidGetOriginsForHostUsage(const std::string& host,
146 const std::set<GURL>& origins); 151 const std::set<GURL>& origins);
147 152
148 void GetUsageForOrigins(const std::string& host, 153 void GetUsageForOrigins(const std::string& host,
149 const std::set<GURL>& origins); 154 const std::set<GURL>& origins);
150 void AccumulateOriginUsage(AccumulateInfo* info, 155 void AccumulateOriginUsage(AccumulateInfo* info,
151 const std::string& host, 156 const std::string& host,
152 const GURL& origin, 157 const GURL& origin,
153 int64 usage); 158 int64 usage);
154 159
160 void DidGetHostUsageAfterUpdate(const GURL& origin, int64 usage);
161
155 // Methods used by our GatherUsage tasks, as a task makes progress 162 // Methods used by our GatherUsage tasks, as a task makes progress
156 // origins and hosts are added incrementally to the cache. 163 // origins and hosts are added incrementally to the cache.
157 void AddCachedOrigin(const GURL& origin, int64 usage); 164 void AddCachedOrigin(const GURL& origin, int64 usage);
158 void AddCachedHost(const std::string& host); 165 void AddCachedHost(const std::string& host);
159 166
160 int64 GetCachedHostUsage(const std::string& host) const; 167 int64 GetCachedHostUsage(const std::string& host) const;
161 int64 GetCachedGlobalUnlimitedUsage(); 168 int64 GetCachedGlobalUnlimitedUsage();
162 bool GetCachedOriginUsage(const GURL& origin, int64* usage) const; 169 bool GetCachedOriginUsage(const GURL& origin, int64* usage) const;
163 170
164 // SpecialStoragePolicy::Observer overrides 171 // SpecialStoragePolicy::Observer overrides
165 virtual void OnGranted(const GURL& origin, int change_flags) OVERRIDE; 172 virtual void OnGranted(const GURL& origin, int change_flags) OVERRIDE;
166 virtual void OnRevoked(const GURL& origin, int change_flags) OVERRIDE; 173 virtual void OnRevoked(const GURL& origin, int change_flags) OVERRIDE;
167 virtual void OnCleared() OVERRIDE; 174 virtual void OnCleared() OVERRIDE;
168 175
169 bool IsStorageUnlimited(const GURL& origin) const; 176 bool IsStorageUnlimited(const GURL& origin) const;
170 177
171 UsageTracker* tracker_; 178 UsageTracker* tracker_;
172 QuotaClient* client_; 179 QuotaClient* client_;
173 const StorageType type_; 180 const StorageType type_;
181 StorageMonitor* storage_monitor_;
174 182
175 int64 global_limited_usage_; 183 int64 global_limited_usage_;
176 int64 global_unlimited_usage_; 184 int64 global_unlimited_usage_;
177 bool global_usage_retrieved_; 185 bool global_usage_retrieved_;
178 HostSet cached_hosts_; 186 HostSet cached_hosts_;
179 HostUsageMap cached_usage_by_host_; 187 HostUsageMap cached_usage_by_host_;
180 188
181 OriginSetByHost non_cached_limited_origins_by_host_; 189 OriginSetByHost non_cached_limited_origins_by_host_;
182 OriginSetByHost non_cached_unlimited_origins_by_host_; 190 OriginSetByHost non_cached_unlimited_origins_by_host_;
183 191
184 GlobalUsageCallbackQueue global_usage_callback_; 192 GlobalUsageCallbackQueue global_usage_callback_;
185 HostUsageAccumulatorMap host_usage_accumulators_; 193 HostUsageAccumulatorMap host_usage_accumulators_;
186 194
187 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; 195 scoped_refptr<SpecialStoragePolicy> special_storage_policy_;
188 196
189 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); 197 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker);
190 }; 198 };
191 199
192 } // namespace quota 200 } // namespace quota
193 201
194 #endif // WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ 202 #endif // WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_
OLDNEW
« no previous file with comments | « webkit/browser/quota/storage_observer.cc ('k') | webkit/browser/quota/usage_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698