Chromium Code Reviews| Index: components/precache/core/precache_database.cc |
| diff --git a/components/precache/core/precache_database.cc b/components/precache/core/precache_database.cc |
| index e9d53ecad16d8bc30ebd4415013430d1bd131dda..d843ff059e9e1c53edcbae3bf7ad39eca6d1d30e 100644 |
| --- a/components/precache/core/precache_database.cc |
| +++ b/components/precache/core/precache_database.cc |
| @@ -13,6 +13,8 @@ |
| #include "base/time/time.h" |
| #include "components/history/core/browser/history_constants.h" |
| #include "components/precache/core/proto/unfinished_work.pb.h" |
| +#include "net/http/http_response_headers.h" |
| +#include "net/http/http_response_info.h" |
| #include "sql/connection.h" |
| #include "sql/transaction.h" |
| #include "url/gurl.h" |
| @@ -93,8 +95,8 @@ void PrecacheDatabase::ClearHistory() { |
| void PrecacheDatabase::RecordURLPrefetch(const GURL& url, |
| const base::TimeDelta& latency, |
| const base::Time& fetch_time, |
| - int64_t size, |
| - bool was_cached) { |
| + const net::HttpResponseInfo& info, |
| + int64_t size) { |
| UMA_HISTOGRAM_TIMES("Precache.Latency.Prefetch", latency); |
| if (!IsDatabaseAccessible()) { |
| @@ -108,15 +110,29 @@ void PrecacheDatabase::RecordURLPrefetch(const GURL& url, |
| Flush(); |
| } |
| - if (was_cached && !precache_url_table_.HasURL(url)) { |
| - // Since the precache came from the cache, and there's no entry in the URL |
| - // table for the URL, this means that the resource was already in the cache |
| - // because of user browsing. Thus, this precache had no effect, so ignore |
| - // it. |
| + DCHECK(info.headers) << "The headers are required."; |
| + if (info.headers) { |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
|
twifkak
2016/07/18 04:30:35
Why not UMA_HISTOGRAM_CUSTOM_TIMES?
jamartin
2016/07/18 16:29:43
I could if you really wanted. However, UMA_HISTOGR
twifkak
2016/07/18 23:50:44
Nah, that's a good enough reason for me.
|
| + "Precache.Freshness.Prefetch", |
| + info.headers->GetFreshnessLifetimes(info.response_time) |
| + .freshness.InSeconds(), |
| + base::TimeDelta::FromMinutes(1).InSeconds() /* min */, |
| + base::TimeDelta::FromHours(36).InSeconds() /* max */, |
|
twifkak
2016/07/18 04:30:35
Obviously a lot of things are going to go in the o
jamartin
2016/07/18 16:29:43
Well, my thought was to mimic the other counter (.
twifkak
2016/07/18 23:50:44
Yeah, that sounds pretty reasonable.
|
| + 100 /* bucket_count */); |
| + } |
| + |
| + if (info.was_cached && !info.network_accessed && |
|
twifkak
2016/07/18 04:30:35
I thought the plan was to add a Precache.Saved.Upp
jamartin
2016/07/18 16:29:43
You are right. I don't understand this code as wel
twifkak
2016/07/18 23:50:44
Oy, that sounds fun.
|
| + !precache_url_table_.HasURL(url)) { |
| + // Since the precache came from the cache, there's no entry in the URL table |
| + // for the URL and there was no validation, this means that the resource was |
| + // already in the cache because of user browsing. Thus, this precache had no |
| + // effect, so ignore it. |
| + // We take credit for resources that were already in the cache due to user |
| + // browsing but needed validation at the time of the prefetch. |
| return; |
| } |
| - if (!was_cached) { |
| + if (!info.was_cached) { |
| // The precache only counts as overhead if it was downloaded over the |
| // network. |
| UMA_HISTOGRAM_COUNTS("Precache.DownloadedPrecacheMotivated", |
| @@ -136,8 +152,8 @@ void PrecacheDatabase::RecordURLPrefetch(const GURL& url, |
| void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url, |
| const base::TimeDelta& latency, |
| const base::Time& fetch_time, |
| + const net::HttpResponseInfo& info, |
| int64_t size, |
| - bool was_cached, |
| int host_rank, |
| bool is_connection_cellular) { |
| UMA_HISTOGRAM_TIMES("Precache.Latency.NonPrefetch", latency); |
| @@ -163,14 +179,14 @@ void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url, |
| Flush(); |
| } |
| - if (was_cached && !precache_url_table_.HasURL(url)) { |
| + if (info.was_cached && !precache_url_table_.HasURL(url)) { |
| // Ignore cache hits that precache can't take credit for. |
| return; |
| } |
| base::HistogramBase::Sample size_sample = |
| static_cast<base::HistogramBase::Sample>(size); |
| - if (!was_cached) { |
| + if (!info.was_cached) { |
| // The fetch was served over the network during user browsing, so count it |
| // as downloaded non-precache bytes. |
| UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size_sample); |