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(GlobalUsageCallback callback); |
42 void GetHostUsage(const std::string& host, HostUsageCallback* callback); | 41 void GetHostUsage(const std::string& host, 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 GetCachedOrigins(std::set<GURL>* origins) const; | 45 void GetCachedOrigins(std::set<GURL>* origins) const; |
47 bool IsWorking() const { | 46 bool IsWorking() const { |
48 return global_usage_callbacks_.HasCallbacks() || | 47 return global_usage_callbacks_.HasCallbacks() || |
49 host_usage_callbacks_.HasAnyCallbacks(); | 48 host_usage_callbacks_.HasAnyCallbacks(); |
50 } | 49 } |
51 | 50 |
52 private: | 51 private: |
(...skipping 14 matching lines...) Expand all Loading... |
67 int64 usage); | 66 int64 usage); |
68 | 67 |
69 const StorageType type_; | 68 const StorageType type_; |
70 ClientTrackerMap client_tracker_map_; | 69 ClientTrackerMap client_tracker_map_; |
71 TrackingInfo global_usage_; | 70 TrackingInfo global_usage_; |
72 std::map<std::string, TrackingInfo> outstanding_host_usage_; | 71 std::map<std::string, TrackingInfo> outstanding_host_usage_; |
73 | 72 |
74 GlobalUsageCallbackQueue global_usage_callbacks_; | 73 GlobalUsageCallbackQueue global_usage_callbacks_; |
75 HostUsageCallbackMap host_usage_callbacks_; | 74 HostUsageCallbackMap host_usage_callbacks_; |
76 | 75 |
77 base::ScopedCallbackFactory<UsageTracker> callback_factory_; | 76 base::WeakPtrFactory<UsageTracker> weak_factory_; |
78 DISALLOW_COPY_AND_ASSIGN(UsageTracker); | 77 DISALLOW_COPY_AND_ASSIGN(UsageTracker); |
79 }; | 78 }; |
80 | 79 |
81 // This class holds per-client usage tracking information and caches per-host | 80 // This class holds per-client usage tracking information and caches per-host |
82 // usage data. An instance of this class is created per client. | 81 // usage data. An instance of this class is created per client. |
83 class ClientUsageTracker : public SpecialStoragePolicy::Observer, | 82 class ClientUsageTracker : public SpecialStoragePolicy::Observer, |
84 public base::NonThreadSafe { | 83 public base::NonThreadSafe { |
85 public: | 84 public: |
86 ClientUsageTracker(UsageTracker* tracker, | 85 ClientUsageTracker(UsageTracker* tracker, |
87 QuotaClient* client, | 86 QuotaClient* client, |
88 StorageType type, | 87 StorageType type, |
89 SpecialStoragePolicy* special_storage_policy); | 88 SpecialStoragePolicy* special_storage_policy); |
90 virtual ~ClientUsageTracker(); | 89 virtual ~ClientUsageTracker(); |
91 | 90 |
92 void GetGlobalUsage(GlobalUsageCallback* callback); | 91 void GetGlobalUsage(GlobalUsageCallback callback); |
93 void GetHostUsage(const std::string& host, HostUsageCallback* callback); | 92 void GetHostUsage(const std::string& host, HostUsageCallback callback); |
94 void UpdateUsageCache(const GURL& origin, int64 delta); | 93 void UpdateUsageCache(const GURL& origin, int64 delta); |
95 void GetCachedOrigins(std::set<GURL>* origins) const; | 94 void GetCachedOrigins(std::set<GURL>* origins) const; |
96 | 95 |
97 private: | 96 private: |
98 typedef std::set<std::string> HostSet; | 97 typedef std::set<std::string> HostSet; |
99 typedef std::map<GURL, int64> UsageMap; | 98 typedef std::map<GURL, int64> UsageMap; |
100 typedef std::map<std::string, UsageMap> HostUsageMap; | 99 typedef std::map<std::string, UsageMap> HostUsageMap; |
101 | 100 |
102 class GatherUsageTaskBase; | 101 class GatherUsageTaskBase; |
103 class GatherGlobalUsageTask; | 102 class GatherGlobalUsageTask; |
(...skipping 30 matching lines...) Expand all Loading... |
134 HostUsageCallbackMap host_usage_callbacks_; | 133 HostUsageCallbackMap host_usage_callbacks_; |
135 | 134 |
136 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 135 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
137 | 136 |
138 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); | 137 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); |
139 }; | 138 }; |
140 | 139 |
141 } // namespace quota | 140 } // namespace quota |
142 | 141 |
143 #endif // WEBKIT_QUOTA_USAGE_TRACKER_H_ | 142 #endif // WEBKIT_QUOTA_USAGE_TRACKER_H_ |
OLD | NEW |