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

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

Issue 1343273003: Integrate SiteEngagementEvictionPolicy with QuotaManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add_eviction_policy
Patch Set: export 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
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..6ae97ffaafe9e7f3dbabea1efa0c13d85135e4b4 100644
--- a/storage/browser/quota/quota_manager.cc
+++ b/storage/browser/quota/quota_manager.cc
@@ -317,6 +317,17 @@ UsageAndQuota::UsageAndQuota(
available_disk_space(available_disk_space) {
}
+QuotaEvictionPolicy::Info::Info() {}
+QuotaEvictionPolicy::Info::~Info() {}
+
+bool QuotaEvictionPolicy::NeedsOriginUsageMap() {
+ return false;
+}
+
+bool QuotaEvictionPolicy::NeedsGlobalQuota() {
+ return false;
+}
+
class UsageAndQuotaCallbackDispatcher
: public QuotaTask,
public base::SupportsWeakPtr<UsageAndQuotaCallbackDispatcher> {
@@ -528,6 +539,87 @@ class QuotaManager::GetUsageInfoTask : public QuotaTask {
DISALLOW_COPY_AND_ASSIGN(GetUsageInfoTask);
};
+class QuotaManager::GetEvictionOriginTask : public QuotaTask {
michaeln 2015/10/06 00:35:09 This task may not bee needed? At the start of an
calamity 2015/10/07 02:42:46 Ah ok, cool. Deleted this.
+ public:
+ GetEvictionOriginTask(
+ QuotaManager* manager,
+ scoped_refptr<SpecialStoragePolicy> special_storage_policy,
+ QuotaEvictionPolicy* eviction_policy,
+ const GetOriginCallback& callback)
+ : QuotaTask(manager),
+ eviction_info_(new QuotaEvictionPolicy::Info()),
+ special_storage_policy_(special_storage_policy),
+ eviction_policy_(eviction_policy),
+ callback_(callback),
+ remaining_tasks_(0),
+ weak_factory_(this) {}
+
+ protected:
+ void Run() override {
+ if (eviction_policy_->NeedsOriginUsageMap()) {
+ // This will populate cached hosts and usage info.
+ manager()
+ ->GetUsageTracker(kStorageTypeTemporary)
+ ->GetGlobalUsage(base::Bind(&GetEvictionOriginTask::DidGetGlobalUsage,
michaeln 2015/10/06 00:35:09 The base::BarrierClosure (barrier_closure.h) class
calamity 2015/10/07 02:42:46 Acknowledged.
+ weak_factory_.GetWeakPtr(),
+ kStorageTypeTemporary));
+ ++remaining_tasks_;
+ }
+
+ if (eviction_policy_->NeedsGlobalQuota()) {
+ manager()->GetTemporaryGlobalQuota(
+ base::Bind(&GetEvictionOriginTask::DidGetTemporaryGlobalQuota,
+ weak_factory_.GetWeakPtr()));
+ ++remaining_tasks_;
+ }
+
+ if (remaining_tasks_ == 0)
+ CallCompleted();
+ }
+
+ void Completed() override {
+ eviction_policy_->GetEvictionOrigin(
+ eviction_info_.Pass(), special_storage_policy_.get(), callback_);
+ DeleteSoon();
+ }
+
+ void Aborted() override {
+ callback_.Run(GURL());
+ DeleteSoon();
+ }
+
+ private:
+ void DidGetGlobalUsage(StorageType type, int64, int64) {
+ DCHECK(manager()->GetUsageTracker(type));
+ manager()->GetUsageTracker(type)->GetCachedOriginsUsage(
+ &eviction_info_->origin_usage_map);
+
+ if (--remaining_tasks_ == 0)
+ CallCompleted();
+ }
+
+ void DidGetTemporaryGlobalQuota(QuotaStatusCode status, int64 quota) {
+ if (status == kQuotaStatusOk)
+ eviction_info_->global_quota = quota;
+
+ if (--remaining_tasks_ == 0)
+ CallCompleted();
+ }
+
+ QuotaManager* manager() const {
+ return static_cast<QuotaManager*>(observer());
+ }
+
+ scoped_ptr<QuotaEvictionPolicy::Info> eviction_info_;
+ scoped_refptr<SpecialStoragePolicy> special_storage_policy_;
+ QuotaEvictionPolicy* eviction_policy_;
+ GetOriginCallback callback_;
+ int remaining_tasks_;
+ base::WeakPtrFactory<GetEvictionOriginTask> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(GetEvictionOriginTask);
+};
+
class QuotaManager::OriginDataDeleter : public QuotaTask {
public:
OriginDataDeleter(QuotaManager* manager,
@@ -813,8 +905,8 @@ QuotaManager::QuotaManager(
special_storage_policy_(special_storage_policy),
get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace),
storage_monitor_(new StorageMonitor(this)),
- weak_factory_(this) {
-}
+ is_getting_eviction_origin_(false),
+ weak_factory_(this) {}
void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
LazyInitialize();
@@ -925,6 +1017,12 @@ void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id,
GetUsageTracker(type)->SetUsageCacheEnabled(client_id, origin, enabled);
}
+void QuotaManager::SetQuotaEvictionPolicy(
+ StorageType type,
+ scoped_ptr<QuotaEvictionPolicy> policy) {
+ eviction_policy_map_.set(type, policy.Pass());
+}
+
void QuotaManager::DeleteOriginData(
const GURL& origin, StorageType type, int quota_client_mask,
const StatusCallback& callback) {
@@ -1287,7 +1385,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);
@@ -1442,7 +1540,33 @@ void QuotaManager::DidGetPersistentGlobalUsageForHistogram(
void QuotaManager::GetEvictionOrigin(StorageType type,
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);
+
+ auto eviction_policy = eviction_policy_map_.find(type);
+ if (eviction_policy != eviction_policy_map_.end()) {
+ GetEvictionOriginTask* task = new GetEvictionOriginTask(
+ this, special_storage_policy_, eviction_policy->second,
+ did_get_origin_callback);
+ task->Start();
+ 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,
@@ -1486,6 +1610,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();

Powered by Google App Engine
This is Rietveld 408576698