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

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

Issue 2146023003: Add UMA Precache.Freshness.Prefetch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed the histogram summary Created 4 years, 5 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "components/history/core/browser/history_service.h" 17 #include "components/history/core/browser/history_service.h"
18 #include "components/precache/core/precache_database.h" 18 #include "components/precache/core/precache_database.h"
19 #include "components/precache/core/precache_switches.h" 19 #include "components/precache/core/precache_switches.h"
20 #include "components/precache/core/proto/unfinished_work.pb.h" 20 #include "components/precache/core/proto/unfinished_work.pb.h"
21 #include "components/prefs/pref_service.h" 21 #include "components/prefs/pref_service.h"
22 #include "components/sync_driver/sync_service.h" 22 #include "components/sync_driver/sync_service.h"
23 #include "components/variations/metrics_util.h" 23 #include "components/variations/metrics_util.h"
24 #include "components/variations/variations_associated_data.h" 24 #include "components/variations/variations_associated_data.h"
25 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/storage_partition.h" 27 #include "content/public/browser/storage_partition.h"
28 #include "net/base/network_change_notifier.h" 28 #include "net/base/network_change_notifier.h"
29 #include "net/http/http_response_info.h"
bengr 2016/07/21 00:03:27 Remove this include. You will forward declare in t
jamartin 2016/07/25 23:23:07 Done.
29 30
30 using content::BrowserThread; 31 using content::BrowserThread;
31 32
32 namespace { 33 namespace {
33 34
34 const char kPrecacheFieldTrialName[] = "Precache"; 35 const char kPrecacheFieldTrialName[] = "Precache";
35 const char kPrecacheFieldTrialEnabledGroup[] = "Enabled"; 36 const char kPrecacheFieldTrialEnabledGroup[] = "Enabled";
36 const char kPrecacheFieldTrialControlGroup[] = "Control"; 37 const char kPrecacheFieldTrialControlGroup[] = "Control";
37 const char kConfigURLParam[] = "config_url"; 38 const char kConfigURLParam[] = "config_url";
38 const char kManifestURLPrefixParam[] = "manifest_url_prefix"; 39 const char kManifestURLPrefixParam[] = "manifest_url_prefix";
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 bool PrecacheManager::IsPrecaching() const { 213 bool PrecacheManager::IsPrecaching() const {
213 DCHECK_CURRENTLY_ON(BrowserThread::UI); 214 DCHECK_CURRENTLY_ON(BrowserThread::UI);
214 return is_precaching_; 215 return is_precaching_;
215 } 216 }
216 217
217 void PrecacheManager::UpdatePrecacheMetricsAndState( 218 void PrecacheManager::UpdatePrecacheMetricsAndState(
218 const GURL& url, 219 const GURL& url,
219 const GURL& referrer, 220 const GURL& referrer,
220 const base::TimeDelta& latency, 221 const base::TimeDelta& latency,
221 const base::Time& fetch_time, 222 const base::Time& fetch_time,
223 const net::HttpResponseInfo& info,
222 int64_t size, 224 int64_t size,
223 bool was_cached,
224 bool is_user_traffic) { 225 bool is_user_traffic) {
225 DCHECK_CURRENTLY_ON(BrowserThread::UI); 226 DCHECK_CURRENTLY_ON(BrowserThread::UI);
226 227
227 RecordStatsForFetch(url, referrer, latency, fetch_time, size, was_cached); 228 RecordStatsForFetch(url, referrer, latency, fetch_time, info, size);
228 if (is_user_traffic && IsPrecaching()) 229 if (is_user_traffic && IsPrecaching())
229 CancelPrecaching(); 230 CancelPrecaching();
230 } 231 }
231 232
232 void PrecacheManager::RecordStatsForFetch(const GURL& url, 233 void PrecacheManager::RecordStatsForFetch(const GURL& url,
233 const GURL& referrer, 234 const GURL& referrer,
234 const base::TimeDelta& latency, 235 const base::TimeDelta& latency,
235 const base::Time& fetch_time, 236 const base::Time& fetch_time,
236 int64_t size, 237 const net::HttpResponseInfo& info,
237 bool was_cached) { 238 int64_t size) {
238 DCHECK_CURRENTLY_ON(BrowserThread::UI); 239 DCHECK_CURRENTLY_ON(BrowserThread::UI);
239 240
240 if (size == 0 || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) { 241 if (size == 0 || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) {
241 // Ignore empty responses, empty URLs, or URLs that aren't HTTP or HTTPS. 242 // Ignore empty responses, empty URLs, or URLs that aren't HTTP or HTTPS.
242 return; 243 return;
243 } 244 }
244 245
245 if (!history_service_) 246 if (!history_service_)
246 return; 247 return;
247 248
248 history_service_->HostRankIfAvailable( 249 history_service_->HostRankIfAvailable(
249 referrer, 250 referrer, base::Bind(&PrecacheManager::RecordStatsForFetchInternal,
250 base::Bind(&PrecacheManager::RecordStatsForFetchInternal, AsWeakPtr(), 251 AsWeakPtr(), url, latency, fetch_time, info, size));
251 url, latency, fetch_time, size, was_cached));
252 } 252 }
253 253
254 void PrecacheManager::RecordStatsForFetchInternal( 254 void PrecacheManager::RecordStatsForFetchInternal(
255 const GURL& url, 255 const GURL& url,
256 const base::TimeDelta& latency, 256 const base::TimeDelta& latency,
257 const base::Time& fetch_time, 257 const base::Time& fetch_time,
258 const net::HttpResponseInfo& info,
258 int64_t size, 259 int64_t size,
259 bool was_cached,
260 int host_rank) { 260 int host_rank) {
261 if (is_precaching_) { 261 if (is_precaching_) {
262 // Assume that precache is responsible for all requests made while 262 // Assume that precache is responsible for all requests made while
263 // precaching is currently in progress. 263 // precaching is currently in progress.
264 // TODO(sclittle): Make PrecacheFetcher explicitly mark precache-motivated 264 // TODO(sclittle): Make PrecacheFetcher explicitly mark precache-motivated
265 // fetches, and use that to determine whether or not a fetch was motivated 265 // fetches, and use that to determine whether or not a fetch was motivated
266 // by precaching. 266 // by precaching.
267 BrowserThread::PostTask( 267 BrowserThread::PostTask(
268 BrowserThread::DB, FROM_HERE, 268 BrowserThread::DB, FROM_HERE,
269 base::Bind(&PrecacheDatabase::RecordURLPrefetch, 269 base::Bind(&PrecacheDatabase::RecordURLPrefetch,
270 base::Unretained(precache_database_.get()), url, latency, 270 base::Unretained(precache_database_.get()), url, latency,
271 fetch_time, size, was_cached)); 271 fetch_time, info, size));
272 } else { 272 } else {
273 bool is_connection_cellular = 273 bool is_connection_cellular =
274 net::NetworkChangeNotifier::IsConnectionCellular( 274 net::NetworkChangeNotifier::IsConnectionCellular(
275 net::NetworkChangeNotifier::GetConnectionType()); 275 net::NetworkChangeNotifier::GetConnectionType());
276 276
277 BrowserThread::PostTask( 277 BrowserThread::PostTask(
278 BrowserThread::DB, FROM_HERE, 278 BrowserThread::DB, FROM_HERE,
279 base::Bind(&PrecacheDatabase::RecordURLNonPrefetch, 279 base::Bind(&PrecacheDatabase::RecordURLNonPrefetch,
280 base::Unretained(precache_database_.get()), url, latency, 280 base::Unretained(precache_database_.get()), url, latency,
281 fetch_time, size, was_cached, host_rank, 281 fetch_time, info, size, host_rank, is_connection_cellular));
282 is_connection_cellular));
283 } 282 }
284 } 283 }
285 284
286 void PrecacheManager::ClearHistory() { 285 void PrecacheManager::ClearHistory() {
287 // PrecacheDatabase::ClearHistory must run after PrecacheDatabase::Init has 286 // PrecacheDatabase::ClearHistory must run after PrecacheDatabase::Init has
288 // finished. Using PostNonNestableTask guarantees this, by definition. See 287 // finished. Using PostNonNestableTask guarantees this, by definition. See
289 // base::SequencedTaskRunner for details. 288 // base::SequencedTaskRunner for details.
290 BrowserThread::PostNonNestableTask( 289 BrowserThread::PostNonNestableTask(
291 BrowserThread::DB, FROM_HERE, 290 BrowserThread::DB, FROM_HERE,
292 base::Bind(&PrecacheDatabase::ClearHistory, 291 base::Bind(&PrecacheDatabase::ClearHistory,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 this)); 342 this));
344 precache_fetcher_->Start(); 343 precache_fetcher_->Start();
345 } 344 }
346 345
347 void PrecacheManager::OnHostsReceivedThenDone( 346 void PrecacheManager::OnHostsReceivedThenDone(
348 const history::TopHostsList& host_counts) { 347 const history::TopHostsList& host_counts) {
349 OnDone(); 348 OnDone();
350 } 349 }
351 350
352 } // namespace precache 351 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698