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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "sql/error_delegate_util.h" 47 #include "sql/error_delegate_util.h"
48 48
49 #if defined(OS_ANDROID) 49 #if defined(OS_ANDROID)
50 #include "chrome/browser/history/android/android_provider_backend.h" 50 #include "chrome/browser/history/android/android_provider_backend.h"
51 #endif 51 #endif
52 52
53 using base::Time; 53 using base::Time;
54 using base::TimeDelta; 54 using base::TimeDelta;
55 using base::TimeTicks; 55 using base::TimeTicks;
56 56
57 #if defined(OS_ANDROID)
58 namespace {
59
60 // Return the rank of the url if it appears in |top_urls| (including within
61 // the associated redirect chains) and -1 if not.
62 int GetRankOfUrl(const history::MostVisitedURLList& top_urls,
63 const GURL& url) {
64 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.
65 if (url == top_urls[i].url)
66 return i;
67 for (size_t j = 0; j < top_urls[i].redirects.size(); ++j) {
68 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
69 return i;
70 }
71 }
72 return -1;
73 }
74
75 // Record counts of page visits by rank. If a url is not ranked, record the
76 // page visit in a slot corresponding to |max_top_url_count|, which should
77 // be one greater than the largest rank of any url in |top_urls|.
78 // This can be removed for M31. (See issue 248761.)
79 void RecordTopPageVisitStats(const history::MostVisitedURLList& top_urls,
80 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.
81 int rank = GetRankOfUrl(top_urls, url);
82 if (rank == -1)
83 rank = max_top_url_count;
84 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.
85 }
86
87 } // namespace
88 #endif
89
57 /* The HistoryBackend consists of a number of components: 90 /* The HistoryBackend consists of a number of components:
58 91
59 HistoryDatabase (stores past 3 months of history) 92 HistoryDatabase (stores past 3 months of history)
60 URLDatabase (stores a list of URLs) 93 URLDatabase (stores a list of URLs)
61 DownloadDatabase (stores a list of downloads) 94 DownloadDatabase (stores a list of downloads)
62 VisitDatabase (stores a list of visits for the URLs) 95 VisitDatabase (stores a list of visits for the URLs)
63 VisitSegmentDatabase (stores groups of URLs for the most visited view). 96 VisitSegmentDatabase (stores groups of URLs for the most visited view).
64 97
65 ArchivedDatabase (stores history older than 3 months) 98 ArchivedDatabase (stores history older than 3 months)
66 URLDatabase (stores a list of URLs) 99 URLDatabase (stores a list of URLs)
(...skipping 29 matching lines...) Expand all
96 static const int kSessionCloseTimeWindowSecs = 10; 129 static const int kSessionCloseTimeWindowSecs = 10;
97 130
98 // The maximum number of items we'll allow in the redirect list before 131 // The maximum number of items we'll allow in the redirect list before
99 // deleting some. 132 // deleting some.
100 static const int kMaxRedirectCount = 32; 133 static const int kMaxRedirectCount = 32;
101 134
102 // The number of days old a history entry can be before it is considered "old" 135 // The number of days old a history entry can be before it is considered "old"
103 // and is archived. 136 // and is archived.
104 static const int kArchiveDaysThreshold = 90; 137 static const int kArchiveDaysThreshold = 90;
105 138
139 #if defined(OS_ANDROID)
140 // The maximum number of top sites to track when recording top page visit stats.
141 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/
142 #endif
143
106 // Converts from PageUsageData to MostVisitedURL. |redirects| is a 144 // Converts from PageUsageData to MostVisitedURL. |redirects| is a
107 // list of redirects for this URL. Empty list means no redirects. 145 // list of redirects for this URL. Empty list means no redirects.
108 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, 146 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data,
109 const RedirectList& redirects) { 147 const RedirectList& redirects) {
110 MostVisitedURL mv; 148 MostVisitedURL mv;
111 mv.url = page_data.GetURL(); 149 mv.url = page_data.GetURL();
112 mv.title = page_data.GetTitle(); 150 mv.title = page_data.GetTitle();
113 if (redirects.empty()) { 151 if (redirects.empty()) {
114 // Redirects must contain at least the target url. 152 // Redirects must contain at least the target url.
115 mv.redirects.push_back(mv.url); 153 mv.redirects.push_back(mv.url);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 #if defined(OS_ANDROID) 331 #if defined(OS_ANDROID)
294 file_util::Delete(GetAndroidCacheFileName(), false); 332 file_util::Delete(GetAndroidCacheFileName(), false);
295 #endif 333 #endif
296 } 334 }
297 335
298 void HistoryBackend::Init(const std::string& languages, bool force_fail) { 336 void HistoryBackend::Init(const std::string& languages, bool force_fail) {
299 if (!force_fail) 337 if (!force_fail)
300 InitImpl(languages); 338 InitImpl(languages);
301 delegate_->DBLoaded(id_); 339 delegate_->DBLoaded(id_);
302 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); 340 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this));
341 #if defined(OS_ANDROID)
342 QueryMostVisitedURLsImpl(kPageVisitStatsMaxTopSites, kSegmentDataRetention,
343 &most_visited_urls_);
344 #endif
303 } 345 }
304 346
305 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, 347 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop,
306 const base::Closure& task) { 348 const base::Closure& task) {
307 if (!backend_destroy_task_.is_null()) 349 if (!backend_destroy_task_.is_null())
308 DLOG(WARNING) << "Setting more than one destroy task, overriding"; 350 DLOG(WARNING) << "Setting more than one destroy task, overriding";
309 backend_destroy_message_loop_ = message_loop; 351 backend_destroy_message_loop_ = message_loop;
310 backend_destroy_task_ = task; 352 backend_destroy_task_ = task;
311 } 353 }
312 354
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 // TODO(pkasting): http://b/1148304 We shouldn't be marking so many URLs as 879 // TODO(pkasting): http://b/1148304 We shouldn't be marking so many URLs as
838 // typed, which would eliminate the need for this code. 880 // typed, which would eliminate the need for this code.
839 int typed_increment = 0; 881 int typed_increment = 0;
840 content::PageTransition transition_type = 882 content::PageTransition transition_type =
841 content::PageTransitionStripQualifier(transition); 883 content::PageTransitionStripQualifier(transition);
842 if ((transition_type == content::PAGE_TRANSITION_TYPED && 884 if ((transition_type == content::PAGE_TRANSITION_TYPED &&
843 !content::PageTransitionIsRedirect(transition)) || 885 !content::PageTransitionIsRedirect(transition)) ||
844 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED) 886 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED)
845 typed_increment = 1; 887 typed_increment = 1;
846 888
889 #if defined(OS_ANDROID)
890 // Only count the page visit if it came from user browsing and only count it
891 // once when cycling through a redirect chain.
892 if (visit_source == SOURCE_BROWSED &&
893 (transition & content::PAGE_TRANSITION_CHAIN_END) != 0)
894 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.
895 kPageVisitStatsMaxTopSites);
896 #endif
897
847 // See if this URL is already in the DB. 898 // See if this URL is already in the DB.
848 URLRow url_info(url); 899 URLRow url_info(url);
849 URLID url_id = db_->GetRowForURL(url, &url_info); 900 URLID url_id = db_->GetRowForURL(url, &url_info);
850 if (url_id) { 901 if (url_id) {
851 // Update of an existing row. 902 // Update of an existing row.
852 if (content::PageTransitionStripQualifier(transition) != 903 if (content::PageTransitionStripQualifier(transition) !=
853 content::PAGE_TRANSITION_RELOAD) 904 content::PAGE_TRANSITION_RELOAD)
854 url_info.set_visit_count(url_info.visit_count() + 1); 905 url_info.set_visit_count(url_info.visit_count() + 1);
855 if (typed_increment) 906 if (typed_increment)
856 url_info.set_typed_count(url_info.typed_count() + typed_increment); 907 url_info.set_typed_count(url_info.typed_count() + typed_increment);
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after
3098 info.url_id = visit.url_id; 3149 info.url_id = visit.url_id;
3099 info.time = visit.visit_time; 3150 info.time = visit.visit_time;
3100 info.transition = visit.transition; 3151 info.transition = visit.transition;
3101 // If we don't have a delegate yet during setup or shutdown, we will drop 3152 // If we don't have a delegate yet during setup or shutdown, we will drop
3102 // these notifications. 3153 // these notifications.
3103 if (delegate_) 3154 if (delegate_)
3104 delegate_->NotifyVisitDBObserversOnAddVisit(info); 3155 delegate_->NotifyVisitDBObserversOnAddVisit(info);
3105 } 3156 }
3106 3157
3107 } // namespace history 3158 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698