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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/precache/content/precache_manager.h" 5 #include "components/precache/content/precache_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 base::FilePath(FILE_PATH_LITERAL("PrecacheDatabase")))); 52 base::FilePath(FILE_PATH_LITERAL("PrecacheDatabase"))));
53 53
54 BrowserThread::PostTask( 54 BrowserThread::PostTask(
55 BrowserThread::DB, FROM_HERE, 55 BrowserThread::DB, FROM_HERE,
56 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), 56 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init),
57 precache_database_, db_path)); 57 precache_database_, db_path));
58 } 58 }
59 59
60 PrecacheManager::~PrecacheManager() {} 60 PrecacheManager::~PrecacheManager() {}
61 61
62 bool PrecacheManager::ShouldRun() const {
63 // Verify IsPrecachingAllowed() before calling IsPrecachingEnabled(). This is
64 // because field trials are only assigned when requested. This allows us to
65 // create Control and Experiment groups that are limited to users for whom
66 // IsPrecachingAllowed() is true, thus accentuating the impact of precaching.
67 return IsPrecachingAllowed() && IsPrecachingEnabled();
68 }
69
70 bool PrecacheManager::WouldRun() const {
71 return IsPrecachingAllowed();
72 }
73
62 // static 74 // static
63 bool PrecacheManager::IsPrecachingEnabled() { 75 bool PrecacheManager::IsPrecachingEnabled() {
64 return base::FieldTrialList::FindFullName(kPrecacheFieldTrialName) == 76 return base::FieldTrialList::FindFullName(kPrecacheFieldTrialName) ==
65 kPrecacheFieldTrialEnabledGroup || 77 kPrecacheFieldTrialEnabledGroup ||
66 base::CommandLine::ForCurrentProcess()->HasSwitch( 78 base::CommandLine::ForCurrentProcess()->HasSwitch(
67 switches::kEnablePrecache); 79 switches::kEnablePrecache);
68 } 80 }
69 81
70 bool PrecacheManager::IsPrecachingAllowed() { 82 bool PrecacheManager::IsPrecachingAllowed() const {
83 // SyncService delegates to SyncPrefs, which must be called on the UI thread.
71 return sync_service_ && 84 return sync_service_ &&
72 sync_service_->GetActiveDataTypes().Has(syncer::SESSIONS) && 85 sync_service_->GetActiveDataTypes().Has(syncer::SESSIONS) &&
73 !sync_service_->GetEncryptedDataTypes().Has(syncer::SESSIONS); 86 !sync_service_->GetEncryptedDataTypes().Has(syncer::SESSIONS);
74 } 87 }
75 88
76 void PrecacheManager::StartPrecaching( 89 void PrecacheManager::StartPrecaching(
77 const PrecacheCompletionCallback& precache_completion_callback, 90 const PrecacheCompletionCallback& precache_completion_callback,
78 const history::HistoryService& history_service) { 91 const history::HistoryService& history_service) {
79 DCHECK_CURRENTLY_ON(BrowserThread::UI); 92 DCHECK_CURRENTLY_ON(BrowserThread::UI);
80 93
81 if (is_precaching_) { 94 if (is_precaching_) {
82 DLOG(WARNING) << "Cannot start precaching because precaching is already " 95 DLOG(WARNING) << "Cannot start precaching because precaching is already "
83 "in progress."; 96 "in progress.";
84 return; 97 return;
85 } 98 }
86 is_precaching_ = true; 99 is_precaching_ = true;
87 100
88 BrowserThread::PostTask(
89 BrowserThread::DB, FROM_HERE,
90 base::Bind(&PrecacheDatabase::DeleteExpiredPrecacheHistory,
91 precache_database_, base::Time::Now()));
92
93 precache_completion_callback_ = precache_completion_callback; 101 precache_completion_callback_ = precache_completion_callback;
94 102
95 // Request NumTopHosts() top hosts. Note that PrecacheFetcher is further bound 103 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
96 // by the value of PrecacheConfigurationSettings.top_sites_count, as retrieved 104 BrowserThread::PostTask(
97 // from the server. 105 BrowserThread::DB, FROM_HERE,
98 history_service.TopHosts( 106 base::Bind(&PrecacheDatabase::DeleteExpiredPrecacheHistory,
99 NumTopHosts(), 107 precache_database_, base::Time::Now()));
100 base::Bind(&PrecacheManager::OnHostsReceived, AsWeakPtr())); 108
109 // Request NumTopHosts() top hosts. Note that PrecacheFetcher is further
110 // bound by the value of PrecacheConfigurationSettings.top_sites_count, as
111 // retrieved from the server.
112 history_service.TopHosts(
113 NumTopHosts(),
114 base::Bind(&PrecacheManager::OnHostsReceived, AsWeakPtr()));
115 } else {
116 OnDone();
117 }
101 } 118 }
102 119
103 void PrecacheManager::CancelPrecaching() { 120 void PrecacheManager::CancelPrecaching() {
104 DCHECK_CURRENTLY_ON(BrowserThread::UI); 121 DCHECK_CURRENTLY_ON(BrowserThread::UI);
105 122
106 if (!is_precaching_) { 123 if (!is_precaching_) {
107 // Do nothing if precaching is not in progress. 124 // Do nothing if precaching is not in progress.
108 return; 125 return;
109 } 126 }
110 is_precaching_ = false; 127 is_precaching_ = false;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // Start precaching. 215 // Start precaching.
199 precache_fetcher_.reset( 216 precache_fetcher_.reset(
200 new PrecacheFetcher(hosts, browser_context_->GetRequestContext(), 217 new PrecacheFetcher(hosts, browser_context_->GetRequestContext(),
201 variations::GetVariationParamValue( 218 variations::GetVariationParamValue(
202 kPrecacheFieldTrialName, kManifestURLPrefixParam), 219 kPrecacheFieldTrialName, kManifestURLPrefixParam),
203 this)); 220 this));
204 precache_fetcher_->Start(); 221 precache_fetcher_->Start();
205 } 222 }
206 223
207 } // namespace precache 224 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698