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

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: Made UMA-related functions into members 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
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_types.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/history_backend.cc
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 614d93a3bf4747e41f1816dff5f47841464e6e3e..c1c16b22fb2249fe4bd6d4b7905e4bc33e85ee6c 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -103,6 +103,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;
+#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,
@@ -256,6 +261,9 @@ 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)
+ PopulateMostVisitedURLMap();
+#endif
}
void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop,
@@ -800,6 +808,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(url);
+ }
+#endif
+
// See if this URL is already in the DB.
URLRow url_info(url);
URLID url_id = db_->GetRowForURL(url, &url_info);
@@ -3074,4 +3091,28 @@ void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) {
delegate_->NotifyVisitDBObserversOnAddVisit(info);
}
+#if defined(OS_ANDROID)
+void HistoryBackend::PopulateMostVisitedURLMap() {
+ MostVisitedURLList most_visited_urls;
+ QueryMostVisitedURLsImpl(kPageVisitStatsMaxTopSites, kSegmentDataRetention,
+ &most_visited_urls);
+
+ DCHECK_LE(most_visited_urls.size(), kPageVisitStatsMaxTopSites);
+ for (size_t i = 0; i < most_visited_urls.size(); ++i) {
+ most_visited_urls_map_[most_visited_urls[i].url] = i;
+ for (size_t j = 0; j < most_visited_urls[i].redirects.size(); ++j)
+ most_visited_urls_map_[most_visited_urls[i].redirects[j]] = i;
+ }
+}
+
+void HistoryBackend::RecordTopPageVisitStats(const GURL& url) {
+ int rank = kPageVisitStatsMaxTopSites;
+ std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url);
+ if (it != most_visited_urls_map_.end())
+ rank = (*it).second;
+ UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank",
+ rank, kPageVisitStatsMaxTopSites + 1);
+}
+#endif
+
} // namespace history
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698