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/autocomplete/history_contents_provider.h" | 5 #include "chrome/browser/autocomplete/history_contents_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
13 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 13 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/search_engines/template_url.h" | 18 #include "chrome/browser/search_engines/template_url.h" |
19 #include "chrome/browser/search_engines/template_url_service.h" | 19 #include "chrome/browser/search_engines/template_url_service.h" |
20 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "googleurl/src/url_util.h" | 22 #include "googleurl/src/url_util.h" |
23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
24 | 24 |
25 using base::TimeTicks; | 25 using base::TimeTicks; |
26 using history::HistoryDatabase; | 26 using history::HistoryDatabase; |
27 | 27 |
28 namespace { | |
29 | |
30 // Number of days to search for full text results. The longer this is, the more | |
31 // time it will take. | |
32 const int kDaysToSearch = 30; | |
33 | |
34 } // namespace | |
35 | |
36 HistoryContentsProvider::MatchReference::MatchReference( | 28 HistoryContentsProvider::MatchReference::MatchReference( |
37 const history::URLResult* result, | 29 const history::URLResult* result, |
38 int relevance) | 30 int relevance) |
39 : result(result), | 31 : result(result), |
40 relevance(relevance) { | 32 relevance(relevance) { |
41 } | 33 } |
42 | 34 |
43 // static | 35 // static |
44 bool HistoryContentsProvider::MatchReference::CompareRelevance( | 36 bool HistoryContentsProvider::MatchReference::CompareRelevance( |
45 const HistoryContentsProvider::MatchReference& lhs, | 37 const HistoryContentsProvider::MatchReference& lhs, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 results_.Swap(&empty_results); | 120 results_.Swap(&empty_results); |
129 } | 121 } |
130 | 122 |
131 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { | 123 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { |
132 HistoryService* history = | 124 HistoryService* history = |
133 HistoryServiceFactory::GetForProfile(profile_, | 125 HistoryServiceFactory::GetForProfile(profile_, |
134 Profile::EXPLICIT_ACCESS); | 126 Profile::EXPLICIT_ACCESS); |
135 if (history) { | 127 if (history) { |
136 done_ = false; | 128 done_ = false; |
137 | 129 |
| 130 // Number of days to search for full text results. The longer |
| 131 // this is, the more time it will take. |
| 132 const int kDaysToSearch = 30; |
| 133 |
| 134 // The maximum number of characters used in a search for full |
| 135 // text results. This was chosen arbitrarily because omnibox |
| 136 // results that come back too late (after tens of seconds) |
| 137 // aren't useful to the user so it's not worth spending CPU time |
| 138 // on them. Furthermore, if a URL matches the first 2k of |
| 139 // characters the user typed (more likely pasted) into the |
| 140 // omnibox, it's likely it matches the rest; there's strongly |
| 141 // diminished returns for the ability to add additional search |
| 142 // terms. |
| 143 const size_t kMaxCharactersToConsider = 2000u; |
| 144 |
138 history::QueryOptions options; | 145 history::QueryOptions options; |
139 options.body_only = body_only_; | 146 options.body_only = body_only_; |
140 options.SetRecentDayRange(kDaysToSearch); | 147 options.SetRecentDayRange(kDaysToSearch); |
141 options.max_count = kMaxMatches; | 148 options.max_count = kMaxMatches; |
142 history->QueryHistory(input.text(), options, | 149 history->QueryHistory( |
| 150 input.text().substr(0, kMaxCharactersToConsider), |
| 151 options, |
143 &request_consumer_, | 152 &request_consumer_, |
144 base::Bind(&HistoryContentsProvider::QueryComplete, | 153 base::Bind(&HistoryContentsProvider::QueryComplete, |
145 base::Unretained(this))); | 154 base::Unretained(this))); |
146 } | 155 } |
147 } | 156 } |
148 } | 157 } |
149 | 158 |
150 void HistoryContentsProvider::Stop(bool clear_cached_results) { | 159 void HistoryContentsProvider::Stop(bool clear_cached_results) { |
151 done_ = true; | 160 done_ = true; |
152 request_consumer_.CancelAllRequests(); | 161 request_consumer_.CancelAllRequests(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 274 |
266 int HistoryContentsProvider::CalculateRelevance( | 275 int HistoryContentsProvider::CalculateRelevance( |
267 const history::URLResult& result) { | 276 const history::URLResult& result) { |
268 const bool in_title = MatchInTitle(result); | 277 const bool in_title = MatchInTitle(result); |
269 BookmarkModel* bm_model = BookmarkModelFactory::GetForProfile(profile_); | 278 BookmarkModel* bm_model = BookmarkModelFactory::GetForProfile(profile_); |
270 if (!bm_model || !bm_model->IsBookmarked(result.url())) | 279 if (!bm_model || !bm_model->IsBookmarked(result.url())) |
271 return in_title ? (700 + title_count_++) : (500 + contents_count_++); | 280 return in_title ? (700 + title_count_++) : (500 + contents_count_++); |
272 return in_title ? | 281 return in_title ? |
273 (1000 + star_title_count_++) : (550 + star_contents_count_++); | 282 (1000 + star_title_count_++) : (550 + star_contents_count_++); |
274 } | 283 } |
OLD | NEW |