| 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 "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "storage/browser/quota/quota_manager.h" |
| 14 #include "url/gurl.h" |
| 15 |
| 16 namespace content { |
| 17 class BrowserContext; |
| 18 } |
| 19 |
| 20 class SiteEngagementService; |
| 21 |
| 22 class SiteEngagementEvictionPolicy |
| 23 : public storage::TemporaryStorageEvictionPolicy { |
| 24 public: |
| 25 explicit SiteEngagementEvictionPolicy( |
| 26 content::BrowserContext* browser_context); |
| 27 virtual ~SiteEngagementEvictionPolicy(); |
| 28 |
| 29 // Overridden from storage::TemporaryStorageEvictionPolicy: |
| 30 void GetEvictionOrigin( |
| 31 const std::map<GURL, int64>& usage_map, |
| 32 int64 global_quota, |
| 33 const storage::GetEvictionOriginCallback& callback) override; |
| 34 |
| 35 private: |
| 36 class GetEvictionOriginTask; |
| 37 friend class SiteEngagementEvictionPolicyTest; |
| 38 |
| 39 content::BrowserContext* browser_context_; |
| 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(SiteEngagementEvictionPolicy); |
| 42 }; |
| 43 |
| 44 // A task that calculates the next origin to evict based on usage and site |
| 45 // engagement. |
| 46 class SiteEngagementEvictionPolicy::GetEvictionOriginTask |
| 47 : public base::RefCountedThreadSafe< |
| 48 SiteEngagementEvictionPolicy::GetEvictionOriginTask> { |
| 49 public: |
| 50 GetEvictionOriginTask( |
| 51 content::BrowserContext* browser_context, |
| 52 const std::map<GURL, int64>& usage_map, |
| 53 int64 global_quota, |
| 54 const storage::GetEvictionOriginCallback& result_callback); |
| 55 |
| 56 void Start(); |
| 57 |
| 58 private: |
| 59 friend class base::RefCountedThreadSafe<GetEvictionOriginTask>; |
| 60 friend class SiteEngagementEvictionPolicyTest; |
| 61 |
| 62 static GURL GetSiteEngagementEvictionOriginOnUIThread( |
| 63 content::BrowserContext* browser_context, |
| 64 const std::map<GURL, int64>& usage_map, |
| 65 int64 global_quota); |
| 66 |
| 67 static GURL CalculateEvictionOrigin( |
| 68 SiteEngagementService* service, |
| 69 const std::map<GURL, int64>& usage_map, |
| 70 int64 global_quota); |
| 71 |
| 72 ~GetEvictionOriginTask(); |
| 73 |
| 74 void ReplyWithEvictionOrigin(const GURL& origin_to_evict); |
| 75 |
| 76 const std::map<GURL, int64> usage_map_; |
| 77 const int64 global_quota_; |
| 78 |
| 79 content::BrowserContext* browser_context_; |
| 80 |
| 81 // The callback to run with the next eviction origin. |
| 82 storage::GetEvictionOriginCallback result_callback_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(GetEvictionOriginTask); |
| 85 }; |
| 86 |
| 87 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_EVICTION_POLICY_H_ |
| OLD | NEW |