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

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: 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 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/http/http_response_info.h"
bengr 2016/07/21 00:03:27 You should be able to forward declare HttpResponse
jamartin 2016/07/25 23:23:07 Done.
15 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 18
18 namespace { 19 namespace {
19 20
20 void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url, 21 void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url,
21 const GURL& referrer, 22 const GURL& referrer,
22 base::TimeDelta latency, 23 base::TimeDelta latency,
23 const base::Time& fetch_time, 24 const base::Time& fetch_time,
25 const net::HttpResponseInfo& info,
24 int64_t size, 26 int64_t size,
25 bool was_cached,
26 bool is_user_traffic, 27 bool is_user_traffic,
27 void* profile_id) { 28 void* profile_id) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
29 30
30 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id)) 31 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id))
31 return; 32 return;
32 Profile* profile = reinterpret_cast<Profile*>(profile_id); 33 Profile* profile = reinterpret_cast<Profile*>(profile_id);
33 34
34 precache::PrecacheManager* precache_manager = 35 precache::PrecacheManager* precache_manager =
35 precache::PrecacheManagerFactory::GetForBrowserContext(profile); 36 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
36 // |precache_manager| could be NULL if the profile is off the record. 37 // |precache_manager| could be NULL if the profile is off the record.
37 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) 38 if (!precache_manager || !precache_manager->IsPrecachingAllowed())
38 return; 39 return;
39 40
40 precache_manager->UpdatePrecacheMetricsAndState( 41 precache_manager->UpdatePrecacheMetricsAndState(
41 url, referrer, latency, fetch_time, size, was_cached, is_user_traffic); 42 url, referrer, latency, fetch_time, info, size, is_user_traffic);
42 } 43 }
43 44
44 } // namespace 45 } // namespace
45 46
46 namespace precache { 47 namespace precache {
47 48
48 // TODO(rajendrant): Add unittests for this function. 49 // TODO(rajendrant): Add unittests for this function.
49 void UpdatePrecacheMetricsAndState(const net::URLRequest* request, 50 void UpdatePrecacheMetricsAndState(const net::URLRequest* request,
50 void* profile_id) { 51 void* profile_id) {
51 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 52 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
52 53
53 // For better accuracy, we use the actual bytes read instead of the length 54 // For better accuracy, we use the actual bytes read instead of the length
54 // specified with the Content-Length header, which may be inaccurate, 55 // specified with the Content-Length header, which may be inaccurate,
55 // or missing, as is the case with chunked encoding. 56 // or missing, as is the case with chunked encoding.
56 int64_t received_content_length = request->received_response_content_length(); 57 int64_t received_content_length = request->received_response_content_length();
57 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time(); 58 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time();
58 59
59 // Record precache metrics when a fetch is completed successfully, if 60 // Record precache metrics when a fetch is completed successfully, if
60 // precaching is allowed. 61 // precaching is allowed.
61 content::BrowserThread::PostTask( 62 content::BrowserThread::PostTask(
62 content::BrowserThread::UI, FROM_HERE, 63 content::BrowserThread::UI, FROM_HERE,
63 base::Bind( 64 base::Bind(
64 &UpdatePrecacheMetricsAndStateOnUIThread, request->url(), 65 &UpdatePrecacheMetricsAndStateOnUIThread, request->url(),
65 GURL(request->referrer()), latency, base::Time::Now(), 66 GURL(request->referrer()), latency, base::Time::Now(),
66 received_content_length, request->was_cached(), 67 request->response_info(), received_content_length,
67 data_use_measurement::DataUseMeasurement::IsUserInitiatedRequest( 68 data_use_measurement::DataUseMeasurement::IsUserInitiatedRequest(
68 request), 69 request),
69 profile_id)); 70 profile_id));
70 } 71 }
71 72
72 } // namespace precache 73 } // namespace precache
OLDNEW
« no previous file with comments | « no previous file | components/precache/content/DEPS » ('j') | components/precache/content/precache_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698