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 #ifndef WEBKIT_QUOTA_USAGE_TRACKER_H_ | 5 #ifndef WEBKIT_QUOTA_USAGE_TRACKER_H_ |
6 #define WEBKIT_QUOTA_USAGE_TRACKER_H_ | 6 #define WEBKIT_QUOTA_USAGE_TRACKER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/memory/scoped_callback_factory.h" | |
17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
18 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
19 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
20 #include "webkit/quota/quota_client.h" | 19 #include "webkit/quota/quota_client.h" |
21 #include "webkit/quota/quota_task.h" | 20 #include "webkit/quota/quota_task.h" |
22 #include "webkit/quota/quota_types.h" | 21 #include "webkit/quota/quota_types.h" |
23 #include "webkit/quota/special_storage_policy.h" | 22 #include "webkit/quota/special_storage_policy.h" |
24 | 23 |
25 namespace quota { | 24 namespace quota { |
26 | 25 |
27 class ClientUsageTracker; | 26 class ClientUsageTracker; |
28 | 27 |
29 // A helper class that gathers and tracks the amount of data stored in | 28 // A helper class that gathers and tracks the amount of data stored in |
30 // all quota clients. | 29 // all quota clients. |
31 // An instance of this class is created per storage type. | 30 // An instance of this class is created per storage type. |
32 class UsageTracker : public QuotaTaskObserver { | 31 class UsageTracker : public QuotaTaskObserver { |
33 public: | 32 public: |
34 UsageTracker(const QuotaClientList& clients, StorageType type, | 33 UsageTracker(const QuotaClientList& clients, StorageType type, |
35 SpecialStoragePolicy* special_storage_policy); | 34 SpecialStoragePolicy* special_storage_policy); |
36 virtual ~UsageTracker(); | 35 virtual ~UsageTracker(); |
37 | 36 |
38 StorageType type() const { return type_; } | 37 StorageType type() const { return type_; } |
39 ClientUsageTracker* GetClientTracker(QuotaClient::ID client_id); | 38 ClientUsageTracker* GetClientTracker(QuotaClient::ID client_id); |
40 | 39 |
41 void GetGlobalUsage(GlobalUsageCallback* callback); | 40 void GetGlobalUsage(const GlobalUsageCallback& callback); |
42 void GetHostUsage(const std::string& host, HostUsageCallback* callback); | 41 void GetHostUsage(const std::string& host, const HostUsageCallback& callback); |
43 void UpdateUsageCache(QuotaClient::ID client_id, | 42 void UpdateUsageCache(QuotaClient::ID client_id, |
44 const GURL& origin, | 43 const GURL& origin, |
45 int64 delta); | 44 int64 delta); |
46 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; | 45 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; |
47 void GetCachedOrigins(std::set<GURL>* origins) const; | 46 void GetCachedOrigins(std::set<GURL>* origins) const; |
48 bool IsWorking() const { | 47 bool IsWorking() const { |
49 return global_usage_callbacks_.HasCallbacks() || | 48 return global_usage_callbacks_.HasCallbacks() || |
50 host_usage_callbacks_.HasAnyCallbacks(); | 49 host_usage_callbacks_.HasAnyCallbacks(); |
51 } | 50 } |
52 | 51 |
(...skipping 15 matching lines...) Expand all Loading... |
68 int64 usage); | 67 int64 usage); |
69 | 68 |
70 const StorageType type_; | 69 const StorageType type_; |
71 ClientTrackerMap client_tracker_map_; | 70 ClientTrackerMap client_tracker_map_; |
72 TrackingInfo global_usage_; | 71 TrackingInfo global_usage_; |
73 std::map<std::string, TrackingInfo> outstanding_host_usage_; | 72 std::map<std::string, TrackingInfo> outstanding_host_usage_; |
74 | 73 |
75 GlobalUsageCallbackQueue global_usage_callbacks_; | 74 GlobalUsageCallbackQueue global_usage_callbacks_; |
76 HostUsageCallbackMap host_usage_callbacks_; | 75 HostUsageCallbackMap host_usage_callbacks_; |
77 | 76 |
78 base::ScopedCallbackFactory<UsageTracker> callback_factory_; | 77 base::WeakPtrFactory<UsageTracker> weak_factory_; |
79 DISALLOW_COPY_AND_ASSIGN(UsageTracker); | 78 DISALLOW_COPY_AND_ASSIGN(UsageTracker); |
80 }; | 79 }; |
81 | 80 |
82 // This class holds per-client usage tracking information and caches per-host | 81 // This class holds per-client usage tracking information and caches per-host |
83 // usage data. An instance of this class is created per client. | 82 // usage data. An instance of this class is created per client. |
84 class ClientUsageTracker : public SpecialStoragePolicy::Observer, | 83 class ClientUsageTracker : public SpecialStoragePolicy::Observer, |
85 public base::NonThreadSafe { | 84 public base::NonThreadSafe { |
86 public: | 85 public: |
87 ClientUsageTracker(UsageTracker* tracker, | 86 ClientUsageTracker(UsageTracker* tracker, |
88 QuotaClient* client, | 87 QuotaClient* client, |
89 StorageType type, | 88 StorageType type, |
90 SpecialStoragePolicy* special_storage_policy); | 89 SpecialStoragePolicy* special_storage_policy); |
91 virtual ~ClientUsageTracker(); | 90 virtual ~ClientUsageTracker(); |
92 | 91 |
93 void GetGlobalUsage(GlobalUsageCallback* callback); | 92 void GetGlobalUsage(const GlobalUsageCallback& callback); |
94 void GetHostUsage(const std::string& host, HostUsageCallback* callback); | 93 void GetHostUsage(const std::string& host, const HostUsageCallback& callback); |
95 void UpdateUsageCache(const GURL& origin, int64 delta); | 94 void UpdateUsageCache(const GURL& origin, int64 delta); |
96 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; | 95 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; |
97 void GetCachedOrigins(std::set<GURL>* origins) const; | 96 void GetCachedOrigins(std::set<GURL>* origins) const; |
98 | 97 |
99 private: | 98 private: |
100 typedef std::set<std::string> HostSet; | 99 typedef std::set<std::string> HostSet; |
101 typedef std::map<GURL, int64> UsageMap; | 100 typedef std::map<GURL, int64> UsageMap; |
102 typedef std::map<std::string, UsageMap> HostUsageMap; | 101 typedef std::map<std::string, UsageMap> HostUsageMap; |
103 | 102 |
104 class GatherUsageTaskBase; | 103 class GatherUsageTaskBase; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 HostUsageCallbackMap host_usage_callbacks_; | 135 HostUsageCallbackMap host_usage_callbacks_; |
137 | 136 |
138 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 137 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
139 | 138 |
140 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); | 139 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); |
141 }; | 140 }; |
142 | 141 |
143 } // namespace quota | 142 } // namespace quota |
144 | 143 |
145 #endif // WEBKIT_QUOTA_USAGE_TRACKER_H_ | 144 #endif // WEBKIT_QUOTA_USAGE_TRACKER_H_ |
OLD | NEW |