| Index: storage/browser/quota/quota_manager.cc
|
| diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc
|
| index 4d9db1285146a1029149387840419a679f3dd27b..8a9955ef1a08a4f711f3712312489b688719d2a6 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(
|
| @@ -814,7 +855,9 @@ QuotaManager::QuotaManager(
|
| get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace),
|
| storage_monitor_(new StorageMonitor(this)),
|
| is_getting_eviction_origin_(false),
|
| - weak_factory_(this) {}
|
| + weak_factory_(this) {
|
| + eviction_policy_map_.resize(kStorageTypeLast + 1);
|
| +}
|
|
|
| void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
|
| LazyInitialize();
|
| @@ -928,7 +971,7 @@ void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id,
|
| void QuotaManager::SetQuotaEvictionPolicy(
|
| StorageType type,
|
| scoped_ptr<QuotaEvictionPolicy> policy) {
|
| - eviction_policy_map_.set(type, policy.Pass());
|
| + eviction_policy_map_[type] = policy.release();
|
| }
|
|
|
| void QuotaManager::DeleteOriginData(
|
| @@ -1294,8 +1337,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);
|
| }
|
|
|
| @@ -1483,20 +1526,17 @@ void QuotaManager::GetEvictionOrigin(StorageType type,
|
| DCHECK(!is_getting_eviction_origin_);
|
| is_getting_eviction_origin_ = true;
|
|
|
| - GetOriginCallback did_get_origin_callback =
|
| - base::Bind(&QuotaManager::DidGetEvictionOrigin,
|
| - weak_factory_.GetWeakPtr(), callback);
|
| + QuotaEvictionPolicy* policy = eviction_policy_map_[type];
|
|
|
| - 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);
|
| - return;
|
| + if (!policy) {
|
| + policy = new LRUOriginEvictionPolicy(this, type);
|
| + eviction_policy_map_[type] = policy;
|
| }
|
|
|
| - // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy.
|
| - GetLRUOrigin(type, did_get_origin_callback);
|
| + policy->GetEvictionOrigin(
|
| + special_storage_policy_, GetEvictionOriginExceptions(),
|
| + base::Bind(&QuotaManager::DidGetEvictionOrigin,
|
| + weak_factory_.GetWeakPtr(), callback));
|
| }
|
|
|
| void QuotaManager::EvictOriginData(const GURL& origin,
|
| @@ -1528,27 +1568,6 @@ void QuotaManager::GetUsageAndQuotaForEviction(
|
| dispatcher->WaitForResults(callback);
|
| }
|
|
|
| -void QuotaManager::GetLRUOrigin(StorageType type,
|
| - 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,
|
| @@ -1600,14 +1619,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_)
|
|
|