| 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" | 16 #include "base/memory/scoped_callback_factory.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/threading/non_thread_safe.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 #include "webkit/quota/quota_client.h" | 20 #include "webkit/quota/quota_client.h" |
| 20 #include "webkit/quota/quota_task.h" | 21 #include "webkit/quota/quota_task.h" |
| 21 #include "webkit/quota/quota_types.h" | 22 #include "webkit/quota/quota_types.h" |
| 23 #include "webkit/quota/special_storage_policy.h" |
| 22 | 24 |
| 23 namespace quota { | 25 namespace quota { |
| 24 | 26 |
| 25 class ClientUsageTracker; | 27 class ClientUsageTracker; |
| 26 class SpecialStoragePolicy; | |
| 27 | 28 |
| 28 // A helper class that gathers and tracks the amount of data stored in | 29 // A helper class that gathers and tracks the amount of data stored in |
| 29 // all quota clients. | 30 // all quota clients. |
| 30 // An instance of this class is created per storage type. | 31 // An instance of this class is created per storage type. |
| 31 class UsageTracker : public QuotaTaskObserver { | 32 class UsageTracker : public QuotaTaskObserver { |
| 32 public: | 33 public: |
| 33 UsageTracker(const QuotaClientList& clients, StorageType type, | 34 UsageTracker(const QuotaClientList& clients, StorageType type, |
| 34 SpecialStoragePolicy* special_storage_policy); | 35 SpecialStoragePolicy* special_storage_policy); |
| 35 virtual ~UsageTracker(); | 36 virtual ~UsageTracker(); |
| 36 | 37 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 73 |
| 73 GlobalUsageCallbackQueue global_usage_callbacks_; | 74 GlobalUsageCallbackQueue global_usage_callbacks_; |
| 74 HostUsageCallbackMap host_usage_callbacks_; | 75 HostUsageCallbackMap host_usage_callbacks_; |
| 75 | 76 |
| 76 base::ScopedCallbackFactory<UsageTracker> callback_factory_; | 77 base::ScopedCallbackFactory<UsageTracker> callback_factory_; |
| 77 DISALLOW_COPY_AND_ASSIGN(UsageTracker); | 78 DISALLOW_COPY_AND_ASSIGN(UsageTracker); |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 // 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 |
| 81 // usage data. An instance of this class is created per client. | 82 // usage data. An instance of this class is created per client. |
| 82 class ClientUsageTracker { | 83 class ClientUsageTracker : public SpecialStoragePolicy::Observer, |
| 84 public base::NonThreadSafe { |
| 83 public: | 85 public: |
| 84 ClientUsageTracker(UsageTracker* tracker, | 86 ClientUsageTracker(UsageTracker* tracker, |
| 85 QuotaClient* client, | 87 QuotaClient* client, |
| 86 StorageType type, | 88 StorageType type, |
| 87 SpecialStoragePolicy* special_storage_policy); | 89 SpecialStoragePolicy* special_storage_policy); |
| 88 ~ClientUsageTracker(); | 90 virtual ~ClientUsageTracker(); |
| 89 | 91 |
| 90 void GetGlobalUsage(GlobalUsageCallback* callback); | 92 void GetGlobalUsage(GlobalUsageCallback* callback); |
| 91 void GetHostUsage(const std::string& host, HostUsageCallback* callback); | 93 void GetHostUsage(const std::string& host, HostUsageCallback* callback); |
| 92 void UpdateUsageCache(const GURL& origin, int64 delta); | 94 void UpdateUsageCache(const GURL& origin, int64 delta); |
| 93 void GetCachedOrigins(std::set<GURL>* origins) const; | 95 void GetCachedOrigins(std::set<GURL>* origins) const; |
| 94 | 96 |
| 95 private: | 97 private: |
| 96 typedef std::set<std::string> HostSet; | 98 typedef std::set<std::string> HostSet; |
| 97 typedef std::map<GURL, int64> UsageMap; | 99 typedef std::map<GURL, int64> UsageMap; |
| 98 typedef std::map<std::string, UsageMap> HostUsageMap; | 100 typedef std::map<std::string, UsageMap> HostUsageMap; |
| 99 | 101 |
| 100 class GatherUsageTaskBase; | 102 class GatherUsageTaskBase; |
| 101 class GatherGlobalUsageTask; | 103 class GatherGlobalUsageTask; |
| 102 class GatherHostUsageTask; | 104 class GatherHostUsageTask; |
| 103 | 105 |
| 104 // Methods used by our GatherUsage tasks, as a task makes progress | 106 // Methods used by our GatherUsage tasks, as a task makes progress |
| 105 // origins and hosts are added incrementally to the cache. | 107 // origins and hosts are added incrementally to the cache. |
| 106 void AddCachedOrigin(const GURL& origin, int64 usage); | 108 void AddCachedOrigin(const GURL& origin, int64 usage); |
| 107 void AddCachedHost(const std::string& host); | 109 void AddCachedHost(const std::string& host); |
| 108 void GatherGlobalUsageComplete(); | 110 void GatherGlobalUsageComplete(); |
| 109 void GatherHostUsageComplete(const std::string& host); | 111 void GatherHostUsageComplete(const std::string& host); |
| 110 | 112 |
| 111 int64 GetCachedHostUsage(const std::string& host); | 113 int64 GetCachedHostUsage(const std::string& host); |
| 112 | 114 int64 GetCachedGlobalUnlimitedUsage(); |
| 115 virtual void OnSpecialStoragePolicyChanged() OVERRIDE; |
| 113 void NoopHostUsageCallback( | 116 void NoopHostUsageCallback( |
| 114 const std::string& host, StorageType type, int64 usage); | 117 const std::string& host, StorageType type, int64 usage); |
| 115 | |
| 116 bool IsStorageUnlimited(const GURL& origin) const; | 118 bool IsStorageUnlimited(const GURL& origin) const; |
| 117 | 119 |
| 118 UsageTracker* tracker_; | 120 UsageTracker* tracker_; |
| 119 QuotaClient* client_; | 121 QuotaClient* client_; |
| 120 const StorageType type_; | 122 const StorageType type_; |
| 121 | 123 |
| 122 int64 global_usage_; | 124 int64 global_usage_; |
| 123 int64 global_unlimited_usage_; | 125 int64 global_unlimited_usage_; |
| 124 bool global_usage_retrieved_; | 126 bool global_usage_retrieved_; |
| 127 bool global_unlimited_usage_is_valid_; |
| 125 HostSet cached_hosts_; | 128 HostSet cached_hosts_; |
| 126 HostUsageMap cached_usage_; | 129 HostUsageMap cached_usage_; |
| 127 | 130 |
| 128 GatherGlobalUsageTask* global_usage_task_; | 131 GatherGlobalUsageTask* global_usage_task_; |
| 129 GlobalUsageCallbackQueue global_usage_callback_; | 132 GlobalUsageCallbackQueue global_usage_callback_; |
| 130 std::map<std::string, GatherHostUsageTask*> host_usage_tasks_; | 133 std::map<std::string, GatherHostUsageTask*> host_usage_tasks_; |
| 131 HostUsageCallbackMap host_usage_callbacks_; | 134 HostUsageCallbackMap host_usage_callbacks_; |
| 132 | 135 |
| 133 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 136 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
| 134 | 137 |
| 135 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); | 138 DISALLOW_COPY_AND_ASSIGN(ClientUsageTracker); |
| 136 }; | 139 }; |
| 137 | 140 |
| 138 } // namespace quota | 141 } // namespace quota |
| 139 | 142 |
| 140 #endif // WEBKIT_QUOTA_USAGE_TRACKER_H_ | 143 #endif // WEBKIT_QUOTA_USAGE_TRACKER_H_ |
| OLD | NEW |