| Index: chrome/browser/predictors/resource_prefetch_predictor.cc
|
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| index f333d10b6f92ae13d5899553915b79ee16ee6edd..9d729fdf4f84b1dbf6caf69e3d1df77994ac6bf3 100644
|
| --- a/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| +++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| @@ -13,6 +13,7 @@
|
| #include "base/memory/ptr_util.h"
|
| #include "base/metrics/histogram_macros.h"
|
| #include "base/metrics/sparse_histogram.h"
|
| +#include "base/rand_util.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/time/time.h"
|
| #include "base/trace_event/trace_event.h"
|
| @@ -56,6 +57,8 @@ const char* kFontMimeTypes[] = {"font/woff2",
|
| "application/font-sfnt",
|
| "application/font-ttf"};
|
|
|
| +const size_t kNumSampleHosts = 50;
|
| +
|
| // For reporting events of interest that are not tied to any navigation.
|
| enum ReportingEvent {
|
| REPORTING_EVENT_ALL_HISTORY_CLEARED = 0,
|
| @@ -609,6 +612,14 @@ void ResourcePrefetchPredictor::OnNavigationComplete(
|
| base::Bind(&ResourcePrefetchPredictor::OnVisitCountLookup,
|
| AsWeakPtr()))),
|
| &history_lookup_consumer_);
|
| +
|
| + // Report readiness metric with 20% probability.
|
| + if (base::RandInt(1, 5) == 5) {
|
| + history_service->TopHosts(
|
| + kNumSampleHosts,
|
| + base::Bind(&ResourcePrefetchPredictor::ReportDatabaseReadiness,
|
| + AsWeakPtr()));
|
| + }
|
| }
|
|
|
| bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& main_frame_url,
|
| @@ -1105,6 +1116,31 @@ void ResourcePrefetchPredictor::LearnRedirect(const std::string& key,
|
| }
|
| }
|
|
|
| +void ResourcePrefetchPredictor::ReportDatabaseReadiness(
|
| + const history::TopHostsList& top_hosts) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + if (top_hosts.size() == 0)
|
| + return;
|
| +
|
| + int count_in_cache = 0;
|
| + for (const std::pair<std::string, int>& top_host : top_hosts) {
|
| + const std::string& host = top_host.first;
|
| + if (host_table_cache_->find(host) != host_table_cache_->end()) {
|
| + ++count_in_cache;
|
| + } else {
|
| + // Hostnames in TopHostsLists are stripped of their 'www.' prefix. We
|
| + // assume that www.foo.com entry from |host_table_cache_| is also suitable
|
| + // for foo.com.
|
| + if (!base::StartsWith(host, "www.", base::CompareCase::SENSITIVE) &&
|
| + host_table_cache_->find("www." + host) != host_table_cache_->end()) {
|
| + ++count_in_cache;
|
| + }
|
| + }
|
| + }
|
| + UMA_HISTOGRAM_PERCENTAGE("ResourcePrefetchPredictor.DatabaseReadiness",
|
| + 100 * count_in_cache / top_hosts.size());
|
| +}
|
| +
|
| void ResourcePrefetchPredictor::OnURLsDeleted(
|
| history::HistoryService* history_service,
|
| bool all_history,
|
|
|