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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 static const int kSessionCloseTimeWindowSecs = 10; | 96 static const int kSessionCloseTimeWindowSecs = 10; |
97 | 97 |
98 // The maximum number of items we'll allow in the redirect list before | 98 // The maximum number of items we'll allow in the redirect list before |
99 // deleting some. | 99 // deleting some. |
100 static const int kMaxRedirectCount = 32; | 100 static const int kMaxRedirectCount = 32; |
101 | 101 |
102 // The number of days old a history entry can be before it is considered "old" | 102 // The number of days old a history entry can be before it is considered "old" |
103 // and is archived. | 103 // and is archived. |
104 static const int kArchiveDaysThreshold = 90; | 104 static const int kArchiveDaysThreshold = 90; |
105 | 105 |
| 106 #if defined(OS_ANDROID) |
| 107 // The maximum number of top sites to track when recording top page visit stats. |
| 108 static const size_t kPageVisitStatsMaxTopSites = 50; |
| 109 #endif |
| 110 |
106 // Converts from PageUsageData to MostVisitedURL. |redirects| is a | 111 // Converts from PageUsageData to MostVisitedURL. |redirects| is a |
107 // list of redirects for this URL. Empty list means no redirects. | 112 // list of redirects for this URL. Empty list means no redirects. |
108 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, | 113 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, |
109 const RedirectList& redirects) { | 114 const RedirectList& redirects) { |
110 MostVisitedURL mv; | 115 MostVisitedURL mv; |
111 mv.url = page_data.GetURL(); | 116 mv.url = page_data.GetURL(); |
112 mv.title = page_data.GetTitle(); | 117 mv.title = page_data.GetTitle(); |
113 if (redirects.empty()) { | 118 if (redirects.empty()) { |
114 // Redirects must contain at least the target url. | 119 // Redirects must contain at least the target url. |
115 mv.redirects.push_back(mv.url); | 120 mv.redirects.push_back(mv.url); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 #if defined(OS_ANDROID) | 254 #if defined(OS_ANDROID) |
250 file_util::Delete(GetAndroidCacheFileName(), false); | 255 file_util::Delete(GetAndroidCacheFileName(), false); |
251 #endif | 256 #endif |
252 } | 257 } |
253 | 258 |
254 void HistoryBackend::Init(const std::string& languages, bool force_fail) { | 259 void HistoryBackend::Init(const std::string& languages, bool force_fail) { |
255 if (!force_fail) | 260 if (!force_fail) |
256 InitImpl(languages); | 261 InitImpl(languages); |
257 delegate_->DBLoaded(id_); | 262 delegate_->DBLoaded(id_); |
258 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 263 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); |
| 264 #if defined(OS_ANDROID) |
| 265 PopulateMostVisitedURLMap(); |
| 266 #endif |
259 } | 267 } |
260 | 268 |
261 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, | 269 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, |
262 const base::Closure& task) { | 270 const base::Closure& task) { |
263 if (!backend_destroy_task_.is_null()) | 271 if (!backend_destroy_task_.is_null()) |
264 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 272 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
265 backend_destroy_message_loop_ = message_loop; | 273 backend_destroy_message_loop_ = message_loop; |
266 backend_destroy_task_ = task; | 274 backend_destroy_task_ = task; |
267 } | 275 } |
268 | 276 |
(...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 | 801 // TODO(pkasting): http://b/1148304 We shouldn't be marking so many URLs as |
794 // typed, which would eliminate the need for this code. | 802 // typed, which would eliminate the need for this code. |
795 int typed_increment = 0; | 803 int typed_increment = 0; |
796 content::PageTransition transition_type = | 804 content::PageTransition transition_type = |
797 content::PageTransitionStripQualifier(transition); | 805 content::PageTransitionStripQualifier(transition); |
798 if ((transition_type == content::PAGE_TRANSITION_TYPED && | 806 if ((transition_type == content::PAGE_TRANSITION_TYPED && |
799 !content::PageTransitionIsRedirect(transition)) || | 807 !content::PageTransitionIsRedirect(transition)) || |
800 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED) | 808 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED) |
801 typed_increment = 1; | 809 typed_increment = 1; |
802 | 810 |
| 811 #if defined(OS_ANDROID) |
| 812 // Only count the page visit if it came from user browsing and only count it |
| 813 // once when cycling through a redirect chain. |
| 814 if (visit_source == SOURCE_BROWSED && |
| 815 (transition & content::PAGE_TRANSITION_CHAIN_END) != 0) { |
| 816 RecordTopPageVisitStats(url); |
| 817 } |
| 818 #endif |
| 819 |
803 // See if this URL is already in the DB. | 820 // See if this URL is already in the DB. |
804 URLRow url_info(url); | 821 URLRow url_info(url); |
805 URLID url_id = db_->GetRowForURL(url, &url_info); | 822 URLID url_id = db_->GetRowForURL(url, &url_info); |
806 if (url_id) { | 823 if (url_id) { |
807 // Update of an existing row. | 824 // Update of an existing row. |
808 if (content::PageTransitionStripQualifier(transition) != | 825 if (content::PageTransitionStripQualifier(transition) != |
809 content::PAGE_TRANSITION_RELOAD) | 826 content::PAGE_TRANSITION_RELOAD) |
810 url_info.set_visit_count(url_info.visit_count() + 1); | 827 url_info.set_visit_count(url_info.visit_count() + 1); |
811 if (typed_increment) | 828 if (typed_increment) |
812 url_info.set_typed_count(url_info.typed_count() + typed_increment); | 829 url_info.set_typed_count(url_info.typed_count() + typed_increment); |
(...skipping 2254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3067 BriefVisitInfo info; | 3084 BriefVisitInfo info; |
3068 info.url_id = visit.url_id; | 3085 info.url_id = visit.url_id; |
3069 info.time = visit.visit_time; | 3086 info.time = visit.visit_time; |
3070 info.transition = visit.transition; | 3087 info.transition = visit.transition; |
3071 // If we don't have a delegate yet during setup or shutdown, we will drop | 3088 // If we don't have a delegate yet during setup or shutdown, we will drop |
3072 // these notifications. | 3089 // these notifications. |
3073 if (delegate_) | 3090 if (delegate_) |
3074 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3091 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
3075 } | 3092 } |
3076 | 3093 |
| 3094 #if defined(OS_ANDROID) |
| 3095 void HistoryBackend::PopulateMostVisitedURLMap() { |
| 3096 MostVisitedURLList most_visited_urls; |
| 3097 QueryMostVisitedURLsImpl(kPageVisitStatsMaxTopSites, kSegmentDataRetention, |
| 3098 &most_visited_urls); |
| 3099 |
| 3100 DCHECK_LE(most_visited_urls.size(), kPageVisitStatsMaxTopSites); |
| 3101 for (size_t i = 0; i < most_visited_urls.size(); ++i) { |
| 3102 most_visited_urls_map_[most_visited_urls[i].url] = i; |
| 3103 for (size_t j = 0; j < most_visited_urls[i].redirects.size(); ++j) |
| 3104 most_visited_urls_map_[most_visited_urls[i].redirects[j]] = i; |
| 3105 } |
| 3106 } |
| 3107 |
| 3108 void HistoryBackend::RecordTopPageVisitStats(const GURL& url) { |
| 3109 int rank = kPageVisitStatsMaxTopSites; |
| 3110 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
| 3111 if (it != most_visited_urls_map_.end()) |
| 3112 rank = (*it).second; |
| 3113 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
| 3114 rank, kPageVisitStatsMaxTopSites + 1); |
| 3115 } |
| 3116 #endif |
| 3117 |
3077 } // namespace history | 3118 } // namespace history |
OLD | NEW |