Chromium Code Reviews| Index: chrome/browser/engagement/site_engagement_eviction_policy.cc |
| diff --git a/chrome/browser/engagement/site_engagement_eviction_policy.cc b/chrome/browser/engagement/site_engagement_eviction_policy.cc |
| index ba7a885fae5d8088978d2e9a18d8627894667c41..6530cda7e3e98963038fb797ff35dbd9deaf771d 100644 |
| --- a/chrome/browser/engagement/site_engagement_eviction_policy.cc |
| +++ b/chrome/browser/engagement/site_engagement_eviction_policy.cc |
| @@ -2,7 +2,6 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "base/barrier_closure.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/engagement/site_engagement_eviction_policy.h" |
| #include "chrome/browser/engagement/site_engagement_service.h" |
| @@ -12,6 +11,9 @@ |
| namespace { |
| +base::Callback<SiteEngagementScoreProvider*(content::BrowserContext*)>* |
| + g_test_score_provider_callback = nullptr; |
| + |
| const int kExpectedEngagementSites = 200; |
| // Gets the quota that an origin deserves based on its site engagement. |
| @@ -64,6 +66,7 @@ GURL DoCalculateEvictionOrigin( |
| origin_to_evict = origin; |
| } |
| } |
| + |
| return origin_to_evict; |
| } |
| @@ -73,16 +76,23 @@ GURL GetSiteEngagementEvictionOriginOnUIThread( |
| const std::map<GURL, int64>& usage_map, |
| int64 global_quota) { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| - Profile* profile = Profile::FromBrowserContext(browser_context); |
| - SiteEngagementService* service = |
| - g_browser_process->profile_manager()->IsValidProfile(profile) |
| - ? SiteEngagementService::Get(profile) |
| - : nullptr; |
| - if (!service) |
| + |
| + SiteEngagementScoreProvider* score_provider = nullptr; |
| + if (g_test_score_provider_callback) { |
| + score_provider = g_test_score_provider_callback->Run(browser_context); |
| + } else { |
| + Profile* profile = Profile::FromBrowserContext(browser_context); |
| + score_provider = |
| + g_browser_process->profile_manager()->IsValidProfile(profile) |
| + ? SiteEngagementService::Get(profile) |
| + : nullptr; |
| + } |
| + |
| + if (!score_provider) |
| return GURL(); |
| - return DoCalculateEvictionOrigin(special_storage_policy, service, usage_map, |
| - global_quota); |
| + return DoCalculateEvictionOrigin(special_storage_policy, score_provider, |
| + usage_map, global_quota); |
| } |
| } // namespace |
| @@ -94,20 +104,37 @@ SiteEngagementEvictionPolicy::SiteEngagementEvictionPolicy( |
| SiteEngagementEvictionPolicy::~SiteEngagementEvictionPolicy() {} |
| void SiteEngagementEvictionPolicy::GetEvictionOrigin( |
| + scoped_ptr<QuotaEvictionPolicy::Info> info, |
| const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, |
| - const std::map<GURL, int64>& usage_map, |
| - int64 global_quota, |
| const storage::GetOriginCallback& callback) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| + |
| content::BrowserThread::PostTaskAndReplyWithResult( |
| content::BrowserThread::UI, FROM_HERE, |
| base::Bind(&GetSiteEngagementEvictionOriginOnUIThread, |
| - special_storage_policy, browser_context_, usage_map, |
| - global_quota), |
| + special_storage_policy, browser_context_, |
| + info->origin_usage_map, info->global_quota), |
|
michaeln
2015/10/06 00:35:09
I thought you might have created the |info| struct
calamity
2015/10/07 02:42:46
Done.
|
| callback); |
| } |
| +bool SiteEngagementEvictionPolicy::NeedsOriginUsageMap() { |
| + return true; |
| +} |
| + |
| +bool SiteEngagementEvictionPolicy::NeedsGlobalQuota() { |
| + return true; |
| +} |
| + |
| +// static |
| +void SiteEngagementEvictionPolicy:: |
| + SetSiteEngagementScoreProviderCallbackForTests( |
| + base::Callback<SiteEngagementScoreProvider*(content::BrowserContext*)>* |
| + callback) { |
| + g_test_score_provider_callback = callback; |
| +} |
| + |
| // static |
| -GURL SiteEngagementEvictionPolicy::CalculateEvictionOrigin( |
| +GURL SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( |
| const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, |
| SiteEngagementScoreProvider* score_provider, |
| const std::map<GURL, int64>& usage_map, |