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..7ab8709cf5acfbe2f05ed6f718edbd42bbff6d8b 100644 |
| --- a/chrome/browser/history/history_backend.cc |
| +++ b/chrome/browser/history/history_backend.cc |
| @@ -54,6 +54,43 @@ using base::Time; |
| using base::TimeDelta; |
| using base::TimeTicks; |
| +#if defined(OS_ANDROID) |
| +namespace { |
| + |
| +// The maximum number of top sites to track when recording top page visit stats. |
| +const size_t kPageVisitStatsMaxTopSites = 50; |
| + |
| +// Populate a map from a |MostVisitedURLList|. The map assigns a rank to each |
| +// top URL and its redirects. This should only be done once at backend |
| +// initialization. |
| +void PopulateMostVisitedURLMap(const history::MostVisitedURLList& top_urls, |
| + std::map<GURL, int>& top_urls_map) { |
|
jar (doing other things)
2013/06/19 00:49:58
nit: Pass in the pointer to modify the map, rather
bengr
2013/06/19 17:44:24
Done.
|
| + DCHECK_LE(top_urls.size(), kPageVisitStatsMaxTopSites); |
| + for (size_t i = 0; i < top_urls.size(); ++i) { |
| + top_urls_map[top_urls[i].url] = i; |
| + for (size_t j = 0; j < top_urls[i].redirects.size(); ++j) |
| + top_urls_map[top_urls[i].redirects[j]] = i; |
| + } |
| +} |
| + |
| +// 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 std::map<GURL, int>& top_urls_map, |
| + const GURL& url) { |
| + int rank = kPageVisitStatsMaxTopSites; |
| + std::map<GURL, int>::const_iterator it = top_urls_map.find(url); |
| + if (it != top_urls_map.end()) |
| + rank = (*it).second; |
| + LOG(WARNING) << "XXX rank " << rank << " url: " << url.spec(); |
|
jar (doing other things)
2013/06/19 00:49:58
Generally we use DLOG, so that we don't swell up t
bengr
2013/06/19 17:44:24
Thanks for catching this. It was some logging left
|
| + UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
| + rank, kPageVisitStatsMaxTopSites + 1); |
| +} |
| + |
| +} // namespace |
| +#endif |
| + |
| /* The HistoryBackend consists of a number of components: |
| HistoryDatabase (stores past 3 months of history) |
| @@ -103,6 +140,7 @@ static const int kMaxRedirectCount = 32; |
| // and is archived. |
| static const int kArchiveDaysThreshold = 90; |
| + |
| // 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 +294,12 @@ 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) |
| + MostVisitedURLList most_visited_urls; |
| + QueryMostVisitedURLsImpl(kPageVisitStatsMaxTopSites, kSegmentDataRetention, |
| + &most_visited_urls); |
| + PopulateMostVisitedURLMap(most_visited_urls, most_visited_urls_map_); |
| +#endif |
| } |
| void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, |
| @@ -800,6 +844,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_map_, url); |
| + } |
| +#endif |
| + |
| // See if this URL is already in the DB. |
| URLRow url_info(url); |
| URLID url_id = db_->GetRowForURL(url, &url_info); |