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 STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 5 #ifndef STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
6 #define STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 6 #define STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
11 #include <list> | 11 #include <list> |
12 #include <map> | 12 #include <map> |
13 #include <memory> | 13 #include <memory> |
14 #include <set> | 14 #include <set> |
15 #include <string> | 15 #include <string> |
16 #include <utility> | 16 #include <utility> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "base/callback.h" | 19 #include "base/callback.h" |
20 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
21 #include "base/macros.h" | 21 #include "base/macros.h" |
22 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
23 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
24 #include "base/optional.h" | |
25 #include "base/sequenced_task_runner_helpers.h" | 24 #include "base/sequenced_task_runner_helpers.h" |
26 #include "storage/browser/quota/quota_callbacks.h" | 25 #include "storage/browser/quota/quota_callbacks.h" |
27 #include "storage/browser/quota/quota_client.h" | 26 #include "storage/browser/quota/quota_client.h" |
28 #include "storage/browser/quota/quota_database.h" | 27 #include "storage/browser/quota/quota_database.h" |
29 #include "storage/browser/quota/quota_settings.h" | |
30 #include "storage/browser/quota/quota_task.h" | 28 #include "storage/browser/quota/quota_task.h" |
31 #include "storage/browser/quota/special_storage_policy.h" | 29 #include "storage/browser/quota/special_storage_policy.h" |
32 #include "storage/browser/quota/storage_observer.h" | 30 #include "storage/browser/quota/storage_observer.h" |
33 #include "storage/browser/storage_browser_export.h" | 31 #include "storage/browser/storage_browser_export.h" |
34 | 32 |
| 33 class SiteEngagementEvictionPolicyWithQuotaManagerTest; |
| 34 |
35 namespace base { | 35 namespace base { |
36 class FilePath; | 36 class FilePath; |
37 class SequencedTaskRunner; | 37 class SequencedTaskRunner; |
38 class SingleThreadTaskRunner; | 38 class SingleThreadTaskRunner; |
39 } | 39 } |
40 | 40 |
41 namespace quota_internals { | 41 namespace quota_internals { |
42 class QuotaInternalsProxy; | 42 class QuotaInternalsProxy; |
43 } | 43 } |
44 | 44 |
45 namespace content { | 45 namespace content { |
46 class MockQuotaManager; | 46 class MockQuotaManager; |
47 class MockStorageClient; | 47 class MockStorageClient; |
48 class QuotaManagerTest; | 48 class QuotaManagerTest; |
49 class StorageMonitorTest; | 49 class StorageMonitorTest; |
50 | 50 |
51 } | 51 } |
52 | 52 |
53 namespace storage { | 53 namespace storage { |
54 | 54 |
55 class QuotaDatabase; | 55 class QuotaDatabase; |
56 class QuotaManagerProxy; | 56 class QuotaManagerProxy; |
57 class QuotaTemporaryStorageEvictor; | 57 class QuotaTemporaryStorageEvictor; |
58 class StorageMonitor; | 58 class StorageMonitor; |
59 class UsageTracker; | 59 class UsageTracker; |
60 | 60 |
61 struct QuotaManagerDeleter; | 61 struct QuotaManagerDeleter; |
62 | 62 |
| 63 struct STORAGE_EXPORT UsageAndQuota { |
| 64 int64_t usage; |
| 65 int64_t global_limited_usage; |
| 66 int64_t quota; |
| 67 int64_t available_disk_space; |
| 68 |
| 69 UsageAndQuota(); |
| 70 UsageAndQuota(int64_t usage, |
| 71 int64_t global_limited_usage, |
| 72 int64_t quota, |
| 73 int64_t available_disk_space); |
| 74 }; |
| 75 |
| 76 // TODO(calamity): Use this in the temporary storage eviction path. |
| 77 // An interface for deciding which origin's storage should be evicted when the |
| 78 // quota is exceeded. |
| 79 class STORAGE_EXPORT QuotaEvictionPolicy { |
| 80 public: |
| 81 virtual ~QuotaEvictionPolicy() {} |
| 82 |
| 83 // Returns the next origin to evict. It might return an empty GURL when there |
| 84 // are no evictable origins. |
| 85 virtual void GetEvictionOrigin( |
| 86 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, |
| 87 const std::set<GURL>& exceptions, |
| 88 const std::map<GURL, int64_t>& usage_map, |
| 89 int64_t global_quota, |
| 90 const GetOriginCallback& callback) = 0; |
| 91 }; |
| 92 |
63 // An interface called by QuotaTemporaryStorageEvictor. | 93 // An interface called by QuotaTemporaryStorageEvictor. |
64 class STORAGE_EXPORT QuotaEvictionHandler { | 94 class STORAGE_EXPORT QuotaEvictionHandler { |
65 public: | 95 public: |
66 using EvictionRoundInfoCallback = | 96 using EvictOriginDataCallback = StatusCallback; |
67 base::Callback<void(QuotaStatusCode status, | 97 using UsageAndQuotaCallback = base::Callback< |
68 const QuotaSettings& settings, | 98 void(QuotaStatusCode status, const UsageAndQuota& usage_and_quota)>; |
69 int64_t available_space, | 99 using VolumeInfoCallback = base::Callback< |
70 int64_t total_space, | 100 void(bool success, uint64_t available_space, uint64_t total_space)>; |
71 int64_t global_usage, | |
72 bool global_usage_is_complete)>; | |
73 | |
74 // Called at the beginning of an eviction round to gather the info about | |
75 // the current settings, capacity, and usage. | |
76 virtual void GetEvictionRoundInfo( | |
77 const EvictionRoundInfoCallback& callback) = 0; | |
78 | 101 |
79 // Returns next origin to evict. It might return an empty GURL when there are | 102 // Returns next origin to evict. It might return an empty GURL when there are |
80 // no evictable origins. | 103 // no evictable origins. |
81 virtual void GetEvictionOrigin(StorageType type, | 104 virtual void GetEvictionOrigin(StorageType type, |
82 const std::set<GURL>& extra_exceptions, | 105 const std::set<GURL>& extra_exceptions, |
83 int64_t global_quota, | 106 int64_t global_quota, |
84 const GetOriginCallback& callback) = 0; | 107 const GetOriginCallback& callback) = 0; |
85 | 108 |
86 // Called to evict an origin. | 109 virtual void EvictOriginData( |
87 virtual void EvictOriginData(const GURL& origin, | 110 const GURL& origin, |
88 StorageType type, | 111 StorageType type, |
89 const StatusCallback& callback) = 0; | 112 const EvictOriginDataCallback& callback) = 0; |
| 113 |
| 114 virtual void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) = 0; |
| 115 virtual void GetUsageAndQuotaForEviction( |
| 116 const UsageAndQuotaCallback& callback) = 0; |
90 | 117 |
91 protected: | 118 protected: |
92 virtual ~QuotaEvictionHandler() {} | 119 virtual ~QuotaEvictionHandler() {} |
93 }; | 120 }; |
94 | 121 |
95 struct UsageInfo { | 122 struct UsageInfo { |
96 UsageInfo(const std::string& host, StorageType type, int64_t usage) | 123 UsageInfo(const std::string& host, StorageType type, int64_t usage) |
97 : host(host), type(type), usage(usage) {} | 124 : host(host), type(type), usage(usage) {} |
98 std::string host; | 125 std::string host; |
99 StorageType type; | 126 StorageType type; |
100 int64_t usage; | 127 int64_t usage; |
101 }; | 128 }; |
102 | 129 |
103 // The quota manager class. This class is instantiated per profile and | 130 // The quota manager class. This class is instantiated per profile and |
104 // held by the profile. With the exception of the constructor and the | 131 // held by the profile. With the exception of the constructor and the |
105 // proxy() method, all methods should only be called on the IO thread. | 132 // proxy() method, all methods should only be called on the IO thread. |
106 class STORAGE_EXPORT QuotaManager | 133 class STORAGE_EXPORT QuotaManager |
107 : public QuotaTaskObserver, | 134 : public QuotaTaskObserver, |
108 public QuotaEvictionHandler, | 135 public QuotaEvictionHandler, |
109 public base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter> { | 136 public base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter> { |
110 public: | 137 public: |
111 typedef base::Callback< | 138 typedef base::Callback<void(QuotaStatusCode, |
112 void(QuotaStatusCode, int64_t /* usage */, int64_t /* quota */)> | 139 int64_t /* usage */, |
113 UsageAndQuotaCallback; | 140 int64_t /* quota */)> GetUsageAndQuotaCallback; |
114 | 141 |
| 142 static const int64_t kIncognitoDefaultQuotaLimit; |
115 static const int64_t kNoLimit; | 143 static const int64_t kNoLimit; |
116 | 144 |
117 QuotaManager( | 145 QuotaManager( |
118 bool is_incognito, | 146 bool is_incognito, |
119 const base::FilePath& profile_path, | 147 const base::FilePath& profile_path, |
120 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, | 148 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, |
121 const scoped_refptr<base::SequencedTaskRunner>& db_thread, | 149 const scoped_refptr<base::SequencedTaskRunner>& db_thread, |
122 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, | 150 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy); |
123 const GetQuotaSettingsFunc& get_settings_function); | |
124 | |
125 const QuotaSettings& settings() const { return settings_; } | |
126 void SetQuotaSettings(const QuotaSettings& settings); | |
127 | 151 |
128 // Returns a proxy object that can be used on any thread. | 152 // Returns a proxy object that can be used on any thread. |
129 QuotaManagerProxy* proxy() { return proxy_.get(); } | 153 QuotaManagerProxy* proxy() { return proxy_.get(); } |
130 | 154 |
131 // Called by clients or webapps. Returns usage per host. | 155 // Called by clients or webapps. Returns usage per host. |
132 void GetUsageInfo(const GetUsageInfoCallback& callback); | 156 void GetUsageInfo(const GetUsageInfoCallback& callback); |
133 | 157 |
134 // Called by Web Apps. | 158 // Called by Web Apps. |
135 // This method is declared as virtual to allow test code to override it. | 159 // This method is declared as virtual to allow test code to override it. |
136 virtual void GetUsageAndQuotaForWebApps( | 160 virtual void GetUsageAndQuotaForWebApps( |
137 const GURL& origin, | 161 const GURL& origin, |
138 StorageType type, | 162 StorageType type, |
139 const UsageAndQuotaCallback& callback); | 163 const GetUsageAndQuotaCallback& callback); |
140 | 164 |
141 // Called by StorageClients. | 165 // Called by StorageClients. |
142 // This method is declared as virtual to allow test code to override it. | 166 // This method is declared as virtual to allow test code to override it. |
143 // | 167 // |
144 // For UnlimitedStorage origins, this version skips usage and quota handling | 168 // For UnlimitedStorage origins, this version skips usage and quota handling |
145 // to avoid extra query cost. | 169 // to avoid extra query cost. |
146 // Do not call this method for apps/user-facing code. | 170 // Do not call this method for apps/user-facing code. |
147 virtual void GetUsageAndQuota(const GURL& origin, | 171 virtual void GetUsageAndQuota( |
148 StorageType type, | 172 const GURL& origin, |
149 const UsageAndQuotaCallback& callback); | 173 StorageType type, |
| 174 const GetUsageAndQuotaCallback& callback); |
150 | 175 |
151 // Called by clients via proxy. | 176 // Called by clients via proxy. |
152 // Client storage should call this method when storage is accessed. | 177 // Client storage should call this method when storage is accessed. |
153 // Used to maintain LRU ordering. | 178 // Used to maintain LRU ordering. |
154 void NotifyStorageAccessed(QuotaClient::ID client_id, | 179 void NotifyStorageAccessed(QuotaClient::ID client_id, |
155 const GURL& origin, | 180 const GURL& origin, |
156 StorageType type); | 181 StorageType type); |
157 | 182 |
158 // Called by clients via proxy. | 183 // Called by clients via proxy. |
159 // Client storage must call this method whenever they have made any | 184 // Client storage must call this method whenever they have made any |
(...skipping 10 matching lines...) Expand all Loading... |
170 void NotifyOriginNoLongerInUse(const GURL& origin); | 195 void NotifyOriginNoLongerInUse(const GURL& origin); |
171 bool IsOriginInUse(const GURL& origin) const { | 196 bool IsOriginInUse(const GURL& origin) const { |
172 return origins_in_use_.find(origin) != origins_in_use_.end(); | 197 return origins_in_use_.find(origin) != origins_in_use_.end(); |
173 } | 198 } |
174 | 199 |
175 void SetUsageCacheEnabled(QuotaClient::ID client_id, | 200 void SetUsageCacheEnabled(QuotaClient::ID client_id, |
176 const GURL& origin, | 201 const GURL& origin, |
177 StorageType type, | 202 StorageType type, |
178 bool enabled); | 203 bool enabled); |
179 | 204 |
| 205 // Set the eviction policy to use when choosing an origin to evict. |
| 206 void SetTemporaryStorageEvictionPolicy( |
| 207 std::unique_ptr<QuotaEvictionPolicy> policy); |
| 208 |
180 // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a | 209 // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a |
181 // particular StorageType associated with either a specific origin or set of | 210 // particular StorageType associated with either a specific origin or set of |
182 // origins. Each method additionally requires a |quota_client_mask| which | 211 // origins. Each method additionally requires a |quota_client_mask| which |
183 // specifies the types of QuotaClients to delete from the origin. This is | 212 // specifies the types of QuotaClients to delete from the origin. This is |
184 // specified by the caller as a bitmask built from QuotaClient::IDs. Setting | 213 // specified by the caller as a bitmask built from QuotaClient::IDs. Setting |
185 // the mask to QuotaClient::kAllClientsMask will remove all clients from the | 214 // the mask to QuotaClient::kAllClientsMask will remove all clients from the |
186 // origin, regardless of type. | 215 // origin, regardless of type. |
187 virtual void DeleteOriginData(const GURL& origin, | 216 virtual void DeleteOriginData(const GURL& origin, |
188 StorageType type, | 217 StorageType type, |
189 int quota_client_mask, | 218 int quota_client_mask, |
190 const StatusCallback& callback); | 219 const StatusCallback& callback); |
191 void DeleteHostData(const std::string& host, | 220 void DeleteHostData(const std::string& host, |
192 StorageType type, | 221 StorageType type, |
193 int quota_client_mask, | 222 int quota_client_mask, |
194 const StatusCallback& callback); | 223 const StatusCallback& callback); |
195 | 224 |
196 // Called by UI and internal modules. | 225 // Called by UI and internal modules. |
| 226 void GetAvailableSpace(const AvailableSpaceCallback& callback); |
| 227 void GetTemporaryGlobalQuota(const QuotaCallback& callback); |
| 228 |
| 229 // Ok to call with NULL callback. |
| 230 void SetTemporaryGlobalOverrideQuota(int64_t new_quota, |
| 231 const QuotaCallback& callback); |
| 232 |
197 void GetPersistentHostQuota(const std::string& host, | 233 void GetPersistentHostQuota(const std::string& host, |
198 const QuotaCallback& callback); | 234 const QuotaCallback& callback); |
199 void SetPersistentHostQuota(const std::string& host, | 235 void SetPersistentHostQuota(const std::string& host, |
200 int64_t new_quota, | 236 int64_t new_quota, |
201 const QuotaCallback& callback); | 237 const QuotaCallback& callback); |
202 void GetGlobalUsage(StorageType type, const GlobalUsageCallback& callback); | 238 void GetGlobalUsage(StorageType type, const GlobalUsageCallback& callback); |
203 void GetHostUsage(const std::string& host, StorageType type, | 239 void GetHostUsage(const std::string& host, StorageType type, |
204 const UsageCallback& callback); | 240 const UsageCallback& callback); |
205 void GetHostUsage(const std::string& host, StorageType type, | 241 void GetHostUsage(const std::string& host, StorageType type, |
206 QuotaClient::ID client_id, | 242 QuotaClient::ID client_id, |
207 const UsageCallback& callback); | 243 const UsageCallback& callback); |
208 | 244 |
209 bool IsTrackingHostUsage(StorageType type, QuotaClient::ID client_id) const; | 245 bool IsTrackingHostUsage(StorageType type, QuotaClient::ID client_id) const; |
210 | 246 |
211 void GetStatistics(std::map<std::string, std::string>* statistics); | 247 void GetStatistics(std::map<std::string, std::string>* statistics); |
212 | 248 |
213 bool IsStorageUnlimited(const GURL& origin, StorageType type) const; | 249 bool IsStorageUnlimited(const GURL& origin, StorageType type) const; |
214 | 250 |
| 251 bool CanQueryDiskSize(const GURL& origin) const { |
| 252 return special_storage_policy_.get() && |
| 253 special_storage_policy_->CanQueryDiskSize(origin); |
| 254 } |
| 255 |
215 virtual void GetOriginsModifiedSince(StorageType type, | 256 virtual void GetOriginsModifiedSince(StorageType type, |
216 base::Time modified_since, | 257 base::Time modified_since, |
217 const GetOriginsCallback& callback); | 258 const GetOriginsCallback& callback); |
218 | 259 |
219 bool ResetUsageTracker(StorageType type); | 260 bool ResetUsageTracker(StorageType type); |
220 | 261 |
221 // Used to register/deregister observers that wish to monitor storage events. | 262 // Used to register/deregister observers that wish to monitor storage events. |
222 void AddStorageObserver(StorageObserver* observer, | 263 void AddStorageObserver(StorageObserver* observer, |
223 const StorageObserver::MonitorParams& params); | 264 const StorageObserver::MonitorParams& params); |
224 void RemoveStorageObserver(StorageObserver* observer); | 265 void RemoveStorageObserver(StorageObserver* observer); |
225 void RemoveStorageObserverForFilter(StorageObserver* observer, | 266 void RemoveStorageObserverForFilter(StorageObserver* observer, |
226 const StorageObserver::Filter& filter); | 267 const StorageObserver::Filter& filter); |
227 | 268 |
| 269 // Determines the portion of the temp pool that can be |
| 270 // utilized by a single host (ie. 5 for 20%). |
| 271 static const int kPerHostTemporaryPortion; |
| 272 |
228 static const int64_t kPerHostPersistentQuotaLimit; | 273 static const int64_t kPerHostPersistentQuotaLimit; |
| 274 |
229 static const char kDatabaseName[]; | 275 static const char kDatabaseName[]; |
| 276 |
230 static const int kThresholdOfErrorsToBeBlacklisted; | 277 static const int kThresholdOfErrorsToBeBlacklisted; |
| 278 |
231 static const int kEvictionIntervalInMilliSeconds; | 279 static const int kEvictionIntervalInMilliSeconds; |
| 280 |
232 static const char kTimeBetweenRepeatedOriginEvictionsHistogram[]; | 281 static const char kTimeBetweenRepeatedOriginEvictionsHistogram[]; |
233 static const char kEvictedOriginAccessedCountHistogram[]; | 282 static const char kEvictedOriginAccessedCountHistogram[]; |
234 static const char kEvictedOriginTimeSinceAccessHistogram[]; | 283 static const char kEvictedOriginTimeSinceAccessHistogram[]; |
235 | 284 |
236 // Kept non-const so that test code can change the value. | 285 // These are kept non-const so that test code can change the value. |
237 // TODO(kinuko): Make this a real const value and add a proper way to set | 286 // TODO(kinuko): Make this a real const value and add a proper way to set |
238 // the quota for syncable storage. (http://crbug.com/155488) | 287 // the quota for syncable storage. (http://crbug.com/155488) |
| 288 static int64_t kMinimumPreserveForSystem; |
239 static int64_t kSyncableStorageDefaultHostQuota; | 289 static int64_t kSyncableStorageDefaultHostQuota; |
240 | 290 |
241 protected: | 291 protected: |
242 ~QuotaManager() override; | 292 ~QuotaManager() override; |
243 | 293 |
244 private: | 294 private: |
245 friend class base::DeleteHelper<QuotaManager>; | 295 friend class base::DeleteHelper<QuotaManager>; |
246 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; | 296 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; |
247 friend class content::QuotaManagerTest; | 297 friend class content::QuotaManagerTest; |
248 friend class content::StorageMonitorTest; | 298 friend class content::StorageMonitorTest; |
249 friend class content::MockQuotaManager; | 299 friend class content::MockQuotaManager; |
250 friend class content::MockStorageClient; | 300 friend class content::MockStorageClient; |
251 friend class quota_internals::QuotaInternalsProxy; | 301 friend class quota_internals::QuotaInternalsProxy; |
252 friend class QuotaManagerProxy; | 302 friend class QuotaManagerProxy; |
253 friend class QuotaTemporaryStorageEvictor; | 303 friend class QuotaTemporaryStorageEvictor; |
254 friend struct QuotaManagerDeleter; | 304 friend struct QuotaManagerDeleter; |
| 305 friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest; |
255 | 306 |
256 class EvictionRoundInfoHelper; | |
257 class UsageAndQuotaHelper; | |
258 class GetUsageInfoTask; | 307 class GetUsageInfoTask; |
| 308 |
259 class OriginDataDeleter; | 309 class OriginDataDeleter; |
260 class HostDataDeleter; | 310 class HostDataDeleter; |
| 311 |
261 class GetModifiedSinceHelper; | 312 class GetModifiedSinceHelper; |
262 class DumpQuotaTableHelper; | 313 class DumpQuotaTableHelper; |
263 class DumpOriginInfoTableHelper; | 314 class DumpOriginInfoTableHelper; |
264 | 315 |
265 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; | 316 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; |
266 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; | 317 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; |
267 typedef std::vector<QuotaTableEntry> QuotaTableEntries; | 318 typedef std::vector<QuotaTableEntry> QuotaTableEntries; |
268 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; | 319 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; |
269 | 320 |
270 using QuotaSettingsCallback = base::Callback<void(const QuotaSettings&)>; | |
271 | |
272 // Function pointer type used to store the function which returns | 321 // Function pointer type used to store the function which returns |
273 // information about the volume containing the given FilePath. | 322 // information about the volume containing the given FilePath. |
274 // The value returned is std::pair<total_space, available_space>. | 323 using GetVolumeInfoFn = bool(*)(const base::FilePath&, |
275 using GetVolumeInfoFn = | 324 uint64_t* available, uint64_t* total); |
276 std::pair<int64_t, int64_t> (*)(const base::FilePath&); | |
277 | 325 |
278 typedef base::Callback<void(const QuotaTableEntries&)> | 326 typedef base::Callback<void(const QuotaTableEntries&)> |
279 DumpQuotaTableCallback; | 327 DumpQuotaTableCallback; |
280 typedef base::Callback<void(const OriginInfoTableEntries&)> | 328 typedef base::Callback<void(const OriginInfoTableEntries&)> |
281 DumpOriginInfoTableCallback; | 329 DumpOriginInfoTableCallback; |
282 | 330 |
283 typedef CallbackQueue<base::Closure> ClosureQueue; | 331 typedef CallbackQueue<base::Closure> ClosureQueue; |
| 332 typedef CallbackQueue<AvailableSpaceCallback, QuotaStatusCode, int64_t> |
| 333 AvailableSpaceCallbackQueue; |
284 typedef CallbackQueueMap<QuotaCallback, std::string, QuotaStatusCode, int64_t> | 334 typedef CallbackQueueMap<QuotaCallback, std::string, QuotaStatusCode, int64_t> |
285 HostQuotaCallbackMap; | 335 HostQuotaCallbackMap; |
286 using QuotaSettingsCallbackQueue = | |
287 CallbackQueue<QuotaSettingsCallback, const QuotaSettings&>; | |
288 | |
289 // The values returned total_space, available_space. | |
290 using StorageCapacityCallback = base::Callback<void(int64_t, int64_t)>; | |
291 using StorageCapacityCallbackQueue = | |
292 CallbackQueue<StorageCapacityCallback, int64_t, int64_t>; | |
293 | 336 |
294 struct EvictionContext { | 337 struct EvictionContext { |
295 EvictionContext(); | 338 EvictionContext(); |
296 ~EvictionContext(); | 339 virtual ~EvictionContext(); |
297 GURL evicted_origin; | 340 GURL evicted_origin; |
298 StorageType evicted_type; | 341 StorageType evicted_type; |
299 StatusCallback evict_origin_data_callback; | 342 |
| 343 EvictOriginDataCallback evict_origin_data_callback; |
300 }; | 344 }; |
301 | 345 |
| 346 typedef QuotaEvictionHandler::UsageAndQuotaCallback |
| 347 UsageAndQuotaDispatcherCallback; |
| 348 |
302 // This initialization method is lazily called on the IO thread | 349 // This initialization method is lazily called on the IO thread |
303 // when the first quota manager API is called. | 350 // when the first quota manager API is called. |
304 // Initialize must be called after all quota clients are added to the | 351 // Initialize must be called after all quota clients are added to the |
305 // manager by RegisterStorage. | 352 // manager by RegisterStorage. |
306 void LazyInitialize(); | 353 void LazyInitialize(); |
307 void FinishLazyInitialize(bool is_database_bootstraped); | |
308 void BootstrapDatabaseForEviction( | |
309 const GetOriginCallback& did_get_origin_callback, | |
310 int64_t unused_usage, | |
311 int64_t unused_unlimited_usage); | |
312 void DidBootstrapDatabase(const GetOriginCallback& did_get_origin_callback, | |
313 bool success); | |
314 | 354 |
315 // Called by clients via proxy. | 355 // Called by clients via proxy. |
316 // Registers a quota client to the manager. | 356 // Registers a quota client to the manager. |
317 // The client must remain valid until OnQuotaManagerDestored is called. | 357 // The client must remain valid until OnQuotaManagerDestored is called. |
318 void RegisterClient(QuotaClient* client); | 358 void RegisterClient(QuotaClient* client); |
319 | 359 |
320 UsageTracker* GetUsageTracker(StorageType type) const; | 360 UsageTracker* GetUsageTracker(StorageType type) const; |
321 | 361 |
322 // Extract cached origins list from the usage tracker. | 362 // Extract cached origins list from the usage tracker. |
323 // (Might return empty list if no origin is tracked by the tracker.) | 363 // (Might return empty list if no origin is tracked by the tracker.) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 void DidGetEvictionOrigin(const GetOriginCallback& callback, | 405 void DidGetEvictionOrigin(const GetOriginCallback& callback, |
366 const GURL& origin); | 406 const GURL& origin); |
367 | 407 |
368 // QuotaEvictionHandler. | 408 // QuotaEvictionHandler. |
369 void GetEvictionOrigin(StorageType type, | 409 void GetEvictionOrigin(StorageType type, |
370 const std::set<GURL>& extra_exceptions, | 410 const std::set<GURL>& extra_exceptions, |
371 int64_t global_quota, | 411 int64_t global_quota, |
372 const GetOriginCallback& callback) override; | 412 const GetOriginCallback& callback) override; |
373 void EvictOriginData(const GURL& origin, | 413 void EvictOriginData(const GURL& origin, |
374 StorageType type, | 414 StorageType type, |
375 const StatusCallback& callback) override; | 415 const EvictOriginDataCallback& callback) override; |
376 void GetEvictionRoundInfo(const EvictionRoundInfoCallback& callback) override; | 416 void GetUsageAndQuotaForEviction( |
| 417 const UsageAndQuotaCallback& callback) override; |
| 418 void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) override; |
| 419 |
| 420 void DidGetVolumeInfo( |
| 421 const VolumeInfoCallback& callback, |
| 422 uint64_t* available_space, uint64_t* total_space, bool success); |
377 | 423 |
378 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); | 424 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); |
379 | 425 |
| 426 void DidSetTemporaryGlobalOverrideQuota(const QuotaCallback& callback, |
| 427 const int64_t* new_quota, |
| 428 bool success); |
380 void DidGetPersistentHostQuota(const std::string& host, | 429 void DidGetPersistentHostQuota(const std::string& host, |
381 const int64_t* quota, | 430 const int64_t* quota, |
382 bool success); | 431 bool success); |
383 void DidSetPersistentHostQuota(const std::string& host, | 432 void DidSetPersistentHostQuota(const std::string& host, |
384 const QuotaCallback& callback, | 433 const QuotaCallback& callback, |
385 const int64_t* new_quota, | 434 const int64_t* new_quota, |
386 bool success); | 435 bool success); |
| 436 void DidInitialize(int64_t* temporary_quota_override, |
| 437 int64_t* desired_available_space, |
| 438 bool success); |
387 void DidGetLRUOrigin(const GURL* origin, | 439 void DidGetLRUOrigin(const GURL* origin, |
388 bool success); | 440 bool success); |
389 void GetQuotaSettings(const QuotaSettingsCallback& callback); | 441 void DidGetInitialTemporaryGlobalQuota(base::TimeTicks start_ticks, |
390 void DidGetSettings(base::TimeTicks start_ticks, | 442 QuotaStatusCode status, |
391 base::Optional<QuotaSettings> settings); | 443 int64_t quota_unused); |
392 void GetStorageCapacity(const StorageCapacityCallback& callback); | 444 void DidInitializeTemporaryOriginsInfo(bool success); |
393 void ContinueIncognitoGetStorageCapacity(const QuotaSettings& settings); | 445 void DidGetAvailableSpace(int64_t space); |
394 void DidGetStorageCapacity( | |
395 const std::pair<int64_t, int64_t>& total_and_available); | |
396 | |
397 void DidDatabaseWork(bool success); | 446 void DidDatabaseWork(bool success); |
398 | 447 |
399 void DeleteOnCorrectThread() const; | 448 void DeleteOnCorrectThread() const; |
400 | 449 |
401 void PostTaskAndReplyWithResultForDBThread( | 450 void PostTaskAndReplyWithResultForDBThread( |
402 const tracked_objects::Location& from_here, | 451 const tracked_objects::Location& from_here, |
403 const base::Callback<bool(QuotaDatabase*)>& task, | 452 const base::Callback<bool(QuotaDatabase*)>& task, |
404 const base::Callback<void(bool)>& reply); | 453 const base::Callback<void(bool)>& reply); |
405 | 454 |
406 static std::pair<int64_t, int64_t> CallGetVolumeInfo( | 455 static int64_t CallGetAmountOfFreeDiskSpace( |
407 GetVolumeInfoFn get_volume_info_fn, | 456 GetVolumeInfoFn get_vol_info_fn, |
408 const base::FilePath& path); | 457 const base::FilePath& profile_path); |
409 static std::pair<int64_t, int64_t> GetVolumeInfo(const base::FilePath& path); | 458 static bool GetVolumeInfo(const base::FilePath& path, |
| 459 uint64_t* available_space, |
| 460 uint64_t* total_size); |
410 | 461 |
411 const bool is_incognito_; | 462 const bool is_incognito_; |
412 const base::FilePath profile_path_; | 463 const base::FilePath profile_path_; |
413 | 464 |
414 scoped_refptr<QuotaManagerProxy> proxy_; | 465 scoped_refptr<QuotaManagerProxy> proxy_; |
415 bool db_disabled_; | 466 bool db_disabled_; |
416 bool eviction_disabled_; | 467 bool eviction_disabled_; |
417 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; | 468 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; |
418 scoped_refptr<base::SequencedTaskRunner> db_thread_; | 469 scoped_refptr<base::SequencedTaskRunner> db_thread_; |
419 mutable std::unique_ptr<QuotaDatabase> database_; | 470 mutable std::unique_ptr<QuotaDatabase> database_; |
420 bool is_database_bootstrapped_ = false; | |
421 | |
422 GetQuotaSettingsFunc get_settings_function_; | |
423 scoped_refptr<base::TaskRunner> get_settings_task_runner_; | |
424 QuotaSettings settings_; | |
425 base::TimeTicks settings_timestamp_; | |
426 QuotaSettingsCallbackQueue settings_callbacks_; | |
427 StorageCapacityCallbackQueue storage_capacity_callbacks_; | |
428 | 471 |
429 GetOriginCallback lru_origin_callback_; | 472 GetOriginCallback lru_origin_callback_; |
430 std::set<GURL> access_notified_origins_; | 473 std::set<GURL> access_notified_origins_; |
431 | 474 |
432 QuotaClientList clients_; | 475 QuotaClientList clients_; |
433 | 476 |
434 std::unique_ptr<UsageTracker> temporary_usage_tracker_; | 477 std::unique_ptr<UsageTracker> temporary_usage_tracker_; |
435 std::unique_ptr<UsageTracker> persistent_usage_tracker_; | 478 std::unique_ptr<UsageTracker> persistent_usage_tracker_; |
436 std::unique_ptr<UsageTracker> syncable_usage_tracker_; | 479 std::unique_ptr<UsageTracker> syncable_usage_tracker_; |
437 // TODO(michaeln): Need a way to clear the cache, drop and | 480 // TODO(michaeln): Need a way to clear the cache, drop and |
438 // reinstantiate the trackers when they're not handling requests. | 481 // reinstantiate the trackers when they're not handling requests. |
439 | 482 |
440 std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; | 483 std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; |
441 EvictionContext eviction_context_; | 484 EvictionContext eviction_context_; |
| 485 std::unique_ptr<QuotaEvictionPolicy> temporary_storage_eviction_policy_; |
442 bool is_getting_eviction_origin_; | 486 bool is_getting_eviction_origin_; |
443 | 487 |
| 488 ClosureQueue db_initialization_callbacks_; |
| 489 AvailableSpaceCallbackQueue available_space_callbacks_; |
444 HostQuotaCallbackMap persistent_host_quota_callbacks_; | 490 HostQuotaCallbackMap persistent_host_quota_callbacks_; |
445 | 491 |
| 492 bool temporary_quota_initialized_; |
| 493 int64_t temporary_quota_override_; |
| 494 int64_t desired_available_space_; |
| 495 |
446 // Map from origin to count. | 496 // Map from origin to count. |
447 std::map<GURL, int> origins_in_use_; | 497 std::map<GURL, int> origins_in_use_; |
448 // Map from origin to error count. | 498 // Map from origin to error count. |
449 std::map<GURL, int> origins_in_error_; | 499 std::map<GURL, int> origins_in_error_; |
450 | 500 |
451 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 501 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
452 | 502 |
453 base::RepeatingTimer histogram_timer_; | 503 base::RepeatingTimer histogram_timer_; |
454 | 504 |
455 // Pointer to the function used to get volume information. This is | 505 // Pointer to the function used to get volume information. This is |
(...skipping 10 matching lines...) Expand all Loading... |
466 | 516 |
467 struct QuotaManagerDeleter { | 517 struct QuotaManagerDeleter { |
468 static void Destruct(const QuotaManager* manager) { | 518 static void Destruct(const QuotaManager* manager) { |
469 manager->DeleteOnCorrectThread(); | 519 manager->DeleteOnCorrectThread(); |
470 } | 520 } |
471 }; | 521 }; |
472 | 522 |
473 } // namespace storage | 523 } // namespace storage |
474 | 524 |
475 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 525 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
OLD | NEW |