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