Chromium Code Reviews| Index: chrome/browser/engagement/site_engagement_eviction_policy.h |
| diff --git a/chrome/browser/engagement/site_engagement_eviction_policy.h b/chrome/browser/engagement/site_engagement_eviction_policy.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..673dd4aa926c6526e20886cbb29ec526a7d64f67 |
| --- /dev/null |
| +++ b/chrome/browser/engagement/site_engagement_eviction_policy.h |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_EVICTION_POLICY_H_ |
| +#define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_EVICTION_POLICY_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/macros.h" |
| +#include "chrome/browser/engagement/site_engagement_service_proxy.h" |
| +#include "storage/browser/quota/quota_manager.h" |
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} |
| + |
| +class SiteEngagementEvictionPolicy |
| + : public storage::TemporaryStorageEvictionPolicy { |
| + public: |
| + // A task that calculates the next origin to evict based on usage and site |
| + // engagement. |
| + class GetEvictionOriginTask { |
|
raymes
2015/07/15 07:55:47
This should be a private class, right?
calamity
2015/07/20 06:39:44
Hmm. I originally did have it as an anonymous clas
|
| + public: |
| + GetEvictionOriginTask( |
| + content::BrowserContext* browser_context, |
| + const std::map<GURL, int64>& usage_map, |
| + int64 global_quota, |
| + const storage::GetEvictionOriginCallback& result_callback); |
| + |
| + void Start(); |
| + |
| + private: |
| + void OnDidGetScoresForOrigin(const std::map<GURL, int>& score_map); |
| + void OnDidGetTotalEngagementPoints(int total_engagement_points); |
| + |
| + void CalculateEvictionOriginAndReply(); |
| + |
| + // Gets the quota that an origin deserves based on its site engagement. |
| + int64 GetSoftQuotaForOrigin(const GURL& origin); |
| + ~GetEvictionOriginTask(); |
| + |
| + std::map<GURL, int64> usage_map_; |
| + int64 global_quota_; |
| + |
| + std::map<GURL, int> score_map_; |
| + int total_engagement_points_; |
| + |
| + // The callback that each task runs as it completes. |
| + base::Closure per_task_callback_; |
| + |
| + // The callback to run with the next eviction origin. |
| + storage::GetEvictionOriginCallback result_callback_; |
| + |
| + SiteEngagementServiceProxy proxy_; |
| + }; |
| + |
| + explicit SiteEngagementEvictionPolicy( |
| + content::BrowserContext* browser_context); |
| + virtual ~SiteEngagementEvictionPolicy(); |
| + |
| + // Overridden from storage::TemporaryStorageEvictionPolicy: |
| + void GetEvictionOrigin( |
| + const std::map<GURL, int64>& usage_map, |
| + int64 global_quota, |
| + const storage::GetEvictionOriginCallback& callback) override; |
| + |
| + private: |
| + content::BrowserContext* browser_context_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SiteEngagementEvictionPolicy); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_EVICTION_POLICY_H_ |