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

Side by Side Diff: components/precache/content/precache_manager.cc

Issue 1272443002: Only set precache.last_time when precache ran. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@filter_stats
Patch Set: 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 void PrecacheManager::StartPrecaching( 89 void PrecacheManager::StartPrecaching(
90 const PrecacheCompletionCallback& precache_completion_callback, 90 const PrecacheCompletionCallback& precache_completion_callback,
91 const history::HistoryService& history_service) { 91 const history::HistoryService& history_service) {
92 DCHECK_CURRENTLY_ON(BrowserThread::UI); 92 DCHECK_CURRENTLY_ON(BrowserThread::UI);
93 93
94 if (is_precaching_) { 94 if (is_precaching_) {
95 DLOG(WARNING) << "Cannot start precaching because precaching is already " 95 DLOG(WARNING) << "Cannot start precaching because precaching is already "
96 "in progress."; 96 "in progress.";
97 return; 97 return;
98 } 98 }
99 is_precaching_ = true;
100
101 precache_completion_callback_ = precache_completion_callback; 99 precache_completion_callback_ = precache_completion_callback;
102 100
103 if (ShouldRun()) { 101 if (ShouldRun()) {
102 is_precaching_ = true;
103
104 BrowserThread::PostTask( 104 BrowserThread::PostTask(
105 BrowserThread::DB, FROM_HERE, 105 BrowserThread::DB, FROM_HERE,
106 base::Bind(&PrecacheDatabase::DeleteExpiredPrecacheHistory, 106 base::Bind(&PrecacheDatabase::DeleteExpiredPrecacheHistory,
107 precache_database_, base::Time::Now())); 107 precache_database_, base::Time::Now()));
108 108
109 // Request NumTopHosts() top hosts. Note that PrecacheFetcher is further 109 // Request NumTopHosts() top hosts. Note that PrecacheFetcher is further
110 // bound by the value of PrecacheConfigurationSettings.top_sites_count, as 110 // bound by the value of PrecacheConfigurationSettings.top_sites_count, as
111 // retrieved from the server. 111 // retrieved from the server.
112 history_service.TopHosts( 112 history_service.TopHosts(
113 NumTopHosts(), 113 NumTopHosts(),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 base::Bind(&PrecacheDatabase::ClearHistory, precache_database_)); 180 base::Bind(&PrecacheDatabase::ClearHistory, precache_database_));
181 } 181 }
182 182
183 void PrecacheManager::Shutdown() { 183 void PrecacheManager::Shutdown() {
184 CancelPrecaching(); 184 CancelPrecaching();
185 } 185 }
186 186
187 void PrecacheManager::OnDone() { 187 void PrecacheManager::OnDone() {
188 DCHECK_CURRENTLY_ON(BrowserThread::UI); 188 DCHECK_CURRENTLY_ON(BrowserThread::UI);
189 189
190 // If OnDone has been called, then we should just be finishing precaching.
191 DCHECK(is_precaching_);
192 is_precaching_ = false;
193
194 precache_fetcher_.reset(); 190 precache_fetcher_.reset();
195 191
196 precache_completion_callback_.Run(); 192 precache_completion_callback_.Run(is_precaching_);
197 // Uninitialize the callback so that any scoped_refptrs in it are released. 193 // Uninitialize the callback so that any scoped_refptrs in it are released.
198 precache_completion_callback_.Reset(); 194 precache_completion_callback_.Reset();
195
196 is_precaching_ = false;
199 } 197 }
200 198
201 void PrecacheManager::OnHostsReceived( 199 void PrecacheManager::OnHostsReceived(
202 const history::TopHostsList& host_counts) { 200 const history::TopHostsList& host_counts) {
203 DCHECK_CURRENTLY_ON(BrowserThread::UI); 201 DCHECK_CURRENTLY_ON(BrowserThread::UI);
204 202
205 if (!is_precaching_) { 203 if (!is_precaching_) {
206 // Don't start precaching if it was canceled while waiting for the list of 204 // Don't start precaching if it was canceled while waiting for the list of
207 // hosts. 205 // hosts.
208 return; 206 return;
209 } 207 }
210 208
211 std::vector<std::string> hosts; 209 std::vector<std::string> hosts;
212 for (const auto& host_count : host_counts) 210 for (const auto& host_count : host_counts)
213 hosts.push_back(host_count.first); 211 hosts.push_back(host_count.first);
214 212
215 // Start precaching. 213 // Start precaching.
216 precache_fetcher_.reset( 214 precache_fetcher_.reset(
217 new PrecacheFetcher(hosts, browser_context_->GetRequestContext(), 215 new PrecacheFetcher(hosts, browser_context_->GetRequestContext(),
218 variations::GetVariationParamValue( 216 variations::GetVariationParamValue(
219 kPrecacheFieldTrialName, kManifestURLPrefixParam), 217 kPrecacheFieldTrialName, kManifestURLPrefixParam),
220 this)); 218 this));
221 precache_fetcher_->Start(); 219 precache_fetcher_->Start();
222 } 220 }
223 221
224 } // namespace precache 222 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698