Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Unified Diff: components/precache/content/precache_manager.cc

Issue 1266243003: Tweaks to the precache triggering code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/precache/content/precache_manager.cc
diff --git a/components/precache/content/precache_manager.cc b/components/precache/content/precache_manager.cc
index a03277c9095da8835296b5708ebf2941f4a94041..f3f2efce9ec60bbebe419290cb22d23426e1c935 100644
--- a/components/precache/content/precache_manager.cc
+++ b/components/precache/content/precache_manager.cc
@@ -59,6 +59,18 @@ PrecacheManager::PrecacheManager(
PrecacheManager::~PrecacheManager() {}
+bool PrecacheManager::ShouldRun() const {
+ // Verify IsPrecachingAllowed() before calling IsPrecachingEnabled(). This is
+ // because field trials are only assigned when requested. This allows us to
+ // create Control and Experiment groups that are limited to users for whom
+ // IsPrecachingAllowed() is true, thus accentuating the impact of precaching.
+ return IsPrecachingAllowed() && IsPrecachingEnabled();
+}
+
+bool PrecacheManager::WouldRun() const {
+ return IsPrecachingAllowed();
+}
+
// static
bool PrecacheManager::IsPrecachingEnabled() {
return base::FieldTrialList::FindFullName(kPrecacheFieldTrialName) ==
@@ -67,7 +79,8 @@ bool PrecacheManager::IsPrecachingEnabled() {
switches::kEnablePrecache);
}
-bool PrecacheManager::IsPrecachingAllowed() {
+bool PrecacheManager::IsPrecachingAllowed() const {
+ // SyncService delegates to SyncPrefs, which must be called on the UI thread.
return sync_service_ &&
sync_service_->GetActiveDataTypes().Has(syncer::SESSIONS) &&
!sync_service_->GetEncryptedDataTypes().Has(syncer::SESSIONS);
@@ -85,19 +98,23 @@ void PrecacheManager::StartPrecaching(
}
is_precaching_ = true;
- BrowserThread::PostTask(
- BrowserThread::DB, FROM_HERE,
- base::Bind(&PrecacheDatabase::DeleteExpiredPrecacheHistory,
- precache_database_, base::Time::Now()));
-
precache_completion_callback_ = precache_completion_callback;
- // Request NumTopHosts() top hosts. Note that PrecacheFetcher is further bound
- // by the value of PrecacheConfigurationSettings.top_sites_count, as retrieved
- // from the server.
- history_service.TopHosts(
- NumTopHosts(),
- base::Bind(&PrecacheManager::OnHostsReceived, AsWeakPtr()));
+ if (ShouldRun()) {
bengr 2015/08/07 17:21:45 Maybe do: if (!ShouldRun()) { OnDone(); retur
twifkak 2015/08/07 17:57:08 I'm not a fan of it (see https://codereview.chromi
+ BrowserThread::PostTask(
+ BrowserThread::DB, FROM_HERE,
+ base::Bind(&PrecacheDatabase::DeleteExpiredPrecacheHistory,
+ precache_database_, base::Time::Now()));
+
+ // Request NumTopHosts() top hosts. Note that PrecacheFetcher is further
+ // bound by the value of PrecacheConfigurationSettings.top_sites_count, as
+ // retrieved from the server.
+ history_service.TopHosts(
+ NumTopHosts(),
+ base::Bind(&PrecacheManager::OnHostsReceived, AsWeakPtr()));
+ } else {
+ OnDone();
+ }
}
void PrecacheManager::CancelPrecaching() {

Powered by Google App Engine
This is Rietveld 408576698