Chromium Code Reviews| Index: storage/browser/quota/quota_manager.cc |
| diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc |
| index 072f77acfffc49e4f36b36a23e756bc6853f8435..4b386dad0c5641dab3d56c0df69f672f0268d601 100644 |
| --- a/storage/browser/quota/quota_manager.cc |
| +++ b/storage/browser/quota/quota_manager.cc |
| @@ -792,6 +792,47 @@ class QuotaManager::DumpOriginInfoTableHelper { |
| OriginInfoTableEntries entries_; |
| }; |
| +class QuotaManager::LRUOriginEvictionPolicy : public QuotaEvictionPolicy { |
| + public: |
| + LRUOriginEvictionPolicy(QuotaManager* manager, StorageType type) |
| + : manager_(manager), type_(type), weak_factory_(this) {} |
| + |
| + ~LRUOriginEvictionPolicy() override {} |
| + |
| + // Overridden from storage::QuotaEvictionPolicy: |
| + void GetEvictionOrigin(const scoped_refptr<storage::SpecialStoragePolicy>& |
| + special_storage_policy, |
| + const std::set<GURL>& exceptions, |
| + const storage::GetOriginCallback& callback) override { |
| + if (manager_->db_disabled_) { |
| + callback.Run(GURL()); |
| + return; |
| + } |
| + |
| + GURL* url = new GURL; |
| + manager_->PostTaskAndReplyWithResultForDBThread( |
| + FROM_HERE, |
| + base::Bind(&GetLRUOriginOnDBThread, type_, exceptions, |
| + manager_->special_storage_policy_, base::Unretained(url)), |
| + base::Bind(&LRUOriginEvictionPolicy::DidGetLRUOrigin, |
| + weak_factory_.GetWeakPtr(), callback, base::Owned(url))); |
| + } |
| + |
| + void DidGetLRUOrigin(const storage::GetOriginCallback& callback, |
| + const GURL* origin, |
| + bool success) { |
| + manager_->DidDatabaseWork(success); |
| + callback.Run(*origin); |
| + } |
| + |
| + private: |
| + QuotaManager* manager_; |
| + StorageType type_; |
| + base::WeakPtrFactory<LRUOriginEvictionPolicy> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(LRUOriginEvictionPolicy); |
| +}; |
| + |
| // QuotaManager --------------------------------------------------------------- |
| QuotaManager::QuotaManager( |
| @@ -1294,8 +1335,8 @@ void QuotaManager::NotifyStorageAccessedInternal( |
| base::Time accessed_time) { |
| LazyInitialize(); |
| if (type == kStorageTypeTemporary && is_getting_eviction_origin_) { |
| - // Record the accessed origins while GetLRUOrigin task is runing |
| - // to filter out them from eviction. |
| + // Record the accessed origins while an eviction origin task is running |
| + // to filter them from eviction. |
| access_notified_origins_.insert(origin); |
| } |
| @@ -1446,26 +1487,6 @@ void QuotaManager::DidGetPersistentGlobalUsageForHistogram( |
| unlimited_origins); |
| } |
| -void QuotaManager::GetEvictionOrigin(StorageType type, |
| - const GetOriginCallback& callback) { |
| - LazyInitialize(); |
| - is_getting_eviction_origin_ = true; |
| - |
| - GetOriginCallback did_get_origin_callback = |
| - base::Bind(&QuotaManager::DidGetEvictionOrigin, |
| - weak_factory_.GetWeakPtr(), callback); |
| - |
| - auto eviction_policy = eviction_policy_map_.find(type); |
| - if (eviction_policy != eviction_policy_map_.end()) { |
| - eviction_policy->second->GetEvictionOrigin(special_storage_policy_, |
| - GetEvictionOriginExceptions(), |
| - did_get_origin_callback); |
| - } |
| - |
| - // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy. |
| - GetLRUOrigin(type, did_get_origin_callback); |
| -} |
| - |
| std::set<GURL> QuotaManager::GetEvictionOriginExceptions() { |
| std::set<GURL> exceptions; |
| for (const auto& p : origins_in_use_) { |
| @@ -1481,6 +1502,22 @@ std::set<GURL> QuotaManager::GetEvictionOriginExceptions() { |
| return exceptions; |
| } |
| +void QuotaManager::GetEvictionOrigin(StorageType type, |
| + const GetOriginCallback& callback) { |
| + LazyInitialize(); |
| + is_getting_eviction_origin_ = true; |
| + |
| + if (eviction_policy_map_.find(type) == eviction_policy_map_.end()) { |
| + eviction_policy_map_.set( |
| + type, make_scoped_ptr(new LRUOriginEvictionPolicy(this, type))); |
|
raymes
2015/09/22 06:58:58
How about setting the LRU policy to the default po
calamity
2015/09/24 06:50:31
There are several storage types and I believe only
|
| + } |
| + |
| + eviction_policy_map_.find(type)->second->GetEvictionOrigin( |
|
raymes
2015/09/22 06:58:58
We can avoid the additional map lookup here
calamity
2015/09/24 06:50:31
Done.
|
| + special_storage_policy_, GetEvictionOriginExceptions(), |
| + base::Bind(&QuotaManager::DidGetEvictionOrigin, |
| + weak_factory_.GetWeakPtr(), callback)); |
| +} |
| + |
| void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback, |
| const GURL& origin) { |
| // Make sure the returned origin is (still) not in the origin_in_use_ set |
| @@ -1525,27 +1562,6 @@ void QuotaManager::GetUsageAndQuotaForEviction( |
| dispatcher->WaitForResults(callback); |
| } |
| -void QuotaManager::GetLRUOrigin(StorageType type, |
|
raymes
2015/09/22 06:58:58
nit: This function still exists in the header
calamity
2015/09/24 06:50:31
Done.
|
| - const GetOriginCallback& callback) { |
| - LazyInitialize(); |
| - // This must not be called while there's an in-flight task. |
| - DCHECK(lru_origin_callback_.is_null()); |
| - lru_origin_callback_ = callback; |
| - if (db_disabled_) { |
| - lru_origin_callback_.Run(GURL()); |
| - lru_origin_callback_.Reset(); |
| - return; |
| - } |
| - |
| - GURL* url = new GURL; |
| - PostTaskAndReplyWithResultForDBThread( |
| - FROM_HERE, |
| - base::Bind(&GetLRUOriginOnDBThread, type, GetEvictionOriginExceptions(), |
| - special_storage_policy_, base::Unretained(url)), |
| - base::Bind(&QuotaManager::DidGetLRUOrigin, weak_factory_.GetWeakPtr(), |
| - base::Owned(url))); |
| -} |
| - |
| void QuotaManager::DidSetTemporaryGlobalOverrideQuota( |
| const QuotaCallback& callback, |
| const int64* new_quota, |
| @@ -1597,14 +1613,6 @@ void QuotaManager::DidInitialize(int64* temporary_quota_override, |
| weak_factory_.GetWeakPtr())); |
| } |
| -void QuotaManager::DidGetLRUOrigin(const GURL* origin, |
| - bool success) { |
| - DidDatabaseWork(success); |
| - |
| - lru_origin_callback_.Run(*origin); |
| - lru_origin_callback_.Reset(); |
| -} |
| - |
| void QuotaManager::DidGetInitialTemporaryGlobalQuota( |
| QuotaStatusCode status, int64 quota_unused) { |
| if (eviction_disabled_) |