Chromium Code Reviews| 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" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 using base::TimeTicks; | 25 using base::TimeTicks; |
| 26 using history::HistoryDatabase; | 26 using history::HistoryDatabase; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Number of days to search for full text results. The longer this is, the more | 30 // Number of days to search for full text results. The longer this is, the more |
| 31 // time it will take. | 31 // time it will take. |
| 32 const int kDaysToSearch = 30; | 32 const int kDaysToSearch = 30; |
| 33 | 33 |
| 34 // The maximum number of characters used in a search for full text results. | |
| 35 // This was chosen arbitrarily because omnibox results that come back too | |
| 36 // late (after tens of seconds) aren't useful to the user so it's not | |
| 37 // worth spending CPU time on them. Furthermore, if a URL matches the | |
| 38 // first 10k of characters the user typed (more likely pasted) into the | |
| 39 // omnibox, it's likely it matches the rest; there's strongly diminished | |
| 40 // returns for the ability to add additional search terms. | |
| 41 const size_t kMaxCharactersToConsider = 10000u; | |
|
Peter Kasting
2013/04/17 22:34:57
Even 10K seems like it will take a while. What ab
Mark P
2013/04/17 22:58:22
2k is also okay with me. Done.
| |
| 42 | |
| 34 } // namespace | 43 } // namespace |
| 35 | 44 |
| 36 HistoryContentsProvider::MatchReference::MatchReference( | 45 HistoryContentsProvider::MatchReference::MatchReference( |
| 37 const history::URLResult* result, | 46 const history::URLResult* result, |
| 38 int relevance) | 47 int relevance) |
| 39 : result(result), | 48 : result(result), |
| 40 relevance(relevance) { | 49 relevance(relevance) { |
| 41 } | 50 } |
| 42 | 51 |
| 43 // static | 52 // static |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 HistoryService* history = | 141 HistoryService* history = |
| 133 HistoryServiceFactory::GetForProfile(profile_, | 142 HistoryServiceFactory::GetForProfile(profile_, |
| 134 Profile::EXPLICIT_ACCESS); | 143 Profile::EXPLICIT_ACCESS); |
| 135 if (history) { | 144 if (history) { |
| 136 done_ = false; | 145 done_ = false; |
| 137 | 146 |
| 138 history::QueryOptions options; | 147 history::QueryOptions options; |
| 139 options.body_only = body_only_; | 148 options.body_only = body_only_; |
| 140 options.SetRecentDayRange(kDaysToSearch); | 149 options.SetRecentDayRange(kDaysToSearch); |
| 141 options.max_count = kMaxMatches; | 150 options.max_count = kMaxMatches; |
| 142 history->QueryHistory(input.text(), options, | 151 history->QueryHistory( |
| 152 input.text().substr(0, kMaxCharactersToConsider), | |
| 153 options, | |
| 143 &request_consumer_, | 154 &request_consumer_, |
| 144 base::Bind(&HistoryContentsProvider::QueryComplete, | 155 base::Bind(&HistoryContentsProvider::QueryComplete, |
| 145 base::Unretained(this))); | 156 base::Unretained(this))); |
| 146 } | 157 } |
| 147 } | 158 } |
| 148 } | 159 } |
| 149 | 160 |
| 150 void HistoryContentsProvider::Stop(bool clear_cached_results) { | 161 void HistoryContentsProvider::Stop(bool clear_cached_results) { |
| 151 done_ = true; | 162 done_ = true; |
| 152 request_consumer_.CancelAllRequests(); | 163 request_consumer_.CancelAllRequests(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 276 |
| 266 int HistoryContentsProvider::CalculateRelevance( | 277 int HistoryContentsProvider::CalculateRelevance( |
| 267 const history::URLResult& result) { | 278 const history::URLResult& result) { |
| 268 const bool in_title = MatchInTitle(result); | 279 const bool in_title = MatchInTitle(result); |
| 269 BookmarkModel* bm_model = BookmarkModelFactory::GetForProfile(profile_); | 280 BookmarkModel* bm_model = BookmarkModelFactory::GetForProfile(profile_); |
| 270 if (!bm_model || !bm_model->IsBookmarked(result.url())) | 281 if (!bm_model || !bm_model->IsBookmarked(result.url())) |
| 271 return in_title ? (700 + title_count_++) : (500 + contents_count_++); | 282 return in_title ? (700 + title_count_++) : (500 + contents_count_++); |
| 272 return in_title ? | 283 return in_title ? |
| 273 (1000 + star_title_count_++) : (550 + star_contents_count_++); | 284 (1000 + star_title_count_++) : (550 + star_contents_count_++); |
| 274 } | 285 } |
| OLD | NEW |