| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/engagement/site_engagement_eviction_policy.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 5 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 6 #include "chrome/browser/engagement/site_engagement_eviction_policy.h" | |
| 7 #include "chrome/browser/engagement/site_engagement_service.h" | 9 #include "chrome/browser/engagement/site_engagement_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/common/chrome_switches.h" |
| 10 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 11 | 14 |
| 12 namespace { | 15 namespace { |
| 13 | 16 |
| 14 const int kExpectedEngagementSites = 200; | 17 const int kExpectedEngagementSites = 200; |
| 15 | 18 |
| 16 // Gets the quota that an origin deserves based on its site engagement. | 19 // Gets the quota that an origin deserves based on its site engagement. |
| 17 int64 GetSoftQuotaForOrigin(const GURL& origin, | 20 int64 GetSoftQuotaForOrigin(const GURL& origin, |
| 18 int score, | 21 int score, |
| 19 int total_engagement_points, | 22 int total_engagement_points, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 87 |
| 85 if (!score_provider) | 88 if (!score_provider) |
| 86 return GURL(); | 89 return GURL(); |
| 87 | 90 |
| 88 return DoCalculateEvictionOrigin(special_storage_policy, score_provider, | 91 return DoCalculateEvictionOrigin(special_storage_policy, score_provider, |
| 89 exceptions, usage_map, global_quota); | 92 exceptions, usage_map, global_quota); |
| 90 } | 93 } |
| 91 | 94 |
| 92 } // namespace | 95 } // namespace |
| 93 | 96 |
| 97 // static |
| 98 bool SiteEngagementEvictionPolicy::IsEnabled() { |
| 99 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 100 switches::kEnableSiteEngagementEvictionPolicy)) { |
| 101 return true; |
| 102 } |
| 103 |
| 104 const std::string group_name = |
| 105 base::FieldTrialList::FindFullName(kEngagementParams); |
| 106 return base::StartsWith(group_name, "StorageEvictionEnabled", |
| 107 base::CompareCase::SENSITIVE) |
| 108 } |
| 109 |
| 94 SiteEngagementEvictionPolicy::SiteEngagementEvictionPolicy( | 110 SiteEngagementEvictionPolicy::SiteEngagementEvictionPolicy( |
| 95 content::BrowserContext* browser_context) | 111 content::BrowserContext* browser_context) |
| 96 : browser_context_(browser_context) {} | 112 : browser_context_(browser_context) {} |
| 97 | 113 |
| 98 SiteEngagementEvictionPolicy::~SiteEngagementEvictionPolicy() {} | 114 SiteEngagementEvictionPolicy::~SiteEngagementEvictionPolicy() {} |
| 99 | 115 |
| 100 void SiteEngagementEvictionPolicy::GetEvictionOrigin( | 116 void SiteEngagementEvictionPolicy::GetEvictionOrigin( |
| 101 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, | 117 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, |
| 102 const std::set<GURL>& exceptions, | 118 const std::set<GURL>& exceptions, |
| 103 const std::map<GURL, int64>& usage_map, | 119 const std::map<GURL, int64>& usage_map, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 116 // static | 132 // static |
| 117 GURL SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( | 133 GURL SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( |
| 118 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, | 134 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, |
| 119 SiteEngagementScoreProvider* score_provider, | 135 SiteEngagementScoreProvider* score_provider, |
| 120 const std::set<GURL>& exceptions, | 136 const std::set<GURL>& exceptions, |
| 121 const std::map<GURL, int64>& usage_map, | 137 const std::map<GURL, int64>& usage_map, |
| 122 int64 global_quota) { | 138 int64 global_quota) { |
| 123 return DoCalculateEvictionOrigin(special_storage_policy, score_provider, | 139 return DoCalculateEvictionOrigin(special_storage_policy, score_provider, |
| 124 exceptions, usage_map, global_quota); | 140 exceptions, usage_map, global_quota); |
| 125 } | 141 } |
| OLD | NEW |