| 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 <deque> | 8 #include <deque> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 22 #include "base/sequenced_task_runner_helpers.h" | 22 #include "base/sequenced_task_runner_helpers.h" |
| 23 #include "storage/browser/quota/quota_callbacks.h" | 23 #include "storage/browser/quota/quota_callbacks.h" |
| 24 #include "storage/browser/quota/quota_client.h" | 24 #include "storage/browser/quota/quota_client.h" |
| 25 #include "storage/browser/quota/quota_database.h" | 25 #include "storage/browser/quota/quota_database.h" |
| 26 #include "storage/browser/quota/quota_task.h" | 26 #include "storage/browser/quota/quota_task.h" |
| 27 #include "storage/browser/quota/special_storage_policy.h" | 27 #include "storage/browser/quota/special_storage_policy.h" |
| 28 #include "storage/browser/quota/storage_observer.h" | 28 #include "storage/browser/quota/storage_observer.h" |
| 29 #include "storage/browser/storage_browser_export.h" | 29 #include "storage/browser/storage_browser_export.h" |
| 30 | 30 |
| 31 class SiteEngagementEvictionPolicyWithQuotaManagerTest; |
| 32 |
| 31 namespace base { | 33 namespace base { |
| 32 class FilePath; | 34 class FilePath; |
| 33 class SequencedTaskRunner; | 35 class SequencedTaskRunner; |
| 34 class SingleThreadTaskRunner; | 36 class SingleThreadTaskRunner; |
| 35 } | 37 } |
| 36 | 38 |
| 37 namespace quota_internals { | 39 namespace quota_internals { |
| 38 class QuotaInternalsProxy; | 40 class QuotaInternalsProxy; |
| 39 } | 41 } |
| 40 | 42 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 63 int64 available_disk_space; | 65 int64 available_disk_space; |
| 64 | 66 |
| 65 UsageAndQuota(); | 67 UsageAndQuota(); |
| 66 UsageAndQuota(int64 usage, | 68 UsageAndQuota(int64 usage, |
| 67 int64 global_limited_usage, | 69 int64 global_limited_usage, |
| 68 int64 quota, | 70 int64 quota, |
| 69 int64 available_disk_space); | 71 int64 available_disk_space); |
| 70 }; | 72 }; |
| 71 | 73 |
| 72 // TODO(calamity): Use this in the temporary storage eviction path. | 74 // TODO(calamity): Use this in the temporary storage eviction path. |
| 73 // An interface for deciding which origin's temporary storage should be evicted | 75 // An interface for deciding which origin's storage should be evicted when the |
| 74 // when the quota is exceeded. | 76 // quota is exceeded. |
| 75 class STORAGE_EXPORT QuotaEvictionPolicy { | 77 class STORAGE_EXPORT QuotaEvictionPolicy { |
| 76 public: | 78 public: |
| 79 virtual ~QuotaEvictionPolicy() {} |
| 80 |
| 77 // Returns the next origin to evict. It might return an empty GURL when there | 81 // Returns the next origin to evict. It might return an empty GURL when there |
| 78 // are no evictable origins. | 82 // are no evictable origins. |
| 79 virtual void GetEvictionOrigin( | 83 virtual void GetEvictionOrigin( |
| 80 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, | 84 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, |
| 81 const std::map<GURL, int64>& usage_map, | 85 const std::map<GURL, int64>& usage_map, |
| 82 int64 global_quota, | 86 int64 global_quota, |
| 83 const GetOriginCallback& callback) = 0; | 87 const GetOriginCallback& callback) = 0; |
| 84 }; | 88 }; |
| 85 | 89 |
| 86 // An interface called by QuotaTemporaryStorageEvictor. | 90 // An interface called by QuotaTemporaryStorageEvictor. |
| 87 class STORAGE_EXPORT QuotaEvictionHandler { | 91 class STORAGE_EXPORT QuotaEvictionHandler { |
| 88 public: | 92 public: |
| 89 typedef StatusCallback EvictOriginDataCallback; | 93 typedef StatusCallback EvictOriginDataCallback; |
| 90 typedef base::Callback<void(QuotaStatusCode status, | 94 typedef base::Callback<void(QuotaStatusCode status, |
| 91 const UsageAndQuota& usage_and_quota)> | 95 const UsageAndQuota& usage_and_quota)> |
| 92 UsageAndQuotaCallback; | 96 UsageAndQuotaCallback; |
| 93 | 97 |
| 94 // Returns next origin to evict. It might return an empty GURL when there are | 98 // Returns next origin to evict. It might return an empty GURL when there are |
| 95 // no evictable origins. | 99 // no evictable origins. |
| 96 virtual void GetEvictionOrigin(StorageType type, | 100 virtual void GetEvictionOrigin(StorageType type, |
| 101 int64 global_quota, |
| 97 const GetOriginCallback& callback) = 0; | 102 const GetOriginCallback& callback) = 0; |
| 98 | 103 |
| 99 virtual void EvictOriginData( | 104 virtual void EvictOriginData( |
| 100 const GURL& origin, | 105 const GURL& origin, |
| 101 StorageType type, | 106 StorageType type, |
| 102 const EvictOriginDataCallback& callback) = 0; | 107 const EvictOriginDataCallback& callback) = 0; |
| 103 | 108 |
| 104 virtual void GetUsageAndQuotaForEviction( | 109 virtual void GetUsageAndQuotaForEviction( |
| 105 const UsageAndQuotaCallback& callback) = 0; | 110 const UsageAndQuotaCallback& callback) = 0; |
| 106 | 111 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 void NotifyOriginNoLongerInUse(const GURL& origin); | 192 void NotifyOriginNoLongerInUse(const GURL& origin); |
| 188 bool IsOriginInUse(const GURL& origin) const { | 193 bool IsOriginInUse(const GURL& origin) const { |
| 189 return origins_in_use_.find(origin) != origins_in_use_.end(); | 194 return origins_in_use_.find(origin) != origins_in_use_.end(); |
| 190 } | 195 } |
| 191 | 196 |
| 192 void SetUsageCacheEnabled(QuotaClient::ID client_id, | 197 void SetUsageCacheEnabled(QuotaClient::ID client_id, |
| 193 const GURL& origin, | 198 const GURL& origin, |
| 194 StorageType type, | 199 StorageType type, |
| 195 bool enabled); | 200 bool enabled); |
| 196 | 201 |
| 202 // Set the eviction policy to use when choosing an origin to evict. |
| 203 void SetTemporaryStorageEvictionPolicy( |
| 204 scoped_ptr<QuotaEvictionPolicy> policy); |
| 205 |
| 197 // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a | 206 // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a |
| 198 // particular StorageType associated with either a specific origin or set of | 207 // particular StorageType associated with either a specific origin or set of |
| 199 // origins. Each method additionally requires a |quota_client_mask| which | 208 // origins. Each method additionally requires a |quota_client_mask| which |
| 200 // specifies the types of QuotaClients to delete from the origin. This is | 209 // 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 | 210 // specified by the caller as a bitmask built from QuotaClient::IDs. Setting |
| 202 // the mask to QuotaClient::kAllClientsMask will remove all clients from the | 211 // the mask to QuotaClient::kAllClientsMask will remove all clients from the |
| 203 // origin, regardless of type. | 212 // origin, regardless of type. |
| 204 virtual void DeleteOriginData(const GURL& origin, | 213 virtual void DeleteOriginData(const GURL& origin, |
| 205 StorageType type, | 214 StorageType type, |
| 206 int quota_client_mask, | 215 int quota_client_mask, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 friend class base::DeleteHelper<QuotaManager>; | 288 friend class base::DeleteHelper<QuotaManager>; |
| 280 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; | 289 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; |
| 281 friend class content::QuotaManagerTest; | 290 friend class content::QuotaManagerTest; |
| 282 friend class content::StorageMonitorTest; | 291 friend class content::StorageMonitorTest; |
| 283 friend class content::MockQuotaManager; | 292 friend class content::MockQuotaManager; |
| 284 friend class content::MockStorageClient; | 293 friend class content::MockStorageClient; |
| 285 friend class quota_internals::QuotaInternalsProxy; | 294 friend class quota_internals::QuotaInternalsProxy; |
| 286 friend class QuotaManagerProxy; | 295 friend class QuotaManagerProxy; |
| 287 friend class QuotaTemporaryStorageEvictor; | 296 friend class QuotaTemporaryStorageEvictor; |
| 288 friend struct QuotaManagerDeleter; | 297 friend struct QuotaManagerDeleter; |
| 298 friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest; |
| 289 | 299 |
| 290 class GetUsageInfoTask; | 300 class GetUsageInfoTask; |
| 291 | 301 |
| 292 class OriginDataDeleter; | 302 class OriginDataDeleter; |
| 293 class HostDataDeleter; | 303 class HostDataDeleter; |
| 294 | 304 |
| 295 class GetModifiedSinceHelper; | 305 class GetModifiedSinceHelper; |
| 296 class DumpQuotaTableHelper; | 306 class DumpQuotaTableHelper; |
| 297 class DumpOriginInfoTableHelper; | 307 class DumpOriginInfoTableHelper; |
| 298 | 308 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); | 376 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); |
| 367 | 377 |
| 368 void DidOriginDataEvicted(QuotaStatusCode status); | 378 void DidOriginDataEvicted(QuotaStatusCode status); |
| 369 | 379 |
| 370 void ReportHistogram(); | 380 void ReportHistogram(); |
| 371 void DidGetTemporaryGlobalUsageForHistogram(int64 usage, | 381 void DidGetTemporaryGlobalUsageForHistogram(int64 usage, |
| 372 int64 unlimited_usage); | 382 int64 unlimited_usage); |
| 373 void DidGetPersistentGlobalUsageForHistogram(int64 usage, | 383 void DidGetPersistentGlobalUsageForHistogram(int64 usage, |
| 374 int64 unlimited_usage); | 384 int64 unlimited_usage); |
| 375 | 385 |
| 386 void DidGetEvictionOrigin(const GetOriginCallback& callback, |
| 387 const GURL& origin); |
| 388 |
| 376 // QuotaEvictionHandler. | 389 // QuotaEvictionHandler. |
| 377 void GetEvictionOrigin(StorageType type, | 390 void GetEvictionOrigin(StorageType type, |
| 391 int64 global_quota, |
| 378 const GetOriginCallback& callback) override; | 392 const GetOriginCallback& callback) override; |
| 379 void EvictOriginData(const GURL& origin, | 393 void EvictOriginData(const GURL& origin, |
| 380 StorageType type, | 394 StorageType type, |
| 381 const EvictOriginDataCallback& callback) override; | 395 const EvictOriginDataCallback& callback) override; |
| 382 void GetUsageAndQuotaForEviction( | 396 void GetUsageAndQuotaForEviction( |
| 383 const UsageAndQuotaCallback& callback) override; | 397 const UsageAndQuotaCallback& callback) override; |
| 384 | 398 |
| 385 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); | 399 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); |
| 386 | 400 |
| 387 void DidSetTemporaryGlobalOverrideQuota(const QuotaCallback& callback, | 401 void DidSetTemporaryGlobalOverrideQuota(const QuotaCallback& callback, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 QuotaClientList clients_; | 442 QuotaClientList clients_; |
| 429 | 443 |
| 430 scoped_ptr<UsageTracker> temporary_usage_tracker_; | 444 scoped_ptr<UsageTracker> temporary_usage_tracker_; |
| 431 scoped_ptr<UsageTracker> persistent_usage_tracker_; | 445 scoped_ptr<UsageTracker> persistent_usage_tracker_; |
| 432 scoped_ptr<UsageTracker> syncable_usage_tracker_; | 446 scoped_ptr<UsageTracker> syncable_usage_tracker_; |
| 433 // TODO(michaeln): Need a way to clear the cache, drop and | 447 // TODO(michaeln): Need a way to clear the cache, drop and |
| 434 // reinstantiate the trackers when they're not handling requests. | 448 // reinstantiate the trackers when they're not handling requests. |
| 435 | 449 |
| 436 scoped_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; | 450 scoped_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; |
| 437 EvictionContext eviction_context_; | 451 EvictionContext eviction_context_; |
| 452 scoped_ptr<QuotaEvictionPolicy> temporary_storage_eviction_policy_; |
| 453 bool is_getting_eviction_origin_; |
| 438 | 454 |
| 439 ClosureQueue db_initialization_callbacks_; | 455 ClosureQueue db_initialization_callbacks_; |
| 440 AvailableSpaceCallbackQueue available_space_callbacks_; | 456 AvailableSpaceCallbackQueue available_space_callbacks_; |
| 441 HostQuotaCallbackMap persistent_host_quota_callbacks_; | 457 HostQuotaCallbackMap persistent_host_quota_callbacks_; |
| 442 | 458 |
| 443 bool temporary_quota_initialized_; | 459 bool temporary_quota_initialized_; |
| 444 int64 temporary_quota_override_; | 460 int64 temporary_quota_override_; |
| 445 | 461 |
| 446 int64 desired_available_space_; | 462 int64 desired_available_space_; |
| 447 | 463 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 468 | 484 |
| 469 struct QuotaManagerDeleter { | 485 struct QuotaManagerDeleter { |
| 470 static void Destruct(const QuotaManager* manager) { | 486 static void Destruct(const QuotaManager* manager) { |
| 471 manager->DeleteOnCorrectThread(); | 487 manager->DeleteOnCorrectThread(); |
| 472 } | 488 } |
| 473 }; | 489 }; |
| 474 | 490 |
| 475 } // namespace storage | 491 } // namespace storage |
| 476 | 492 |
| 477 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 493 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
| OLD | NEW |