Index: components/history/core/browser/history_backend.cc |
diff --git a/components/history/core/browser/history_backend.cc b/components/history/core/browser/history_backend.cc |
index d04c038d5bef7fd7c6d97a6bd878e7288a5b94ef..cc0654e9746f536d8fd929d79bed616ea34ec8ff 100644 |
--- a/components/history/core/browser/history_backend.cc |
+++ b/components/history/core/browser/history_backend.cc |
@@ -37,6 +37,7 @@ |
#include "components/history/core/browser/keyword_search_term.h" |
#include "components/history/core/browser/page_usage_data.h" |
#include "components/history/core/browser/typed_url_syncable_service.h" |
+#include "components/history/core/browser/url_utils.h" |
#include "components/history/core/browser/visit_filter.h" |
#include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
#include "sql/error_delegate_util.h" |
@@ -89,6 +90,8 @@ const int kMaxRedirectCount = 32; |
// and is deleted. |
const int kExpireDaysThreshold = 90; |
+const int kMaxTopHostsForMetrics = 50; |
+ |
// Converts from PageUsageData to MostVisitedURL. |redirects| is a |
// list of redirects for this URL. Empty list means no redirects. |
MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, |
@@ -416,7 +419,13 @@ TopHostsList HistoryBackend::TopHosts(int num_hosts) const { |
if (!db_) |
return TopHostsList(); |
- return db_->TopHosts(num_hosts); |
+ auto top_hosts = db_->TopHosts(num_hosts); |
+ |
+ host_ranks_.clear(); |
+ int i = 0; |
+ for (const auto& host_count : top_hosts) |
+ host_ranks_[host_count.first] = ++i; |
+ return top_hosts; |
} |
void HistoryBackend::AddPage(const HistoryAddPageArgs& request) { |
@@ -725,6 +734,15 @@ void HistoryBackend::CloseAllDatabases() { |
} |
} |
+void HistoryBackend::RecordTopHostsMetrics(const GURL& url) { |
+ auto it = host_ranks_.find(HostForTopHosts(url)); |
+ int host_rank = |
+ it != host_ranks_.end() ? it->second : (kMaxTopHostsForMetrics + 1); |
+ |
+ UMA_HISTOGRAM_ENUMERATION("History.TopHostsVisitsByRank", host_rank, |
+ kMaxTopHostsForMetrics + 2); |
+} |
+ |
std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( |
const GURL& url, |
Time time, |
@@ -745,6 +763,11 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( |
transition_type == ui::PAGE_TRANSITION_KEYWORD_GENERATED)) |
typed_increment = 1; |
+ if (!host_ranks_.empty() && visit_source == SOURCE_BROWSED && |
+ (transition & ui::PAGE_TRANSITION_CHAIN_END)) { |
+ RecordTopHostsMetrics(url); |
+ } |
+ |
// See if this URL is already in the DB. |
URLRow url_info(url); |
URLID url_id = db_->GetRowForURL(url, &url_info); |