OLD | NEW |
---|---|
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 Loading... | |
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 #if defined(OS_ANDROID) | |
61 // The maximum number of top sites to track when recording top page visit stats. | |
62 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.
| |
63 #endif | |
64 | |
65 // Return the rank of the url if it appears in |top_urls| (including within | |
66 // the associated redirect chains) and -1 if not. | |
67 int GetRankOfUrl(const history::MostVisitedURLList& top_urls, | |
68 const GURL& url) { | |
69 DCHECK_LE(top_urls.size(), kPageVisitStatsMaxTopSites); | |
70 for (size_t i = 0; i < top_urls.size(); ++i) { | |
71 if (url == top_urls[i].url) | |
72 return i; | |
73 for (size_t j = 0; j < top_urls[i].redirects.size(); ++j) { | |
74 if (url == top_urls[i].redirects[j]) | |
75 return i; | |
76 } | |
77 } | |
78 return -1; | |
79 } | |
80 | |
81 // Record counts of page visits by rank. If a url is not ranked, record the | |
82 // page visit in a slot corresponding to |max_top_url_count|, which should | |
83 // be one greater than the largest rank of any url in |top_urls|. | |
84 // This can be removed for M31. (See issue 248761.) | |
85 void RecordTopPageVisitStats(const history::MostVisitedURLList& top_urls, | |
86 const GURL& url, | |
87 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.
| |
88 int rank = GetRankOfUrl(top_urls, url); | |
89 if (rank == -1) | |
90 rank = max_top_url_count; | |
91 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | |
92 rank, max_top_url_count + 1); | |
93 } | |
94 | |
95 } // namespace | |
96 #endif | |
97 | |
57 /* The HistoryBackend consists of a number of components: | 98 /* The HistoryBackend consists of a number of components: |
58 | 99 |
59 HistoryDatabase (stores past 3 months of history) | 100 HistoryDatabase (stores past 3 months of history) |
60 URLDatabase (stores a list of URLs) | 101 URLDatabase (stores a list of URLs) |
61 DownloadDatabase (stores a list of downloads) | 102 DownloadDatabase (stores a list of downloads) |
62 VisitDatabase (stores a list of visits for the URLs) | 103 VisitDatabase (stores a list of visits for the URLs) |
63 VisitSegmentDatabase (stores groups of URLs for the most visited view). | 104 VisitSegmentDatabase (stores groups of URLs for the most visited view). |
64 | 105 |
65 ArchivedDatabase (stores history older than 3 months) | 106 ArchivedDatabase (stores history older than 3 months) |
66 URLDatabase (stores a list of URLs) | 107 URLDatabase (stores a list of URLs) |
(...skipping 29 matching lines...) Expand all Loading... | |
96 static const int kSessionCloseTimeWindowSecs = 10; | 137 static const int kSessionCloseTimeWindowSecs = 10; |
97 | 138 |
98 // The maximum number of items we'll allow in the redirect list before | 139 // The maximum number of items we'll allow in the redirect list before |
99 // deleting some. | 140 // deleting some. |
100 static const int kMaxRedirectCount = 32; | 141 static const int kMaxRedirectCount = 32; |
101 | 142 |
102 // The number of days old a history entry can be before it is considered "old" | 143 // The number of days old a history entry can be before it is considered "old" |
103 // and is archived. | 144 // and is archived. |
104 static const int kArchiveDaysThreshold = 90; | 145 static const int kArchiveDaysThreshold = 90; |
105 | 146 |
147 | |
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
| |
106 // Converts from PageUsageData to MostVisitedURL. |redirects| is a | 148 // Converts from PageUsageData to MostVisitedURL. |redirects| is a |
107 // list of redirects for this URL. Empty list means no redirects. | 149 // list of redirects for this URL. Empty list means no redirects. |
108 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, | 150 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, |
109 const RedirectList& redirects) { | 151 const RedirectList& redirects) { |
110 MostVisitedURL mv; | 152 MostVisitedURL mv; |
111 mv.url = page_data.GetURL(); | 153 mv.url = page_data.GetURL(); |
112 mv.title = page_data.GetTitle(); | 154 mv.title = page_data.GetTitle(); |
113 if (redirects.empty()) { | 155 if (redirects.empty()) { |
114 // Redirects must contain at least the target url. | 156 // Redirects must contain at least the target url. |
115 mv.redirects.push_back(mv.url); | 157 mv.redirects.push_back(mv.url); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 #if defined(OS_ANDROID) | 291 #if defined(OS_ANDROID) |
250 file_util::Delete(GetAndroidCacheFileName(), false); | 292 file_util::Delete(GetAndroidCacheFileName(), false); |
251 #endif | 293 #endif |
252 } | 294 } |
253 | 295 |
254 void HistoryBackend::Init(const std::string& languages, bool force_fail) { | 296 void HistoryBackend::Init(const std::string& languages, bool force_fail) { |
255 if (!force_fail) | 297 if (!force_fail) |
256 InitImpl(languages); | 298 InitImpl(languages); |
257 delegate_->DBLoaded(id_); | 299 delegate_->DBLoaded(id_); |
258 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 300 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); |
301 #if defined(OS_ANDROID) | |
302 QueryMostVisitedURLsImpl(kPageVisitStatsMaxTopSites, kSegmentDataRetention, | |
303 &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.
| |
304 #endif | |
259 } | 305 } |
260 | 306 |
261 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, | 307 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, |
262 const base::Closure& task) { | 308 const base::Closure& task) { |
263 if (!backend_destroy_task_.is_null()) | 309 if (!backend_destroy_task_.is_null()) |
264 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 310 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
265 backend_destroy_message_loop_ = message_loop; | 311 backend_destroy_message_loop_ = message_loop; |
266 backend_destroy_task_ = task; | 312 backend_destroy_task_ = task; |
267 } | 313 } |
268 | 314 |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 // TODO(pkasting): http://b/1148304 We shouldn't be marking so many URLs as | 839 // TODO(pkasting): http://b/1148304 We shouldn't be marking so many URLs as |
794 // typed, which would eliminate the need for this code. | 840 // typed, which would eliminate the need for this code. |
795 int typed_increment = 0; | 841 int typed_increment = 0; |
796 content::PageTransition transition_type = | 842 content::PageTransition transition_type = |
797 content::PageTransitionStripQualifier(transition); | 843 content::PageTransitionStripQualifier(transition); |
798 if ((transition_type == content::PAGE_TRANSITION_TYPED && | 844 if ((transition_type == content::PAGE_TRANSITION_TYPED && |
799 !content::PageTransitionIsRedirect(transition)) || | 845 !content::PageTransitionIsRedirect(transition)) || |
800 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED) | 846 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED) |
801 typed_increment = 1; | 847 typed_increment = 1; |
802 | 848 |
849 #if defined(OS_ANDROID) | |
850 // 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.
| |
851 // once when cycling through a redirect chain. | |
852 if (visit_source == SOURCE_BROWSED && | |
853 (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
| |
854 RecordTopPageVisitStats(most_visited_urls_, url, | |
855 kPageVisitStatsMaxTopSites); | |
856 } | |
857 #endif | |
858 | |
803 // See if this URL is already in the DB. | 859 // See if this URL is already in the DB. |
804 URLRow url_info(url); | 860 URLRow url_info(url); |
805 URLID url_id = db_->GetRowForURL(url, &url_info); | 861 URLID url_id = db_->GetRowForURL(url, &url_info); |
806 if (url_id) { | 862 if (url_id) { |
807 // Update of an existing row. | 863 // Update of an existing row. |
808 if (content::PageTransitionStripQualifier(transition) != | 864 if (content::PageTransitionStripQualifier(transition) != |
809 content::PAGE_TRANSITION_RELOAD) | 865 content::PAGE_TRANSITION_RELOAD) |
810 url_info.set_visit_count(url_info.visit_count() + 1); | 866 url_info.set_visit_count(url_info.visit_count() + 1); |
811 if (typed_increment) | 867 if (typed_increment) |
812 url_info.set_typed_count(url_info.typed_count() + typed_increment); | 868 url_info.set_typed_count(url_info.typed_count() + typed_increment); |
(...skipping 2255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3068 info.url_id = visit.url_id; | 3124 info.url_id = visit.url_id; |
3069 info.time = visit.visit_time; | 3125 info.time = visit.visit_time; |
3070 info.transition = visit.transition; | 3126 info.transition = visit.transition; |
3071 // If we don't have a delegate yet during setup or shutdown, we will drop | 3127 // If we don't have a delegate yet during setup or shutdown, we will drop |
3072 // these notifications. | 3128 // these notifications. |
3073 if (delegate_) | 3129 if (delegate_) |
3074 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3130 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
3075 } | 3131 } |
3076 | 3132 |
3077 } // namespace history | 3133 } // namespace history |
OLD | NEW |