Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Unified Diff: components/history/core/browser/history_backend.cc

Issue 1179953005: Add History.TopHostsVisitsByRank UMA metric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@is_allowed
Patch Set: Use HistogramTester to eliminate test brittleness. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
« no previous file with comments | « components/history/core/browser/history_backend.h ('k') | components/history/core/browser/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698