diff options
Diffstat (limited to 'storage')
-rw-r--r-- | storage/browser/quota/client_usage_tracker.cc | 9 | ||||
-rw-r--r-- | storage/browser/quota/client_usage_tracker.h | 3 | ||||
-rw-r--r-- | storage/browser/quota/quota_manager.cc | 44 | ||||
-rw-r--r-- | storage/browser/quota/quota_manager.h | 20 | ||||
-rw-r--r-- | storage/browser/quota/quota_temporary_storage_evictor.cc | 2 | ||||
-rw-r--r-- | storage/browser/quota/usage_tracker.cc | 8 | ||||
-rw-r--r-- | storage/browser/quota/usage_tracker.h | 1 |
7 files changed, 78 insertions, 9 deletions
diff --git a/storage/browser/quota/client_usage_tracker.cc b/storage/browser/quota/client_usage_tracker.cc index 968b351..0b11bd1 100644 --- a/storage/browser/quota/client_usage_tracker.cc +++ b/storage/browser/quota/client_usage_tracker.cc @@ -173,6 +173,15 @@ void ClientUsageTracker::GetCachedHostsUsage( } } +void ClientUsageTracker::GetCachedOriginsUsage( + std::map<GURL, int64>* origin_usage) const { + DCHECK(origin_usage); + for (const auto& host_and_usage_map : cached_usage_by_host_) { + for (const auto& origin_and_usage : host_and_usage_map.second) + (*origin_usage)[origin_and_usage.first] += origin_and_usage.second; + } +} + void ClientUsageTracker::GetCachedOrigins(std::set<GURL>* origins) const { DCHECK(origins); for (const auto& host_and_usage_map : cached_usage_by_host_) { diff --git a/storage/browser/quota/client_usage_tracker.h b/storage/browser/quota/client_usage_tracker.h index 1c07dc8..0505fae 100644 --- a/storage/browser/quota/client_usage_tracker.h +++ b/storage/browser/quota/client_usage_tracker.h @@ -51,9 +51,8 @@ class ClientUsageTracker : public SpecialStoragePolicy::Observer, void GetHostUsage(const std::string& host, const UsageCallback& callback); void UpdateUsageCache(const GURL& origin, int64 delta); void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; + void GetCachedOriginsUsage(std::map<GURL, int64>* origin_usage) const; void GetCachedOrigins(std::set<GURL>* origins) const; - int64 GetCachedOriginsUsage(const std::set<GURL>& origins, - std::vector<GURL>* origins_not_in_cache); bool IsUsageCacheEnabledForOrigin(const GURL& origin) const; void SetUsageCacheEnabled(const GURL& origin, bool enabled); diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc index 674b1ec..c2ccb26 100644 --- a/storage/browser/quota/quota_manager.cc +++ b/storage/browser/quota/quota_manager.cc @@ -836,14 +836,14 @@ QuotaManager::QuotaManager( eviction_disabled_(false), io_thread_(io_thread), db_thread_(db_thread), + is_getting_eviction_origin_(false), temporary_quota_initialized_(false), temporary_quota_override_(-1), desired_available_space_(-1), special_storage_policy_(special_storage_policy), get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace), storage_monitor_(new StorageMonitor(this)), - weak_factory_(this) { -} + weak_factory_(this) {} void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { LazyInitialize(); @@ -954,6 +954,11 @@ void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id, GetUsageTracker(type)->SetUsageCacheEnabled(client_id, origin, enabled); } +void QuotaManager::SetTemporaryStorageEvictionPolicy( + scoped_ptr<QuotaEvictionPolicy> policy) { + temporary_storage_eviction_policy_ = policy.Pass(); +} + void QuotaManager::DeleteOriginData( const GURL& origin, StorageType type, int quota_client_mask, const StatusCallback& callback) { @@ -1318,7 +1323,7 @@ void QuotaManager::NotifyStorageAccessedInternal( const GURL& origin, StorageType type, base::Time accessed_time) { LazyInitialize(); - if (type == kStorageTypeTemporary && !lru_origin_callback_.is_null()) { + if (type == kStorageTypeTemporary && is_getting_eviction_origin_) { // Record the accessed origins while GetLRUOrigin task is runing // to filter out them from eviction. access_notified_origins_.insert(origin); @@ -1472,8 +1477,38 @@ void QuotaManager::DidGetPersistentGlobalUsageForHistogram( } void QuotaManager::GetEvictionOrigin(StorageType type, + int64 global_quota, const GetOriginCallback& callback) { - GetLRUOrigin(type, callback); + LazyInitialize(); + // This must not be called while there's an in-flight task. + DCHECK(!is_getting_eviction_origin_); + is_getting_eviction_origin_ = true; + + GetOriginCallback did_get_origin_callback = + base::Bind(&QuotaManager::DidGetEvictionOrigin, + weak_factory_.GetWeakPtr(), callback); + + if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) { + std::map<GURL, int64> usage_map; + // The cached origins are populated by the prior call to + // GetUsageAndQuotaForEviction(). + GetUsageTracker(kStorageTypeTemporary)->GetCachedOriginsUsage(&usage_map); + + temporary_storage_eviction_policy_->GetEvictionOrigin( + special_storage_policy_, usage_map, global_quota, + did_get_origin_callback); + return; + } + + // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy. + GetLRUOrigin(type, did_get_origin_callback); +} + +void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback, + const GURL& origin) { + callback.Run(origin); + + is_getting_eviction_origin_ = false; } void QuotaManager::EvictOriginData(const GURL& origin, @@ -1520,6 +1555,7 @@ void QuotaManager::GetLRUOrigin(StorageType type, return; } + // TODO(calamity): make all QuotaEvictionPolicies aware of these exceptions. std::set<GURL>* exceptions = new std::set<GURL>; for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin(); p != origins_in_use_.end(); diff --git a/storage/browser/quota/quota_manager.h b/storage/browser/quota/quota_manager.h index 3e05388..0e4884b 100644 --- a/storage/browser/quota/quota_manager.h +++ b/storage/browser/quota/quota_manager.h @@ -28,6 +28,8 @@ #include "storage/browser/quota/storage_observer.h" #include "storage/browser/storage_browser_export.h" +class SiteEngagementEvictionPolicyWithQuotaManagerTest; + namespace base { class FilePath; class SequencedTaskRunner; @@ -70,10 +72,12 @@ struct STORAGE_EXPORT UsageAndQuota { }; // TODO(calamity): Use this in the temporary storage eviction path. -// An interface for deciding which origin's temporary storage should be evicted -// when the quota is exceeded. +// An interface for deciding which origin's storage should be evicted when the +// quota is exceeded. class STORAGE_EXPORT QuotaEvictionPolicy { public: + virtual ~QuotaEvictionPolicy() {} + // Returns the next origin to evict. It might return an empty GURL when there // are no evictable origins. virtual void GetEvictionOrigin( @@ -94,6 +98,7 @@ class STORAGE_EXPORT QuotaEvictionHandler { // Returns next origin to evict. It might return an empty GURL when there are // no evictable origins. virtual void GetEvictionOrigin(StorageType type, + int64 global_quota, const GetOriginCallback& callback) = 0; virtual void EvictOriginData( @@ -194,6 +199,10 @@ class STORAGE_EXPORT QuotaManager StorageType type, bool enabled); + // Set the eviction policy to use when choosing an origin to evict. + void SetTemporaryStorageEvictionPolicy( + scoped_ptr<QuotaEvictionPolicy> policy); + // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a // particular StorageType associated with either a specific origin or set of // origins. Each method additionally requires a |quota_client_mask| which @@ -286,6 +295,7 @@ class STORAGE_EXPORT QuotaManager friend class QuotaManagerProxy; friend class QuotaTemporaryStorageEvictor; friend struct QuotaManagerDeleter; + friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest; class GetUsageInfoTask; @@ -373,8 +383,12 @@ class STORAGE_EXPORT QuotaManager void DidGetPersistentGlobalUsageForHistogram(int64 usage, int64 unlimited_usage); + void DidGetEvictionOrigin(const GetOriginCallback& callback, + const GURL& origin); + // QuotaEvictionHandler. void GetEvictionOrigin(StorageType type, + int64 global_quota, const GetOriginCallback& callback) override; void EvictOriginData(const GURL& origin, StorageType type, @@ -435,6 +449,8 @@ class STORAGE_EXPORT QuotaManager scoped_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; EvictionContext eviction_context_; + scoped_ptr<QuotaEvictionPolicy> temporary_storage_eviction_policy_; + bool is_getting_eviction_origin_; ClosureQueue db_initialization_callbacks_; AvailableSpaceCallbackQueue available_space_callbacks_; diff --git a/storage/browser/quota/quota_temporary_storage_evictor.cc b/storage/browser/quota/quota_temporary_storage_evictor.cc index adcff0d..30f17b8 100644 --- a/storage/browser/quota/quota_temporary_storage_evictor.cc +++ b/storage/browser/quota/quota_temporary_storage_evictor.cc @@ -196,7 +196,7 @@ void QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction( // TODO(michaeln): if the reason for eviction is low physical disk space, // make 'unlimited' origins subject to eviction too. quota_eviction_handler_->GetEvictionOrigin( - kStorageTypeTemporary, + kStorageTypeTemporary, qau.quota, base::Bind(&QuotaTemporaryStorageEvictor::OnGotEvictionOrigin, weak_factory_.GetWeakPtr())); } else { diff --git a/storage/browser/quota/usage_tracker.cc b/storage/browser/quota/usage_tracker.cc index 528725d..de9fbeb 100644 --- a/storage/browser/quota/usage_tracker.cc +++ b/storage/browser/quota/usage_tracker.cc @@ -144,6 +144,14 @@ void UsageTracker::GetCachedHostsUsage( client_id_and_tracker.second->GetCachedHostsUsage(host_usage); } +void UsageTracker::GetCachedOriginsUsage( + std::map<GURL, int64>* origin_usage) const { + DCHECK(origin_usage); + origin_usage->clear(); + for (const auto& client_id_and_tracker : client_tracker_map_) + client_id_and_tracker.second->GetCachedOriginsUsage(origin_usage); +} + void UsageTracker::GetCachedOrigins(std::set<GURL>* origins) const { DCHECK(origins); origins->clear(); diff --git a/storage/browser/quota/usage_tracker.h b/storage/browser/quota/usage_tracker.h index 224faf8..ed54fcc 100644 --- a/storage/browser/quota/usage_tracker.h +++ b/storage/browser/quota/usage_tracker.h @@ -45,6 +45,7 @@ class STORAGE_EXPORT UsageTracker : public QuotaTaskObserver { void UpdateUsageCache(QuotaClient::ID client_id, const GURL& origin, int64 delta); + void GetCachedOriginsUsage(std::map<GURL, int64>* origin_usage) const; void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; void GetCachedOrigins(std::set<GURL>* origins) const; bool IsWorking() const { |