| Index: components/precache/core/precache_database.cc
|
| diff --git a/components/precache/core/precache_database.cc b/components/precache/core/precache_database.cc
|
| index 269eded59dc1da3031a31610d56265cfe8372458..913c09fe4cc800e9dd3cc8586378ab02b200bb2f 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"
|
| @@ -118,8 +120,8 @@ base::Time PrecacheDatabase::GetLastPrecacheTimestamp() {
|
| 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()) {
|
| @@ -133,15 +135,27 @@ void PrecacheDatabase::RecordURLPrefetch(const GURL& url,
|
| Flush();
|
| }
|
|
|
| - if (was_cached && !precache_url_table_.HasURL(url)) {
|
| + DCHECK(info.headers) << "The headers are required to get the freshness.";
|
| + if (info.headers) {
|
| + UMA_HISTOGRAM_CUSTOM_COUNTS(
|
| + "Precache.Freshness.Prefetch",
|
| + info.headers->GetFreshnessLifetimes(info.response_time)
|
| + .freshness.InSeconds(),
|
| + base::TimeDelta::FromMinutes(5).InSeconds() /* min */,
|
| + base::TimeDelta::FromDays(356).InSeconds() /* max */,
|
| + 100 /* bucket_count */);
|
| + }
|
| +
|
| + if (info.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.
|
| + // because of user browsing. Therefore, this precache won't be considered as
|
| + // precache-motivated since it had no significant effect (besides a possible
|
| + // revalidation and a change in the cache LRU priority).
|
| 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",
|
| @@ -161,8 +175,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);
|
| @@ -190,14 +204,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);
|
| @@ -205,7 +219,7 @@ void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url,
|
| UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular",
|
| size_sample);
|
| }
|
| - } else {
|
| + } else { // info.was_cached.
|
| // The fetch was served from the cache, and since there's an entry for this
|
| // URL in the URL table, this means that the resource was served from the
|
| // cache only because precaching put it there. Thus, precaching was helpful,
|
| @@ -214,6 +228,18 @@ void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url,
|
| if (is_connection_cellular) {
|
| UMA_HISTOGRAM_COUNTS("Precache.Saved.Cellular", size_sample);
|
| }
|
| +
|
| + DCHECK(info.headers) << "The headers are required to get the freshness.";
|
| + if (info.headers) {
|
| + // TODO(jamartin): Maybe report stale_while_validate as well.
|
| + UMA_HISTOGRAM_CUSTOM_COUNTS(
|
| + "Precache.Saved.Freshness",
|
| + info.headers->GetFreshnessLifetimes(info.response_time)
|
| + .freshness.InSeconds(),
|
| + base::TimeDelta::FromMinutes(5).InSeconds() /* min */,
|
| + base::TimeDelta::FromDays(356).InSeconds() /* max */,
|
| + 100 /* bucket_count */);
|
| + }
|
| }
|
|
|
| // Since the resource has been fetched during user browsing, remove any record
|
|
|