Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_EVICTION_POLICY_H_ | |
| 6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_EVICTION_POLICY_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "chrome/browser/engagement/site_engagement_service_proxy.h" | |
| 12 #include "storage/browser/quota/quota_manager.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace content { | |
| 16 class BrowserContext; | |
| 17 } | |
| 18 | |
| 19 class SiteEngagementEvictionPolicy | |
| 20 : public storage::TemporaryStorageEvictionPolicy { | |
| 21 public: | |
| 22 // A task that calculates the next origin to evict based on usage and site | |
| 23 // engagement. | |
| 24 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
| |
| 25 public: | |
| 26 GetEvictionOriginTask( | |
| 27 content::BrowserContext* browser_context, | |
| 28 const std::map<GURL, int64>& usage_map, | |
| 29 int64 global_quota, | |
| 30 const storage::GetEvictionOriginCallback& result_callback); | |
| 31 | |
| 32 void Start(); | |
| 33 | |
| 34 private: | |
| 35 void OnDidGetScoresForOrigin(const std::map<GURL, int>& score_map); | |
| 36 void OnDidGetTotalEngagementPoints(int total_engagement_points); | |
| 37 | |
| 38 void CalculateEvictionOriginAndReply(); | |
| 39 | |
| 40 // Gets the quota that an origin deserves based on its site engagement. | |
| 41 int64 GetSoftQuotaForOrigin(const GURL& origin); | |
| 42 ~GetEvictionOriginTask(); | |
| 43 | |
| 44 std::map<GURL, int64> usage_map_; | |
| 45 int64 global_quota_; | |
| 46 | |
| 47 std::map<GURL, int> score_map_; | |
| 48 int total_engagement_points_; | |
| 49 | |
| 50 // The callback that each task runs as it completes. | |
| 51 base::Closure per_task_callback_; | |
| 52 | |
| 53 // The callback to run with the next eviction origin. | |
| 54 storage::GetEvictionOriginCallback result_callback_; | |
| 55 | |
| 56 SiteEngagementServiceProxy proxy_; | |
| 57 }; | |
| 58 | |
| 59 explicit SiteEngagementEvictionPolicy( | |
| 60 content::BrowserContext* browser_context); | |
| 61 virtual ~SiteEngagementEvictionPolicy(); | |
| 62 | |
| 63 // Overridden from storage::TemporaryStorageEvictionPolicy: | |
| 64 void GetEvictionOrigin( | |
| 65 const std::map<GURL, int64>& usage_map, | |
| 66 int64 global_quota, | |
| 67 const storage::GetEvictionOriginCallback& callback) override; | |
| 68 | |
| 69 private: | |
| 70 content::BrowserContext* browser_context_; | |
| 71 | |
| 72 DISALLOW_COPY_AND_ASSIGN(SiteEngagementEvictionPolicy); | |
| 73 }; | |
| 74 | |
| 75 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_EVICTION_POLICY_H_ | |
| OLD | NEW |