Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: storage/browser/quota/quota_manager.h

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

Powered by Google App Engine
This is Rietveld 408576698