| 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" | 5 #include "chrome/browser/engagement/site_engagement_eviction_policy.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/engagement/site_engagement_service.h" | 11 #include "chrome/browser/engagement/site_engagement_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const int kExpectedEngagementSites = 200; | 19 const int kExpectedEngagementSites = 200; |
| 20 | 20 |
| 21 // Gets the quota that an origin deserves based on its site engagement. | 21 // Gets the quota that an origin deserves based on its site engagement. |
| 22 int64_t GetSoftQuotaForOrigin(const GURL& origin, | 22 int64_t GetSoftQuotaForOrigin(const GURL& origin, |
| 23 int score, | 23 int score, |
| 24 int total_engagement_points, | 24 int total_engagement_points, |
| 25 int64_t global_quota) { | 25 int64_t global_quota) { |
| 26 double quota_per_point = | 26 double quota_per_point = |
| 27 global_quota / | 27 global_quota / |
| 28 std::max(kExpectedEngagementSites * SiteEngagementScore::kMaxPoints, | 28 std::max(kExpectedEngagementSites * SiteEngagementService::GetMaxPoints(), |
| 29 static_cast<double>(total_engagement_points)); | 29 static_cast<double>(total_engagement_points)); |
| 30 | 30 |
| 31 return score * quota_per_point; | 31 return score * quota_per_point; |
| 32 } | 32 } |
| 33 | 33 |
| 34 GURL DoCalculateEvictionOrigin( | 34 GURL DoCalculateEvictionOrigin( |
| 35 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, | 35 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, |
| 36 SiteEngagementScoreProvider* score_provider, | 36 SiteEngagementScoreProvider* score_provider, |
| 37 const std::set<GURL>& exceptions, | 37 const std::set<GURL>& exceptions, |
| 38 const std::map<GURL, int64_t>& usage_map, | 38 const std::map<GURL, int64_t>& usage_map, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // static | 135 // static |
| 136 GURL SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( | 136 GURL SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( |
| 137 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, | 137 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, |
| 138 SiteEngagementScoreProvider* score_provider, | 138 SiteEngagementScoreProvider* score_provider, |
| 139 const std::set<GURL>& exceptions, | 139 const std::set<GURL>& exceptions, |
| 140 const std::map<GURL, int64_t>& usage_map, | 140 const std::map<GURL, int64_t>& usage_map, |
| 141 int64_t global_quota) { | 141 int64_t global_quota) { |
| 142 return DoCalculateEvictionOrigin(special_storage_policy, score_provider, | 142 return DoCalculateEvictionOrigin(special_storage_policy, score_provider, |
| 143 exceptions, usage_map, global_quota); | 143 exceptions, usage_map, global_quota); |
| 144 } | 144 } |
| OLD | NEW |