| 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..4f8e78f3e21b0dbb1eb301d0491c9bd10ed9aed4 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,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",
|
| @@ -136,8 +150,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 +177,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);
|
| @@ -178,7 +192,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,
|
| @@ -187,6 +201,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
|
|
|