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

Unified Diff: chrome/browser/history/history_backend.cc

Issue 16517002: Track fraction of visits to top URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added more detail to histogram description. Created 7 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: chrome/browser/history/history_backend.cc
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 26a51d0ab59e2f7b82fcefe85aced76798561b01..6a8ffb0b967ee54733663a89b26592bf5d888e31 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -54,6 +54,39 @@ using base::Time;
using base::TimeDelta;
using base::TimeTicks;
+#if defined(OS_ANDROID)
+namespace {
+
+// Return the rank of the url if it appears in |top_urls| (including within
+// the associated redirect chains) and -1 if not.
+int GetRankOfUrl(const history::MostVisitedURLList& top_urls,
+ const GURL& url) {
+ for (size_t i = 0; i < top_urls.size(); ++i) {
jar (doing other things) 2013/06/17 22:58:14 nit: How about at least not searching beyond max_t
bengr 2013/06/17 23:46:59 Done.
+ if (url == top_urls[i].url)
+ return i;
+ for (size_t j = 0; j < top_urls[i].redirects.size(); ++j) {
+ if (url == top_urls[i].redirects[j])
jar (doing other things) 2013/06/17 22:58:14 I'm not sure how long these chains are.... but are
bengr 2013/06/17 23:46:59 From a random sampling of top sites, I'm seeing ch
jar (doing other things) 2013/06/18 00:51:34 This histogram will be hardly anything in performa
+ return i;
+ }
+ }
+ return -1;
+}
+
+// Record counts of page visits by rank. If a url is not ranked, record the
+// page visit in a slot corresponding to |max_top_url_count|, which should
+// be one greater than the largest rank of any url in |top_urls|.
+// This can be removed for M31. (See issue 248761.)
+void RecordTopPageVisitStats(const history::MostVisitedURLList& top_urls,
+ const GURL& url, int max_top_url_count) {
jar (doing other things) 2013/06/17 22:58:14 nit: one arg per line in declaration and definitio
bengr 2013/06/17 23:46:59 Done.
+ int rank = GetRankOfUrl(top_urls, url);
+ if (rank == -1)
+ rank = max_top_url_count;
+ UMA_HISTOGRAM_COUNTS("History.TopSitesVisitsByRank", rank);
jar (doing other things) 2013/06/17 22:58:14 Better would be to use: UMA_HISTOGRAM_ENUMERATION(
bengr 2013/06/17 23:46:59 Done.
+}
+
+} // namespace
+#endif
+
/* The HistoryBackend consists of a number of components:
HistoryDatabase (stores past 3 months of history)
@@ -103,6 +136,11 @@ static const int kMaxRedirectCount = 32;
// and is archived.
static const int kArchiveDaysThreshold = 90;
+#if defined(OS_ANDROID)
+// The maximum number of top sites to track when recording top page visit stats.
+static const size_t kPageVisitStatsMaxTopSites = 50;
jar (doing other things) 2013/06/17 22:58:14 nit: (even though I like statics at file scope...)
bengr 2013/06/17 23:46:59 I moved just my constant to the top. On 2013/06/
+#endif
+
// 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,
@@ -300,6 +338,10 @@ void HistoryBackend::Init(const std::string& languages, bool force_fail) {
InitImpl(languages);
delegate_->DBLoaded(id_);
typed_url_syncable_service_.reset(new TypedUrlSyncableService(this));
+#if defined(OS_ANDROID)
+ QueryMostVisitedURLsImpl(kPageVisitStatsMaxTopSites, kSegmentDataRetention,
+ &most_visited_urls_);
+#endif
}
void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop,
@@ -844,6 +886,15 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED)
typed_increment = 1;
+#if defined(OS_ANDROID)
+ // Only count the page visit if it came from user browsing and only count it
+ // once when cycling through a redirect chain.
+ if (visit_source == SOURCE_BROWSED &&
+ (transition & content::PAGE_TRANSITION_CHAIN_END) != 0)
+ RecordTopPageVisitStats(most_visited_urls_, url,
jar (doing other things) 2013/06/17 22:58:14 nit: use curlies around any if action that runs on
bengr 2013/06/17 23:46:59 Done.
+ kPageVisitStatsMaxTopSites);
+#endif
+
// See if this URL is already in the DB.
URLRow url_info(url);
URLID url_id = db_->GetRowForURL(url, &url_info);

Powered by Google App Engine
This is Rietveld 408576698