Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Unified Diff: storage/browser/quota/quota_manager.cc

Issue 1321733004: Use the site engagement eviction policy for temporary storage eviction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add_eviction_policy
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « storage/browser/quota/quota_manager.h ('k') | storage/browser/quota/usage_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: storage/browser/quota/quota_manager.cc
diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc
index 52f728086b7169b02f5b62831cf50f7108b6c619..53568fa72c60c864850c160dd966b17b9ad03919 100644
--- a/storage/browser/quota/quota_manager.cc
+++ b/storage/browser/quota/quota_manager.cc
@@ -507,6 +507,7 @@ class QuotaManager::GetUsageInfoTask : public QuotaTask {
++iter) {
entries_.push_back(UsageInfo(iter->first, type, iter->second));
}
+
if (--remaining_trackers_ == 0)
CallCompleted();
}
@@ -528,6 +529,75 @@ class QuotaManager::GetUsageInfoTask : public QuotaTask {
DISALLOW_COPY_AND_ASSIGN(GetUsageInfoTask);
};
+class QuotaManager::GetTemporaryEvictionOriginTask : public QuotaTask {
+ public:
+ GetTemporaryEvictionOriginTask(
+ QuotaManager* manager,
+ scoped_refptr<SpecialStoragePolicy> special_storage_policy,
+ QuotaEvictionPolicy* eviction_policy,
+ const GetOriginCallback& callback)
+ : QuotaTask(manager),
+ special_storage_policy_(special_storage_policy),
+ eviction_policy_(eviction_policy),
+ callback_(callback),
+ weak_factory_(this) {}
+
+ protected:
+ void Run() override {
+ remaining_tasks_ = 2;
+ // This will populate cached hosts and usage info.
+ manager()
+ ->GetUsageTracker(kStorageTypeTemporary)
+ ->GetGlobalUsage(
+ base::Bind(&GetTemporaryEvictionOriginTask::DidGetGlobalUsage,
+ weak_factory_.GetWeakPtr(), kStorageTypeTemporary));
+ manager()->GetTemporaryGlobalQuota(
+ base::Bind(&GetTemporaryEvictionOriginTask::DidGetTemporaryGlobalQuota,
+ weak_factory_.GetWeakPtr()));
+ }
+
+ void Completed() override {
+ eviction_policy_->GetEvictionOrigin(special_storage_policy_.get(),
+ usage_map_, global_quota_, callback_);
+ DeleteSoon();
+ }
+
+ void Aborted() override {
+ callback_.Run(GURL());
+ DeleteSoon();
+ }
+
+ private:
+ void DidGetGlobalUsage(StorageType type, int64, int64) {
+ DCHECK(manager()->GetUsageTracker(type));
+ manager()->GetUsageTracker(type)->GetCachedOriginsUsage(&usage_map_);
+ if (--remaining_tasks_ == 0)
+ CallCompleted();
+ }
+
+ void DidGetTemporaryGlobalQuota(QuotaStatusCode status, int64 quota) {
+ if (status == kQuotaStatusOk)
+ global_quota_ = quota;
+
+ if (--remaining_tasks_ == 0)
+ CallCompleted();
+ }
+
+ QuotaManager* manager() const {
+ return static_cast<QuotaManager*>(observer());
+ }
+
+ int64 global_quota_;
+ scoped_refptr<SpecialStoragePolicy> special_storage_policy_;
+ QuotaEvictionPolicy* eviction_policy_;
+ GetOriginCallback callback_;
+ std::map<GURL, int64> usage_map_;
+ int remaining_tasks_;
+ base::WeakPtrFactory<GetTemporaryEvictionOriginTask> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(GetTemporaryEvictionOriginTask);
+};
+
class QuotaManager::OriginDataDeleter : public QuotaTask {
public:
OriginDataDeleter(QuotaManager* manager,
@@ -799,7 +869,8 @@ QuotaManager::QuotaManager(
const base::FilePath& profile_path,
const scoped_refptr<base::SingleThreadTaskRunner>& io_thread,
const scoped_refptr<base::SequencedTaskRunner>& db_thread,
- const scoped_refptr<SpecialStoragePolicy>& special_storage_policy)
+ const scoped_refptr<SpecialStoragePolicy>& special_storage_policy,
+ QuotaEvictionPolicy* temporary_storage_eviction_policy)
: is_incognito_(is_incognito),
profile_path_(profile_path),
proxy_(new QuotaManagerProxy(this, io_thread)),
@@ -807,14 +878,14 @@ QuotaManager::QuotaManager(
eviction_disabled_(false),
io_thread_(io_thread),
db_thread_(db_thread),
+ temporary_storage_eviction_policy_(temporary_storage_eviction_policy),
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();
@@ -1442,6 +1513,15 @@ void QuotaManager::DidGetPersistentGlobalUsageForHistogram(
void QuotaManager::GetEvictionOrigin(StorageType type,
const GetOriginCallback& callback) {
+ LazyInitialize();
+ if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) {
+ GetTemporaryEvictionOriginTask* task = new GetTemporaryEvictionOriginTask(
+ this, special_storage_policy_, temporary_storage_eviction_policy_,
+ callback);
+ task->Start();
+ return;
+ }
+
GetLRUOrigin(type, callback);
}
« no previous file with comments | « storage/browser/quota/quota_manager.h ('k') | storage/browser/quota/usage_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698