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

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

Issue 2229983002: Send the list of used and unused resources for precache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits Created 4 years, 3 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 base::Unretained(precache_database_.get())), 135 base::Unretained(precache_database_.get())),
136 base::Bind(&PrecacheManager::OnGetUnfinishedWorkDone, AsWeakPtr())); 136 base::Bind(&PrecacheManager::OnGetUnfinishedWorkDone, AsWeakPtr()));
137 } 137 }
138 138
139 void PrecacheManager::OnGetUnfinishedWorkDone( 139 void PrecacheManager::OnGetUnfinishedWorkDone(
140 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work) { 140 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work) {
141 if (!unfinished_work->has_start_time() || 141 if (!unfinished_work->has_start_time() ||
142 base::Time::Now() - base::Time::FromInternalValue( 142 base::Time::Now() - base::Time::FromInternalValue(
143 unfinished_work->start_time()) > base::TimeDelta::FromHours(6)) { 143 unfinished_work->start_time()) > base::TimeDelta::FromHours(6)) {
144 PrecacheFetcher::RecordCompletionStatistics( 144 PrecacheFetcher::RecordCompletionStatistics(
145 *unfinished_work, 145 *unfinished_work, unfinished_work->top_host_size(),
146 unfinished_work->manifest_size(),
147 unfinished_work->resource_size()); 146 unfinished_work->resource_size());
148 unfinished_work.reset(new PrecacheUnfinishedWork()); 147 unfinished_work.reset(new PrecacheUnfinishedWork());
149 unfinished_work->set_start_time(base::Time::Now().ToInternalValue()); 148 unfinished_work->set_start_time(base::Time::Now().ToInternalValue());
150 } 149 }
151 unfinished_work_ = std::move(unfinished_work); 150 unfinished_work_ = std::move(unfinished_work);
152 bool needs_top_hosts = unfinished_work_->top_host_size() == 0; 151 bool needs_top_hosts = unfinished_work_->top_host_size() == 0;
153 152
154 if (IsInExperimentGroup()) { 153 if (IsInExperimentGroup()) {
155 BrowserThread::PostTask( 154 BrowserThread::PostTask(
156 BrowserThread::DB, FROM_HERE, 155 BrowserThread::DB, FROM_HERE,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 243
245 if (size == 0 || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) { 244 if (size == 0 || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) {
246 // Ignore empty responses, empty URLs, or URLs that aren't HTTP or HTTPS. 245 // Ignore empty responses, empty URLs, or URLs that aren't HTTP or HTTPS.
247 return; 246 return;
248 } 247 }
249 248
250 if (!history_service_) 249 if (!history_service_)
251 return; 250 return;
252 251
253 history_service_->HostRankIfAvailable( 252 history_service_->HostRankIfAvailable(
254 referrer, base::Bind(&PrecacheManager::RecordStatsForFetchInternal, 253 referrer,
255 AsWeakPtr(), url, latency, fetch_time, info, size)); 254 base::Bind(&PrecacheManager::RecordStatsForFetchInternal, AsWeakPtr(),
255 url, referrer.host(), latency, fetch_time, info, size));
256 } 256 }
257 257
258 void PrecacheManager::RecordStatsForFetchInternal( 258 void PrecacheManager::RecordStatsForFetchInternal(
259 const GURL& url, 259 const GURL& url,
260 const std::string& referrer_host,
260 const base::TimeDelta& latency, 261 const base::TimeDelta& latency,
261 const base::Time& fetch_time, 262 const base::Time& fetch_time,
262 const net::HttpResponseInfo& info, 263 const net::HttpResponseInfo& info,
263 int64_t size, 264 int64_t size,
264 int host_rank) { 265 int host_rank) {
265 if (is_precaching_) { 266 if (is_precaching_) {
266 // Assume that precache is responsible for all requests made while 267 // Assume that precache is responsible for all requests made while
267 // precaching is currently in progress. 268 // precaching is currently in progress.
268 // TODO(sclittle): Make PrecacheFetcher explicitly mark precache-motivated 269 // TODO(sclittle): Make PrecacheFetcher explicitly mark precache-motivated
269 // fetches, and use that to determine whether or not a fetch was motivated 270 // fetches, and use that to determine whether or not a fetch was motivated
270 // by precaching. 271 // by precaching.
271 BrowserThread::PostTask( 272 BrowserThread::PostTask(
272 BrowserThread::DB, FROM_HERE, 273 BrowserThread::DB, FROM_HERE,
273 base::Bind(&PrecacheDatabase::RecordURLPrefetch, 274 base::Bind(&PrecacheDatabase::RecordURLPrefetchMetrics,
274 base::Unretained(precache_database_.get()), url, latency, 275 base::Unretained(precache_database_.get()), info, latency));
275 fetch_time, info, size));
276 } else { 276 } else {
277 bool is_connection_cellular = 277 bool is_connection_cellular =
278 net::NetworkChangeNotifier::IsConnectionCellular( 278 net::NetworkChangeNotifier::IsConnectionCellular(
279 net::NetworkChangeNotifier::GetConnectionType()); 279 net::NetworkChangeNotifier::GetConnectionType());
280 280
281 BrowserThread::PostTask( 281 BrowserThread::PostTask(
282 BrowserThread::DB, FROM_HERE, 282 BrowserThread::DB, FROM_HERE,
283 base::Bind(&PrecacheDatabase::RecordURLNonPrefetch, 283 base::Bind(&PrecacheDatabase::RecordURLNonPrefetch,
284 base::Unretained(precache_database_.get()), url, latency, 284 base::Unretained(precache_database_.get()), url, latency,
285 fetch_time, info, size, host_rank, is_connection_cellular)); 285 fetch_time, info, size, host_rank, is_connection_cellular));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 precache_fetcher_.reset(new PrecacheFetcher( 336 precache_fetcher_.reset(new PrecacheFetcher(
337 content::BrowserContext::GetDefaultStoragePartition(browser_context_) 337 content::BrowserContext::GetDefaultStoragePartition(browser_context_)
338 ->GetURLRequestContext(), 338 ->GetURLRequestContext(),
339 GURL(variations::GetVariationParamValue(kPrecacheFieldTrialName, 339 GURL(variations::GetVariationParamValue(kPrecacheFieldTrialName,
340 kConfigURLParam)), 340 kConfigURLParam)),
341 variations::GetVariationParamValue(kPrecacheFieldTrialName, 341 variations::GetVariationParamValue(kPrecacheFieldTrialName,
342 kManifestURLPrefixParam), 342 kManifestURLPrefixParam),
343 std::move(unfinished_work_), 343 std::move(unfinished_work_),
344 metrics::HashName( 344 metrics::HashName(
345 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName)), 345 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName)),
346 precache_database_->GetWeakPtr(),
347 content::BrowserThread::GetTaskRunnerForThread(
348 content::BrowserThread::DB),
346 this)); 349 this));
347 precache_fetcher_->Start(); 350 precache_fetcher_->Start();
348 } 351 }
349 352
350 void PrecacheManager::OnHostsReceivedThenDone( 353 void PrecacheManager::OnHostsReceivedThenDone(
351 const history::TopHostsList& host_counts) { 354 const history::TopHostsList& host_counts) {
352 OnDone(); 355 OnDone();
353 } 356 }
354 357
355 } // namespace precache 358 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/content/precache_manager.h ('k') | components/precache/content/precache_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698