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

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 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 // Return the rank of the url if it appears in |top_urls| (including within
brettw 2013/06/11 18:28:16 Style: blank line before here, don't indent namesp
bengr 2013/06/11 23:47:57 Done.
60 // the associated redirect chains) and -1 if not.
61 int GetRankOfUrl(const history::MostVisitedURLList& top_urls,
62 const GURL& url) {
63 for (size_t i = 0; i < top_urls.size(); ++i) {
64 if (url == top_urls[i].url)
65 return i;
66 for (size_t j = 0; j < top_urls[i].redirects.size(); ++j) {
67 if (url == top_urls[i].redirects[j])
68 return i;
69 }
70 }
71 return -1;
72 }
73
74 // Record counts of page visits by rank. If a url is not ranked, record the
75 // page visit in a slot corresponding to |max_top_url_count|, which should
76 // be one greater than the largest rank of any url in |top_urls|.
77 void RecordTopPageVisitStats(const history::MostVisitedURLList& top_urls,
78 const GURL& url, int max_top_url_count) {
79 int rank = GetRankOfUrl(top_urls, url);
80 if (rank == -1)
81 rank = max_top_url_count;
82 UMA_HISTOGRAM_COUNTS("History.TopSitesVisitsByRank", rank);
83 }
84 } // namespace
brettw 2013/06/11 18:28:16 Blank line before here.
bengr 2013/06/11 23:47:57 Done.
85 #endif
86
57 /* The HistoryBackend consists of a number of components: 87 /* The HistoryBackend consists of a number of components:
58 88
59 HistoryDatabase (stores past 3 months of history) 89 HistoryDatabase (stores past 3 months of history)
60 URLDatabase (stores a list of URLs) 90 URLDatabase (stores a list of URLs)
61 DownloadDatabase (stores a list of downloads) 91 DownloadDatabase (stores a list of downloads)
62 VisitDatabase (stores a list of visits for the URLs) 92 VisitDatabase (stores a list of visits for the URLs)
63 VisitSegmentDatabase (stores groups of URLs for the most visited view). 93 VisitSegmentDatabase (stores groups of URLs for the most visited view).
64 94
65 ArchivedDatabase (stores history older than 3 months) 95 ArchivedDatabase (stores history older than 3 months)
66 URLDatabase (stores a list of URLs) 96 URLDatabase (stores a list of URLs)
(...skipping 29 matching lines...) Expand all
96 static const int kSessionCloseTimeWindowSecs = 10; 126 static const int kSessionCloseTimeWindowSecs = 10;
97 127
98 // The maximum number of items we'll allow in the redirect list before 128 // The maximum number of items we'll allow in the redirect list before
99 // deleting some. 129 // deleting some.
100 static const int kMaxRedirectCount = 32; 130 static const int kMaxRedirectCount = 32;
101 131
102 // The number of days old a history entry can be before it is considered "old" 132 // The number of days old a history entry can be before it is considered "old"
103 // and is archived. 133 // and is archived.
104 static const int kArchiveDaysThreshold = 90; 134 static const int kArchiveDaysThreshold = 90;
105 135
136 #if defined(OS_ANDROID)
137 static const size_t kMaxTopSites = 50;
brettw 2013/06/11 18:28:16 Can this have a name more specific to your metrics
bengr 2013/06/11 23:47:57 Done.
138 #endif
139
106 // Converts from PageUsageData to MostVisitedURL. |redirects| is a 140 // Converts from PageUsageData to MostVisitedURL. |redirects| is a
107 // list of redirects for this URL. Empty list means no redirects. 141 // list of redirects for this URL. Empty list means no redirects.
108 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, 142 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data,
109 const RedirectList& redirects) { 143 const RedirectList& redirects) {
110 MostVisitedURL mv; 144 MostVisitedURL mv;
111 mv.url = page_data.GetURL(); 145 mv.url = page_data.GetURL();
112 mv.title = page_data.GetTitle(); 146 mv.title = page_data.GetTitle();
113 if (redirects.empty()) { 147 if (redirects.empty()) {
114 // Redirects must contain at least the target url. 148 // Redirects must contain at least the target url.
115 mv.redirects.push_back(mv.url); 149 mv.redirects.push_back(mv.url);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 #if defined(OS_ANDROID) 327 #if defined(OS_ANDROID)
294 file_util::Delete(GetAndroidCacheFileName(), false); 328 file_util::Delete(GetAndroidCacheFileName(), false);
295 #endif 329 #endif
296 } 330 }
297 331
298 void HistoryBackend::Init(const std::string& languages, bool force_fail) { 332 void HistoryBackend::Init(const std::string& languages, bool force_fail) {
299 if (!force_fail) 333 if (!force_fail)
300 InitImpl(languages); 334 InitImpl(languages);
301 delegate_->DBLoaded(id_); 335 delegate_->DBLoaded(id_);
302 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); 336 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this));
337 #if defined(OS_ANDROID)
338 QueryMostVisitedURLsImpl(kMaxTopSites, kSegmentDataRetention,
339 &most_visited_urls_);
340 #endif
303 } 341 }
304 342
305 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, 343 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop,
306 const base::Closure& task) { 344 const base::Closure& task) {
307 if (!backend_destroy_task_.is_null()) 345 if (!backend_destroy_task_.is_null())
308 DLOG(WARNING) << "Setting more than one destroy task, overriding"; 346 DLOG(WARNING) << "Setting more than one destroy task, overriding";
309 backend_destroy_message_loop_ = message_loop; 347 backend_destroy_message_loop_ = message_loop;
310 backend_destroy_task_ = task; 348 backend_destroy_task_ = task;
311 } 349 }
312 350
(...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 875 // TODO(pkasting): http://b/1148304 We shouldn't be marking so many URLs as
838 // typed, which would eliminate the need for this code. 876 // typed, which would eliminate the need for this code.
839 int typed_increment = 0; 877 int typed_increment = 0;
840 content::PageTransition transition_type = 878 content::PageTransition transition_type =
841 content::PageTransitionStripQualifier(transition); 879 content::PageTransitionStripQualifier(transition);
842 if ((transition_type == content::PAGE_TRANSITION_TYPED && 880 if ((transition_type == content::PAGE_TRANSITION_TYPED &&
843 !content::PageTransitionIsRedirect(transition)) || 881 !content::PageTransitionIsRedirect(transition)) ||
844 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED) 882 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED)
845 typed_increment = 1; 883 typed_increment = 1;
846 884
885 #if defined(OS_ANDROID)
886 // Only count the page visit if it came from user browsing and only count it
887 // once when cycling through a redirect chain.
888 if (visit_source == SOURCE_BROWSED &&
889 (transition & content::PAGE_TRANSITION_CHAIN_END) != 0)
brettw 2013/06/11 18:28:16 If you want only the last one, then this code shou
bengr 2013/06/11 23:47:57 If I understand the code, AddPage calls this AddPa
890 RecordTopPageVisitStats(most_visited_urls_, url, kMaxTopSites);
891 // TODO(bengr): check referrer as well.
brettw 2013/06/11 18:28:16 This TODO doesn't make any sense to me. Either rem
bengr 2013/06/11 23:47:57 Done.
892 #endif
893
847 // See if this URL is already in the DB. 894 // See if this URL is already in the DB.
848 URLRow url_info(url); 895 URLRow url_info(url);
849 URLID url_id = db_->GetRowForURL(url, &url_info); 896 URLID url_id = db_->GetRowForURL(url, &url_info);
850 if (url_id) { 897 if (url_id) {
851 // Update of an existing row. 898 // Update of an existing row.
852 if (content::PageTransitionStripQualifier(transition) != 899 if (content::PageTransitionStripQualifier(transition) !=
853 content::PAGE_TRANSITION_RELOAD) 900 content::PAGE_TRANSITION_RELOAD)
854 url_info.set_visit_count(url_info.visit_count() + 1); 901 url_info.set_visit_count(url_info.visit_count() + 1);
855 if (typed_increment) 902 if (typed_increment)
856 url_info.set_typed_count(url_info.typed_count() + typed_increment); 903 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; 3145 info.url_id = visit.url_id;
3099 info.time = visit.visit_time; 3146 info.time = visit.visit_time;
3100 info.transition = visit.transition; 3147 info.transition = visit.transition;
3101 // If we don't have a delegate yet during setup or shutdown, we will drop 3148 // If we don't have a delegate yet during setup or shutdown, we will drop
3102 // these notifications. 3149 // these notifications.
3103 if (delegate_) 3150 if (delegate_)
3104 delegate_->NotifyVisitDBObserversOnAddVisit(info); 3151 delegate_->NotifyVisitDBObserversOnAddVisit(info);
3105 } 3152 }
3106 3153
3107 } // namespace history 3154 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698