Chromium Code Reviews| 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..1a4ca313b7d27d00c71ed10a9dcaf5fb09445c5f 100644 |
| --- a/chrome/browser/history/history_backend.cc |
| +++ b/chrome/browser/history/history_backend.cc |
| @@ -54,6 +54,47 @@ using base::Time; |
| using base::TimeDelta; |
| using base::TimeTicks; |
| +#if defined(OS_ANDROID) |
| +namespace { |
| + |
| +#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/18 00:51:34
nit: no need to for static, now that you're in the
bengr
2013/06/18 18:43:37
Done.
|
| +#endif |
| + |
| +// 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) { |
| + DCHECK_LE(top_urls.size(), kPageVisitStatsMaxTopSites); |
| + for (size_t i = 0; i < top_urls.size(); ++i) { |
| + 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]) |
| + 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/18 00:51:34
Why is this now passed as an argument, rather than
bengr
2013/06/18 18:43:37
Done.
|
| + int rank = GetRankOfUrl(top_urls, url); |
| + if (rank == -1) |
| + rank = max_top_url_count; |
| + UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
| + rank, max_top_url_count + 1); |
| +} |
| + |
| +} // namespace |
| +#endif |
| + |
| /* The HistoryBackend consists of a number of components: |
| HistoryDatabase (stores past 3 months of history) |
| @@ -103,6 +144,7 @@ static const int kMaxRedirectCount = 32; |
| // and is archived. |
| static const int kArchiveDaysThreshold = 90; |
| + |
|
jar (doing other things)
2013/06/18 00:51:34
nit: How about coming these constants up to the to
bengr
2013/06/18 18:43:37
The histogram code I've added is temporary and onc
jar (doing other things)
2013/06/19 00:49:58
When editing files, it is always good to clean (mi
|
| // 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 +298,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_); |
|
jar (doing other things)
2013/06/18 00:51:34
Is this done exactly once per process run? If so,
bengr
2013/06/18 18:43:37
Done.
|
| +#endif |
| } |
| void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, |
| @@ -800,6 +846,16 @@ 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 |
|
jar (doing other things)
2013/06/18 00:51:34
Please indicate this in your histograms.xml prose.
bengr
2013/06/18 18:43:37
Done.
|
| + // once when cycling through a redirect chain. |
| + if (visit_source == SOURCE_BROWSED && |
| + (transition & content::PAGE_TRANSITION_CHAIN_END) != 0) { |
|
jar (doing other things)
2013/06/18 00:51:34
It is interesting that you *only* check if we're a
bengr
2013/06/18 18:43:37
Let's say the user commonly follows a redirect cha
jar (doing other things)
2013/06/19 00:49:58
If there is a redirect chain... I sure hope it is
brettw
2013/06/19 19:10:27
Redirect chains should be ordered by time, so if i
bengr
2013/06/19 19:42:58
Good to know. I've switched over to using a map, s
|
| + RecordTopPageVisitStats(most_visited_urls_, url, |
| + kPageVisitStatsMaxTopSites); |
| + } |
| +#endif |
| + |
| // See if this URL is already in the DB. |
| URLRow url_info(url); |
| URLID url_id = db_->GetRowForURL(url, &url_info); |