| 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> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 struct AccumulateInfo { | 58 struct AccumulateInfo { |
| 59 AccumulateInfo() : pending_clients(0), usage(0), unlimited_usage(0) {} | 59 AccumulateInfo() : pending_clients(0), usage(0), unlimited_usage(0) {} |
| 60 int pending_clients; | 60 int pending_clients; |
| 61 int64 usage; | 61 int64 usage; |
| 62 int64 unlimited_usage; | 62 int64 unlimited_usage; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 typedef std::map<QuotaClient::ID, ClientUsageTracker*> ClientTrackerMap; | 65 typedef std::map<QuotaClient::ID, ClientUsageTracker*> ClientTrackerMap; |
| 66 | 66 |
| 67 friend class ClientUsageTracker; | 67 friend class ClientUsageTracker; |
| 68 void AccumulateClientGlobalLimitedUsage(AccumulateInfo* info, |
| 69 int64 limited_usage); |
| 68 void AccumulateClientGlobalUsage(AccumulateInfo* info, | 70 void AccumulateClientGlobalUsage(AccumulateInfo* info, |
| 69 int64 usage, | 71 int64 usage, |
| 70 int64 unlimited_usage); | 72 int64 unlimited_usage); |
| 71 void AccumulateClientHostUsage(AccumulateInfo* info, | 73 void AccumulateClientHostUsage(AccumulateInfo* info, |
| 72 const std::string& host, | 74 const std::string& host, |
| 73 int64 usage); | 75 int64 usage); |
| 74 | 76 |
| 75 const StorageType type_; | 77 const StorageType type_; |
| 76 ClientTrackerMap client_tracker_map_; | 78 ClientTrackerMap client_tracker_map_; |
| 77 | 79 |
| 80 UsageCallbackQueue global_limited_usage_callbacks_; |
| 78 GlobalUsageCallbackQueue global_usage_callbacks_; | 81 GlobalUsageCallbackQueue global_usage_callbacks_; |
| 79 HostUsageCallbackMap host_usage_callbacks_; | 82 HostUsageCallbackMap host_usage_callbacks_; |
| 80 | 83 |
| 81 base::WeakPtrFactory<UsageTracker> weak_factory_; | 84 base::WeakPtrFactory<UsageTracker> weak_factory_; |
| 82 DISALLOW_COPY_AND_ASSIGN(UsageTracker); | 85 DISALLOW_COPY_AND_ASSIGN(UsageTracker); |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 // This class holds per-client usage tracking information and caches per-host | 88 // This class holds per-client usage tracking information and caches per-host |
| 86 // usage data. An instance of this class is created per client. | 89 // usage data. An instance of this class is created per client. |
| 87 class ClientUsageTracker : public SpecialStoragePolicy::Observer, | 90 class ClientUsageTracker : public SpecialStoragePolicy::Observer, |
| 88 public base::NonThreadSafe, | 91 public base::NonThreadSafe, |
| 89 public base::SupportsWeakPtr<ClientUsageTracker> { | 92 public base::SupportsWeakPtr<ClientUsageTracker> { |
| 90 public: | 93 public: |
| 91 typedef base::Callback<void(int64 cached_usage, | 94 typedef base::Callback<void(int64 limited_usage, |
| 92 int64 non_cached_usage)> HostUsageAccumulator; | 95 int64 unlimited_usage)> HostUsageAccumulator; |
| 93 typedef base::Callback<void(const GURL& origin, | 96 typedef base::Callback<void(const GURL& origin, |
| 94 int64 usage)> OriginUsageAccumulator; | 97 int64 usage)> OriginUsageAccumulator; |
| 95 typedef std::map<std::string, std::set<GURL> > OriginSetByHost; | 98 typedef std::map<std::string, std::set<GURL> > OriginSetByHost; |
| 96 | 99 |
| 97 ClientUsageTracker(UsageTracker* tracker, | 100 ClientUsageTracker(UsageTracker* tracker, |
| 98 QuotaClient* client, | 101 QuotaClient* client, |
| 99 StorageType type, | 102 StorageType type, |
| 100 SpecialStoragePolicy* special_storage_policy); | 103 SpecialStoragePolicy* special_storage_policy); |
| 101 virtual ~ClientUsageTracker(); | 104 virtual ~ClientUsageTracker(); |
| 102 | 105 |
| 106 void GetGlobalLimitedUsage(const UsageCallback& callback); |
| 103 void GetGlobalUsage(const GlobalUsageCallback& callback); | 107 void GetGlobalUsage(const GlobalUsageCallback& callback); |
| 104 void GetHostUsage(const std::string& host, const UsageCallback& callback); | 108 void GetHostUsage(const std::string& host, const UsageCallback& callback); |
| 105 void UpdateUsageCache(const GURL& origin, int64 delta); | 109 void UpdateUsageCache(const GURL& origin, int64 delta); |
| 106 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; | 110 void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; |
| 107 void GetCachedOrigins(std::set<GURL>* origins) const; | 111 void GetCachedOrigins(std::set<GURL>* origins) const; |
| 108 int64 GetCachedOriginsUsage(const std::set<GURL>& origins, | 112 int64 GetCachedOriginsUsage(const std::set<GURL>& origins, |
| 109 std::vector<GURL>* origins_not_in_cache); | 113 std::vector<GURL>* origins_not_in_cache); |
| 110 bool IsUsageCacheEnabledForOrigin(const GURL& origin) const; | 114 bool IsUsageCacheEnabledForOrigin(const GURL& origin) const; |
| 111 void SetUsageCacheEnabled(const GURL& origin, bool enabled); | 115 void SetUsageCacheEnabled(const GURL& origin, bool enabled); |
| 112 | 116 |
| 113 private: | 117 private: |
| 114 typedef CallbackQueueMap<HostUsageAccumulator, std::string, | 118 typedef CallbackQueueMap<HostUsageAccumulator, std::string, |
| 115 Tuple2<int64, int64> > HostUsageAccumulatorMap; | 119 Tuple2<int64, int64> > HostUsageAccumulatorMap; |
| 116 | 120 |
| 117 typedef std::set<std::string> HostSet; | 121 typedef std::set<std::string> HostSet; |
| 118 typedef std::map<GURL, int64> UsageMap; | 122 typedef std::map<GURL, int64> UsageMap; |
| 119 typedef std::map<std::string, UsageMap> HostUsageMap; | 123 typedef std::map<std::string, UsageMap> HostUsageMap; |
| 120 | 124 |
| 121 struct AccumulateInfo { | 125 struct AccumulateInfo { |
| 122 int pending_jobs; | 126 int pending_jobs; |
| 123 int64 cached_usage; | 127 int64 limited_usage; |
| 124 int64 non_cached_usage; | 128 int64 unlimited_usage; |
| 125 | 129 |
| 126 AccumulateInfo() : pending_jobs(0), cached_usage(0), non_cached_usage(0) {} | 130 AccumulateInfo() |
| 131 : pending_jobs(0), limited_usage(0), unlimited_usage(0) {} |
| 127 }; | 132 }; |
| 128 | 133 |
| 134 void AccumulateLimitedOriginUsage(AccumulateInfo* info, |
| 135 const UsageCallback& callback, |
| 136 int64 usage); |
| 129 void DidGetOriginsForGlobalUsage(const GlobalUsageCallback& callback, | 137 void DidGetOriginsForGlobalUsage(const GlobalUsageCallback& callback, |
| 130 const std::set<GURL>& origins); | 138 const std::set<GURL>& origins); |
| 131 void AccumulateHostUsage(AccumulateInfo* info, | 139 void AccumulateHostUsage(AccumulateInfo* info, |
| 132 const GlobalUsageCallback& callback, | 140 const GlobalUsageCallback& callback, |
| 133 int64 cached_usage, | 141 int64 limited_usage, |
| 134 int64 non_cached_usage); | 142 int64 unlimited_usage); |
| 135 | 143 |
| 136 void DidGetOriginsForHostUsage(const std::string& host, | 144 void DidGetOriginsForHostUsage(const std::string& host, |
| 137 const std::set<GURL>& origins); | 145 const std::set<GURL>& origins); |
| 138 | 146 |
| 139 void GetUsageForOrigins(const std::string& host, | 147 void GetUsageForOrigins(const std::string& host, |
| 140 const std::set<GURL>& origins); | 148 const std::set<GURL>& origins); |
| 141 void AccumulateOriginUsage(AccumulateInfo* info, | 149 void AccumulateOriginUsage(AccumulateInfo* info, |
| 142 const std::string& host, | 150 const std::string& host, |
| 143 const GURL& origin, | 151 const GURL& origin, |
| 144 int64 usage); | 152 int64 usage); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 HostUsageAccumulatorMap host_usage_accumulators_; | 184 HostUsageAccumulatorMap host_usage_accumulators_; |
| 177 | 185 |
| 178 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 186 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
| 179 | 187 |
| 180 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); | 188 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); |
| 181 }; | 189 }; |
| 182 | 190 |
| 183 } // namespace quota | 191 } // namespace quota |
| 184 | 192 |
| 185 #endif // WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ | 193 #endif // WEBKIT_BROWSER_QUOTA_USAGE_TRACKER_H_ |
| OLD | NEW |