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