Chromium Code Reviews| 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> |
| 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 Loading... | |
| 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 virtual ~QuotaEvictionPolicy() {} | |
| 81 | |
| 77 // Returns the next origin to evict. It might return an empty GURL when there | 82 // Returns the next origin to evict. It might return an empty GURL when there |
| 78 // are no evictable origins. | 83 // are no evictable origins. |
| 79 virtual void GetEvictionOrigin( | 84 virtual void GetEvictionOrigin( |
| 80 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, | 85 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, |
| 81 const std::map<GURL, int64>& usage_map, | |
| 82 int64 global_quota, | |
| 83 const GetOriginCallback& callback) = 0; | 86 const GetOriginCallback& callback) = 0; |
| 84 }; | 87 }; |
| 85 | 88 |
| 86 // An interface called by QuotaTemporaryStorageEvictor. | 89 // An interface called by QuotaTemporaryStorageEvictor. |
| 87 class STORAGE_EXPORT QuotaEvictionHandler { | 90 class STORAGE_EXPORT QuotaEvictionHandler { |
| 88 public: | 91 public: |
| 89 typedef StatusCallback EvictOriginDataCallback; | 92 typedef StatusCallback EvictOriginDataCallback; |
| 90 typedef base::Callback<void(QuotaStatusCode status, | 93 typedef base::Callback<void(QuotaStatusCode status, |
| 91 const UsageAndQuota& usage_and_quota)> | 94 const UsageAndQuota& usage_and_quota)> |
| 92 UsageAndQuotaCallback; | 95 UsageAndQuotaCallback; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 void NotifyOriginNoLongerInUse(const GURL& origin); | 190 void NotifyOriginNoLongerInUse(const GURL& origin); |
| 188 bool IsOriginInUse(const GURL& origin) const { | 191 bool IsOriginInUse(const GURL& origin) const { |
| 189 return origins_in_use_.find(origin) != origins_in_use_.end(); | 192 return origins_in_use_.find(origin) != origins_in_use_.end(); |
| 190 } | 193 } |
| 191 | 194 |
| 192 void SetUsageCacheEnabled(QuotaClient::ID client_id, | 195 void SetUsageCacheEnabled(QuotaClient::ID client_id, |
| 193 const GURL& origin, | 196 const GURL& origin, |
| 194 StorageType type, | 197 StorageType type, |
| 195 bool enabled); | 198 bool enabled); |
| 196 | 199 |
| 200 // Set the eviction policy to use when choosing an origin to evict. | |
| 201 void SetQuotaEvictionPolicy(StorageType type, | |
| 202 scoped_ptr<QuotaEvictionPolicy> policy); | |
| 203 | |
| 197 // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a | 204 // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a |
| 198 // particular StorageType associated with either a specific origin or set of | 205 // particular StorageType associated with either a specific origin or set of |
| 199 // origins. Each method additionally requires a |quota_client_mask| which | 206 // origins. Each method additionally requires a |quota_client_mask| which |
| 200 // specifies the types of QuotaClients to delete from the origin. This is | 207 // 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 | 208 // specified by the caller as a bitmask built from QuotaClient::IDs. Setting |
| 202 // the mask to QuotaClient::kAllClientsMask will remove all clients from the | 209 // the mask to QuotaClient::kAllClientsMask will remove all clients from the |
| 203 // origin, regardless of type. | 210 // origin, regardless of type. |
| 204 virtual void DeleteOriginData(const GURL& origin, | 211 virtual void DeleteOriginData(const GURL& origin, |
| 205 StorageType type, | 212 StorageType type, |
| 206 int quota_client_mask, | 213 int quota_client_mask, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 | 245 |
| 239 bool CanQueryDiskSize(const GURL& origin) const { | 246 bool CanQueryDiskSize(const GURL& origin) const { |
| 240 return special_storage_policy_.get() && | 247 return special_storage_policy_.get() && |
| 241 special_storage_policy_->CanQueryDiskSize(origin); | 248 special_storage_policy_->CanQueryDiskSize(origin); |
| 242 } | 249 } |
| 243 | 250 |
| 244 virtual void GetOriginsModifiedSince(StorageType type, | 251 virtual void GetOriginsModifiedSince(StorageType type, |
| 245 base::Time modified_since, | 252 base::Time modified_since, |
| 246 const GetOriginsCallback& callback); | 253 const GetOriginsCallback& callback); |
| 247 | 254 |
| 255 UsageTracker* GetUsageTracker(StorageType type) const; | |
|
raymes
2015/09/22 06:08:49
The storage people would be able to comment on whe
calamity
2015/09/23 01:46:24
I thought it would pollute the QuotaManager API le
| |
| 248 bool ResetUsageTracker(StorageType type); | 256 bool ResetUsageTracker(StorageType type); |
| 249 | 257 |
| 250 // Used to register/deregister observers that wish to monitor storage events. | 258 // Used to register/deregister observers that wish to monitor storage events. |
| 251 void AddStorageObserver(StorageObserver* observer, | 259 void AddStorageObserver(StorageObserver* observer, |
| 252 const StorageObserver::MonitorParams& params); | 260 const StorageObserver::MonitorParams& params); |
| 253 void RemoveStorageObserver(StorageObserver* observer); | 261 void RemoveStorageObserver(StorageObserver* observer); |
| 254 void RemoveStorageObserverForFilter(StorageObserver* observer, | 262 void RemoveStorageObserverForFilter(StorageObserver* observer, |
| 255 const StorageObserver::Filter& filter); | 263 const StorageObserver::Filter& filter); |
| 256 | 264 |
| 257 // Determines the portion of the temp pool that can be | 265 // Determines the portion of the temp pool that can be |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 279 friend class base::DeleteHelper<QuotaManager>; | 287 friend class base::DeleteHelper<QuotaManager>; |
| 280 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; | 288 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; |
| 281 friend class content::QuotaManagerTest; | 289 friend class content::QuotaManagerTest; |
| 282 friend class content::StorageMonitorTest; | 290 friend class content::StorageMonitorTest; |
| 283 friend class content::MockQuotaManager; | 291 friend class content::MockQuotaManager; |
| 284 friend class content::MockStorageClient; | 292 friend class content::MockStorageClient; |
| 285 friend class quota_internals::QuotaInternalsProxy; | 293 friend class quota_internals::QuotaInternalsProxy; |
| 286 friend class QuotaManagerProxy; | 294 friend class QuotaManagerProxy; |
| 287 friend class QuotaTemporaryStorageEvictor; | 295 friend class QuotaTemporaryStorageEvictor; |
| 288 friend struct QuotaManagerDeleter; | 296 friend struct QuotaManagerDeleter; |
| 297 friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest; | |
|
raymes
2015/09/22 06:08:49
nit: is the :: necessary, I think the forward decl
calamity
2015/09/23 01:46:24
Didn't seem to be.
C++, how does it work.
raymes
2015/09/23 01:56:14
Agreed!
| |
| 289 | 298 |
| 290 class GetUsageInfoTask; | 299 class GetUsageInfoTask; |
| 291 | 300 |
| 292 class OriginDataDeleter; | 301 class OriginDataDeleter; |
| 293 class HostDataDeleter; | 302 class HostDataDeleter; |
| 294 | 303 |
| 295 class GetModifiedSinceHelper; | 304 class GetModifiedSinceHelper; |
| 296 class DumpQuotaTableHelper; | 305 class DumpQuotaTableHelper; |
| 297 class DumpOriginInfoTableHelper; | 306 class DumpOriginInfoTableHelper; |
| 298 | 307 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 // when the first quota manager API is called. | 341 // when the first quota manager API is called. |
| 333 // Initialize must be called after all quota clients are added to the | 342 // Initialize must be called after all quota clients are added to the |
| 334 // manager by RegisterStorage. | 343 // manager by RegisterStorage. |
| 335 void LazyInitialize(); | 344 void LazyInitialize(); |
| 336 | 345 |
| 337 // Called by clients via proxy. | 346 // Called by clients via proxy. |
| 338 // Registers a quota client to the manager. | 347 // Registers a quota client to the manager. |
| 339 // The client must remain valid until OnQuotaManagerDestored is called. | 348 // The client must remain valid until OnQuotaManagerDestored is called. |
| 340 void RegisterClient(QuotaClient* client); | 349 void RegisterClient(QuotaClient* client); |
| 341 | 350 |
| 342 UsageTracker* GetUsageTracker(StorageType type) const; | |
| 343 | |
| 344 // Extract cached origins list from the usage tracker. | 351 // Extract cached origins list from the usage tracker. |
| 345 // (Might return empty list if no origin is tracked by the tracker.) | 352 // (Might return empty list if no origin is tracked by the tracker.) |
| 346 void GetCachedOrigins(StorageType type, std::set<GURL>* origins); | 353 void GetCachedOrigins(StorageType type, std::set<GURL>* origins); |
| 347 | 354 |
| 348 // These internal methods are separately defined mainly for testing. | 355 // These internal methods are separately defined mainly for testing. |
| 349 void NotifyStorageAccessedInternal( | 356 void NotifyStorageAccessedInternal( |
| 350 QuotaClient::ID client_id, | 357 QuotaClient::ID client_id, |
| 351 const GURL& origin, | 358 const GURL& origin, |
| 352 StorageType type, | 359 StorageType type, |
| 353 base::Time accessed_time); | 360 base::Time accessed_time); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 366 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); | 373 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); |
| 367 | 374 |
| 368 void DidOriginDataEvicted(QuotaStatusCode status); | 375 void DidOriginDataEvicted(QuotaStatusCode status); |
| 369 | 376 |
| 370 void ReportHistogram(); | 377 void ReportHistogram(); |
| 371 void DidGetTemporaryGlobalUsageForHistogram(int64 usage, | 378 void DidGetTemporaryGlobalUsageForHistogram(int64 usage, |
| 372 int64 unlimited_usage); | 379 int64 unlimited_usage); |
| 373 void DidGetPersistentGlobalUsageForHistogram(int64 usage, | 380 void DidGetPersistentGlobalUsageForHistogram(int64 usage, |
| 374 int64 unlimited_usage); | 381 int64 unlimited_usage); |
| 375 | 382 |
| 383 void DidGetEvictionOrigin(const GetOriginCallback& callback, | |
| 384 const GURL& origin); | |
| 385 | |
| 376 // QuotaEvictionHandler. | 386 // QuotaEvictionHandler. |
| 377 void GetEvictionOrigin(StorageType type, | 387 void GetEvictionOrigin(StorageType type, |
| 378 const GetOriginCallback& callback) override; | 388 const GetOriginCallback& callback) override; |
| 379 void EvictOriginData(const GURL& origin, | 389 void EvictOriginData(const GURL& origin, |
| 380 StorageType type, | 390 StorageType type, |
| 381 const EvictOriginDataCallback& callback) override; | 391 const EvictOriginDataCallback& callback) override; |
| 382 void GetUsageAndQuotaForEviction( | 392 void GetUsageAndQuotaForEviction( |
| 383 const UsageAndQuotaCallback& callback) override; | 393 const UsageAndQuotaCallback& callback) override; |
| 384 | 394 |
| 385 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); | 395 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 | 464 |
| 455 base::RepeatingTimer<QuotaManager> histogram_timer_; | 465 base::RepeatingTimer<QuotaManager> histogram_timer_; |
| 456 | 466 |
| 457 // Pointer to the function used to get the available disk space. This is | 467 // Pointer to the function used to get the available disk space. This is |
| 458 // overwritten by QuotaManagerTest in order to attain a deterministic reported | 468 // overwritten by QuotaManagerTest in order to attain a deterministic reported |
| 459 // value. The default value points to base::SysInfo::AmountOfFreeDiskSpace. | 469 // value. The default value points to base::SysInfo::AmountOfFreeDiskSpace. |
| 460 GetAvailableDiskSpaceFn get_disk_space_fn_; | 470 GetAvailableDiskSpaceFn get_disk_space_fn_; |
| 461 | 471 |
| 462 scoped_ptr<StorageMonitor> storage_monitor_; | 472 scoped_ptr<StorageMonitor> storage_monitor_; |
| 463 | 473 |
| 474 base::ScopedPtrMap<StorageType, scoped_ptr<QuotaEvictionPolicy>> | |
| 475 eviction_policy_map_; | |
| 476 | |
| 477 bool is_getting_eviction_origin_; | |
| 478 | |
| 464 base::WeakPtrFactory<QuotaManager> weak_factory_; | 479 base::WeakPtrFactory<QuotaManager> weak_factory_; |
| 465 | 480 |
| 466 DISALLOW_COPY_AND_ASSIGN(QuotaManager); | 481 DISALLOW_COPY_AND_ASSIGN(QuotaManager); |
| 467 }; | 482 }; |
| 468 | 483 |
| 469 struct QuotaManagerDeleter { | 484 struct QuotaManagerDeleter { |
| 470 static void Destruct(const QuotaManager* manager) { | 485 static void Destruct(const QuotaManager* manager) { |
| 471 manager->DeleteOnCorrectThread(); | 486 manager->DeleteOnCorrectThread(); |
| 472 } | 487 } |
| 473 }; | 488 }; |
| 474 | 489 |
| 475 } // namespace storage | 490 } // namespace storage |
| 476 | 491 |
| 477 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 492 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
| OLD | NEW |