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

Side by Side Diff: chrome/browser/precache/precache_util.cc

Issue 2146023003: Add UMA Precache.Freshness.Prefetch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gclient sync Created 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/precache/precache_util.h" 5 #include "chrome/browser/precache/precache_util.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/precache/precache_manager_factory.h" 9 #include "chrome/browser/precache/precache_manager_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "components/data_use_measurement/content/data_use_measurement.h" 12 #include "components/data_use_measurement/content/data_use_measurement.h"
13 #include "components/precache/content/precache_manager.h" 13 #include "components/precache/content/precache_manager.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 namespace { 18 namespace {
19 19
20 void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url, 20 void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url,
21 const GURL& referrer, 21 const GURL& referrer,
22 base::TimeDelta latency, 22 base::TimeDelta latency,
23 const base::Time& fetch_time, 23 const base::Time& fetch_time,
24 const net::HttpResponseInfo& info,
24 int64_t size, 25 int64_t size,
25 bool was_cached,
26 bool is_user_traffic, 26 bool is_user_traffic,
27 void* profile_id) { 27 void* profile_id) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
29 29
30 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id)) 30 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id))
31 return; 31 return;
32 Profile* profile = reinterpret_cast<Profile*>(profile_id); 32 Profile* profile = reinterpret_cast<Profile*>(profile_id);
33 33
34 precache::PrecacheManager* precache_manager = 34 precache::PrecacheManager* precache_manager =
35 precache::PrecacheManagerFactory::GetForBrowserContext(profile); 35 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
36 // |precache_manager| could be NULL if the profile is off the record. 36 // |precache_manager| could be NULL if the profile is off the record.
37 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) 37 if (!precache_manager || !precache_manager->IsPrecachingAllowed())
38 return; 38 return;
39 39
40 precache_manager->UpdatePrecacheMetricsAndState( 40 precache_manager->UpdatePrecacheMetricsAndState(
41 url, referrer, latency, fetch_time, size, was_cached, is_user_traffic); 41 url, referrer, latency, fetch_time, info, size, is_user_traffic);
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 namespace precache { 46 namespace precache {
47 47
48 // TODO(rajendrant): Add unittests for this function. 48 // TODO(rajendrant): Add unittests for this function.
49 void UpdatePrecacheMetricsAndState(const net::URLRequest* request, 49 void UpdatePrecacheMetricsAndState(const net::URLRequest* request,
50 void* profile_id) { 50 void* profile_id) {
51 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 51 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
52 52
53 // For better accuracy, we use the actual bytes read instead of the length 53 // For better accuracy, we use the actual bytes read instead of the length
54 // specified with the Content-Length header, which may be inaccurate, 54 // specified with the Content-Length header, which may be inaccurate,
55 // or missing, as is the case with chunked encoding. 55 // or missing, as is the case with chunked encoding.
56 int64_t received_content_length = request->received_response_content_length(); 56 int64_t received_content_length = request->received_response_content_length();
57 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time(); 57 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time();
58 58
59 // Record precache metrics when a fetch is completed successfully, if 59 // Record precache metrics when a fetch is completed successfully, if
60 // precaching is allowed. 60 // precaching is allowed.
61 content::BrowserThread::PostTask( 61 content::BrowserThread::PostTask(
62 content::BrowserThread::UI, FROM_HERE, 62 content::BrowserThread::UI, FROM_HERE,
63 base::Bind( 63 base::Bind(
64 &UpdatePrecacheMetricsAndStateOnUIThread, request->url(), 64 &UpdatePrecacheMetricsAndStateOnUIThread, request->url(),
65 GURL(request->referrer()), latency, base::Time::Now(), 65 GURL(request->referrer()), latency, base::Time::Now(),
66 received_content_length, request->was_cached(), 66 request->response_info(), received_content_length,
67 data_use_measurement::DataUseMeasurement::IsUserInitiatedRequest( 67 data_use_measurement::DataUseMeasurement::IsUserInitiatedRequest(
68 request), 68 request),
69 profile_id)); 69 profile_id));
70 } 70 }
71 71
72 } // namespace precache 72 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698