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

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

Issue 1343273003: Integrate SiteEngagementEvictionPolicy with QuotaManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add_eviction_policy
Patch Set: export Created 5 years, 2 months 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 <deque> 8 #include <deque>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/containers/scoped_ptr_map.h"
18 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
19 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
20 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
21 #include "base/memory/weak_ptr.h" 22 #include "base/memory/weak_ptr.h"
22 #include "base/sequenced_task_runner_helpers.h" 23 #include "base/sequenced_task_runner_helpers.h"
23 #include "storage/browser/quota/quota_callbacks.h" 24 #include "storage/browser/quota/quota_callbacks.h"
24 #include "storage/browser/quota/quota_client.h" 25 #include "storage/browser/quota/quota_client.h"
25 #include "storage/browser/quota/quota_database.h" 26 #include "storage/browser/quota/quota_database.h"
26 #include "storage/browser/quota/quota_task.h" 27 #include "storage/browser/quota/quota_task.h"
27 #include "storage/browser/quota/special_storage_policy.h" 28 #include "storage/browser/quota/special_storage_policy.h"
28 #include "storage/browser/quota/storage_observer.h" 29 #include "storage/browser/quota/storage_observer.h"
29 #include "storage/browser/storage_browser_export.h" 30 #include "storage/browser/storage_browser_export.h"
30 31
32 class SiteEngagementEvictionPolicyWithQuotaManagerTest;
33
31 namespace base { 34 namespace base {
32 class FilePath; 35 class FilePath;
33 class SequencedTaskRunner; 36 class SequencedTaskRunner;
34 class SingleThreadTaskRunner; 37 class SingleThreadTaskRunner;
35 } 38 }
36 39
37 namespace quota_internals { 40 namespace quota_internals {
38 class QuotaInternalsProxy; 41 class QuotaInternalsProxy;
39 } 42 }
40 43
(...skipping 22 matching lines...) Expand all
63 int64 available_disk_space; 66 int64 available_disk_space;
64 67
65 UsageAndQuota(); 68 UsageAndQuota();
66 UsageAndQuota(int64 usage, 69 UsageAndQuota(int64 usage,
67 int64 global_limited_usage, 70 int64 global_limited_usage,
68 int64 quota, 71 int64 quota,
69 int64 available_disk_space); 72 int64 available_disk_space);
70 }; 73 };
71 74
72 // TODO(calamity): Use this in the temporary storage eviction path. 75 // TODO(calamity): Use this in the temporary storage eviction path.
73 // An interface for deciding which origin's temporary storage should be evicted 76 // An interface for deciding which origin's storage should be evicted when the
74 // when the quota is exceeded. 77 // quota is exceeded.
75 class STORAGE_EXPORT QuotaEvictionPolicy { 78 class STORAGE_EXPORT QuotaEvictionPolicy {
76 public: 79 public:
80 struct STORAGE_EXPORT Info {
81 std::map<GURL, int64> origin_usage_map;
82 int64 global_quota = 0;
83
84 Info();
85 ~Info();
86 };
87
88 virtual ~QuotaEvictionPolicy() {}
89
77 // Returns the next origin to evict. It might return an empty GURL when there 90 // Returns the next origin to evict. It might return an empty GURL when there
78 // are no evictable origins. 91 // are no evictable origins.
79 virtual void GetEvictionOrigin( 92 virtual void GetEvictionOrigin(
93 scoped_ptr<Info> info,
80 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, 94 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy,
81 const std::map<GURL, int64>& usage_map,
82 int64 global_quota,
83 const GetOriginCallback& callback) = 0; 95 const GetOriginCallback& callback) = 0;
96
97 virtual bool NeedsOriginUsageMap();
98 virtual bool NeedsGlobalQuota();
michaeln 2015/10/06 00:35:09 It'd be simpler to always include this info and I
calamity 2015/10/07 02:42:46 Done.
84 }; 99 };
85 100
86 // An interface called by QuotaTemporaryStorageEvictor. 101 // An interface called by QuotaTemporaryStorageEvictor.
87 class STORAGE_EXPORT QuotaEvictionHandler { 102 class STORAGE_EXPORT QuotaEvictionHandler {
88 public: 103 public:
89 typedef StatusCallback EvictOriginDataCallback; 104 typedef StatusCallback EvictOriginDataCallback;
90 typedef base::Callback<void(QuotaStatusCode status, 105 typedef base::Callback<void(QuotaStatusCode status,
91 const UsageAndQuota& usage_and_quota)> 106 const UsageAndQuota& usage_and_quota)>
92 UsageAndQuotaCallback; 107 UsageAndQuotaCallback;
93 108
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 void NotifyOriginNoLongerInUse(const GURL& origin); 202 void NotifyOriginNoLongerInUse(const GURL& origin);
188 bool IsOriginInUse(const GURL& origin) const { 203 bool IsOriginInUse(const GURL& origin) const {
189 return origins_in_use_.find(origin) != origins_in_use_.end(); 204 return origins_in_use_.find(origin) != origins_in_use_.end();
190 } 205 }
191 206
192 void SetUsageCacheEnabled(QuotaClient::ID client_id, 207 void SetUsageCacheEnabled(QuotaClient::ID client_id,
193 const GURL& origin, 208 const GURL& origin,
194 StorageType type, 209 StorageType type,
195 bool enabled); 210 bool enabled);
196 211
212 // Set the eviction policy to use when choosing an origin to evict.
213 void SetQuotaEvictionPolicy(StorageType type,
michaeln 2015/10/06 00:35:09 We can probably constrain this to just "temp" stor
calamity 2015/10/07 02:42:46 Done.
214 scoped_ptr<QuotaEvictionPolicy> policy);
215
197 // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a 216 // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a
198 // particular StorageType associated with either a specific origin or set of 217 // particular StorageType associated with either a specific origin or set of
199 // origins. Each method additionally requires a |quota_client_mask| which 218 // origins. Each method additionally requires a |quota_client_mask| which
200 // specifies the types of QuotaClients to delete from the origin. This is 219 // specifies the types of QuotaClients to delete from the origin. This is
201 // specified by the caller as a bitmask built from QuotaClient::IDs. Setting 220 // specified by the caller as a bitmask built from QuotaClient::IDs. Setting
202 // the mask to QuotaClient::kAllClientsMask will remove all clients from the 221 // the mask to QuotaClient::kAllClientsMask will remove all clients from the
203 // origin, regardless of type. 222 // origin, regardless of type.
204 virtual void DeleteOriginData(const GURL& origin, 223 virtual void DeleteOriginData(const GURL& origin,
205 StorageType type, 224 StorageType type,
206 int quota_client_mask, 225 int quota_client_mask,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 257
239 bool CanQueryDiskSize(const GURL& origin) const { 258 bool CanQueryDiskSize(const GURL& origin) const {
240 return special_storage_policy_.get() && 259 return special_storage_policy_.get() &&
241 special_storage_policy_->CanQueryDiskSize(origin); 260 special_storage_policy_->CanQueryDiskSize(origin);
242 } 261 }
243 262
244 virtual void GetOriginsModifiedSince(StorageType type, 263 virtual void GetOriginsModifiedSince(StorageType type,
245 base::Time modified_since, 264 base::Time modified_since,
246 const GetOriginsCallback& callback); 265 const GetOriginsCallback& callback);
247 266
267 UsageTracker* GetUsageTracker(StorageType type) const;
michaeln 2015/10/06 00:35:09 pleas keep this method private
calamity 2015/10/07 02:42:46 Done.
248 bool ResetUsageTracker(StorageType type); 268 bool ResetUsageTracker(StorageType type);
249 269
250 // Used to register/deregister observers that wish to monitor storage events. 270 // Used to register/deregister observers that wish to monitor storage events.
251 void AddStorageObserver(StorageObserver* observer, 271 void AddStorageObserver(StorageObserver* observer,
252 const StorageObserver::MonitorParams& params); 272 const StorageObserver::MonitorParams& params);
253 void RemoveStorageObserver(StorageObserver* observer); 273 void RemoveStorageObserver(StorageObserver* observer);
254 void RemoveStorageObserverForFilter(StorageObserver* observer, 274 void RemoveStorageObserverForFilter(StorageObserver* observer,
255 const StorageObserver::Filter& filter); 275 const StorageObserver::Filter& filter);
256 276
257 // Determines the portion of the temp pool that can be 277 // Determines the portion of the temp pool that can be
(...skipping 21 matching lines...) Expand all
279 friend class base::DeleteHelper<QuotaManager>; 299 friend class base::DeleteHelper<QuotaManager>;
280 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; 300 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>;
281 friend class content::QuotaManagerTest; 301 friend class content::QuotaManagerTest;
282 friend class content::StorageMonitorTest; 302 friend class content::StorageMonitorTest;
283 friend class content::MockQuotaManager; 303 friend class content::MockQuotaManager;
284 friend class content::MockStorageClient; 304 friend class content::MockStorageClient;
285 friend class quota_internals::QuotaInternalsProxy; 305 friend class quota_internals::QuotaInternalsProxy;
286 friend class QuotaManagerProxy; 306 friend class QuotaManagerProxy;
287 friend class QuotaTemporaryStorageEvictor; 307 friend class QuotaTemporaryStorageEvictor;
288 friend struct QuotaManagerDeleter; 308 friend struct QuotaManagerDeleter;
309 friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest;
289 310
290 class GetUsageInfoTask; 311 class GetUsageInfoTask;
312 class GetEvictionOriginTask;
291 313
292 class OriginDataDeleter; 314 class OriginDataDeleter;
293 class HostDataDeleter; 315 class HostDataDeleter;
294 316
295 class GetModifiedSinceHelper; 317 class GetModifiedSinceHelper;
296 class DumpQuotaTableHelper; 318 class DumpQuotaTableHelper;
297 class DumpOriginInfoTableHelper; 319 class DumpOriginInfoTableHelper;
298 320
299 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; 321 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry;
300 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; 322 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // when the first quota manager API is called. 354 // when the first quota manager API is called.
333 // Initialize must be called after all quota clients are added to the 355 // Initialize must be called after all quota clients are added to the
334 // manager by RegisterStorage. 356 // manager by RegisterStorage.
335 void LazyInitialize(); 357 void LazyInitialize();
336 358
337 // Called by clients via proxy. 359 // Called by clients via proxy.
338 // Registers a quota client to the manager. 360 // Registers a quota client to the manager.
339 // The client must remain valid until OnQuotaManagerDestored is called. 361 // The client must remain valid until OnQuotaManagerDestored is called.
340 void RegisterClient(QuotaClient* client); 362 void RegisterClient(QuotaClient* client);
341 363
342 UsageTracker* GetUsageTracker(StorageType type) const;
343
344 // Extract cached origins list from the usage tracker. 364 // Extract cached origins list from the usage tracker.
345 // (Might return empty list if no origin is tracked by the tracker.) 365 // (Might return empty list if no origin is tracked by the tracker.)
346 void GetCachedOrigins(StorageType type, std::set<GURL>* origins); 366 void GetCachedOrigins(StorageType type, std::set<GURL>* origins);
347 367
348 // These internal methods are separately defined mainly for testing. 368 // These internal methods are separately defined mainly for testing.
349 void NotifyStorageAccessedInternal( 369 void NotifyStorageAccessedInternal(
350 QuotaClient::ID client_id, 370 QuotaClient::ID client_id,
351 const GURL& origin, 371 const GURL& origin,
352 StorageType type, 372 StorageType type,
353 base::Time accessed_time); 373 base::Time accessed_time);
(...skipping 12 matching lines...) Expand all
366 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); 386 void DeleteOriginFromDatabase(const GURL& origin, StorageType type);
367 387
368 void DidOriginDataEvicted(QuotaStatusCode status); 388 void DidOriginDataEvicted(QuotaStatusCode status);
369 389
370 void ReportHistogram(); 390 void ReportHistogram();
371 void DidGetTemporaryGlobalUsageForHistogram(int64 usage, 391 void DidGetTemporaryGlobalUsageForHistogram(int64 usage,
372 int64 unlimited_usage); 392 int64 unlimited_usage);
373 void DidGetPersistentGlobalUsageForHistogram(int64 usage, 393 void DidGetPersistentGlobalUsageForHistogram(int64 usage,
374 int64 unlimited_usage); 394 int64 unlimited_usage);
375 395
396 void DidGetEvictionOrigin(const GetOriginCallback& callback,
397 const GURL& origin);
398
376 // QuotaEvictionHandler. 399 // QuotaEvictionHandler.
377 void GetEvictionOrigin(StorageType type, 400 void GetEvictionOrigin(StorageType type,
378 const GetOriginCallback& callback) override; 401 const GetOriginCallback& callback) override;
379 void EvictOriginData(const GURL& origin, 402 void EvictOriginData(const GURL& origin,
380 StorageType type, 403 StorageType type,
381 const EvictOriginDataCallback& callback) override; 404 const EvictOriginDataCallback& callback) override;
382 void GetUsageAndQuotaForEviction( 405 void GetUsageAndQuotaForEviction(
383 const UsageAndQuotaCallback& callback) override; 406 const UsageAndQuotaCallback& callback) override;
384 407
385 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); 408 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 477
455 base::RepeatingTimer histogram_timer_; 478 base::RepeatingTimer histogram_timer_;
456 479
457 // Pointer to the function used to get the available disk space. This is 480 // Pointer to the function used to get the available disk space. This is
458 // overwritten by QuotaManagerTest in order to attain a deterministic reported 481 // overwritten by QuotaManagerTest in order to attain a deterministic reported
459 // value. The default value points to base::SysInfo::AmountOfFreeDiskSpace. 482 // value. The default value points to base::SysInfo::AmountOfFreeDiskSpace.
460 GetAvailableDiskSpaceFn get_disk_space_fn_; 483 GetAvailableDiskSpaceFn get_disk_space_fn_;
461 484
462 scoped_ptr<StorageMonitor> storage_monitor_; 485 scoped_ptr<StorageMonitor> storage_monitor_;
463 486
487 base::ScopedPtrMap<StorageType, scoped_ptr<QuotaEvictionPolicy>>
488 eviction_policy_map_;
michaeln 2015/10/06 00:35:09 lets put these new data members next to the other
calamity 2015/10/07 02:42:46 Done.
489
490 bool is_getting_eviction_origin_;
491
464 base::WeakPtrFactory<QuotaManager> weak_factory_; 492 base::WeakPtrFactory<QuotaManager> weak_factory_;
465 493
466 DISALLOW_COPY_AND_ASSIGN(QuotaManager); 494 DISALLOW_COPY_AND_ASSIGN(QuotaManager);
467 }; 495 };
468 496
469 struct QuotaManagerDeleter { 497 struct QuotaManagerDeleter {
470 static void Destruct(const QuotaManager* manager) { 498 static void Destruct(const QuotaManager* manager) {
471 manager->DeleteOnCorrectThread(); 499 manager->DeleteOnCorrectThread();
472 } 500 }
473 }; 501 };
474 502
475 } // namespace storage 503 } // namespace storage
476 504
477 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ 505 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698