| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/history/query_parser.h" | 10 #include "chrome/browser/history/query_parser.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // (REQUESTED_URL or UNKNOWN with dots) because we get poor results for it, | 64 // (REQUESTED_URL or UNKNOWN with dots) because we get poor results for it, |
| 65 // but we could get better results if we did better tokenizing instead. | 65 // but we could get better results if we did better tokenizing instead. |
| 66 if ((input.type() == AutocompleteInput::URL) || | 66 if ((input.type() == AutocompleteInput::URL) || |
| 67 (((input.type() == AutocompleteInput::REQUESTED_URL) || | 67 (((input.type() == AutocompleteInput::REQUESTED_URL) || |
| 68 (input.type() == AutocompleteInput::UNKNOWN)) && | 68 (input.type() == AutocompleteInput::UNKNOWN)) && |
| 69 (input.text().find('.') != std::wstring::npos))) { | 69 (input.text().find('.') != std::wstring::npos))) { |
| 70 Stop(); | 70 Stop(); |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Change input type and reset relevance counters, so matches will be marked | 74 // Change input type so matches will be marked up properly. |
| 75 // up properly. | |
| 76 input_type_ = input.type(); | 75 input_type_ = input.type(); |
| 77 trim_http_ = !url_util::FindAndCompareScheme(WideToUTF8(input.text()), | 76 trim_http_ = !url_util::FindAndCompareScheme(WideToUTF8(input.text()), |
| 78 chrome::kHttpScheme, NULL); | 77 chrome::kHttpScheme, NULL); |
| 79 star_title_count_ = star_contents_count_ = title_count_ = contents_count_ = 0; | |
| 80 | 78 |
| 81 // Decide what to do about any previous query/results. | 79 // Decide what to do about any previous query/results. |
| 82 if (!minimal_changes) { | 80 if (!minimal_changes) { |
| 83 // Any in-progress request is irrelevant, cancel it. | 81 // Any in-progress request is irrelevant, cancel it. |
| 84 Stop(); | 82 Stop(); |
| 85 } else if (have_results_) { | 83 } else if (have_results_) { |
| 86 // We finished the previous query and still have its results. Mark them up | 84 // We finished the previous query and still have its results. Mark them up |
| 87 // again for the new input. | 85 // again for the new input. |
| 88 ConvertResults(); | 86 ConvertResults(); |
| 89 return; | 87 return; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 results_.AppendResultsBySwapping(results, true); | 141 results_.AppendResultsBySwapping(results, true); |
| 144 have_results_ = true; | 142 have_results_ = true; |
| 145 ConvertResults(); | 143 ConvertResults(); |
| 146 | 144 |
| 147 done_ = true; | 145 done_ = true; |
| 148 if (listener_) | 146 if (listener_) |
| 149 listener_->OnProviderUpdate(!matches_.empty()); | 147 listener_->OnProviderUpdate(!matches_.empty()); |
| 150 } | 148 } |
| 151 | 149 |
| 152 void HistoryContentsProvider::ConvertResults() { | 150 void HistoryContentsProvider::ConvertResults() { |
| 151 // Reset the relevance counters so that result relevance won't vary on |
| 152 // subsequent passes of ConvertResults. |
| 153 star_title_count_ = star_contents_count_ = title_count_ = contents_count_ = 0; |
| 154 |
| 153 // Make the result references and score the results. | 155 // Make the result references and score the results. |
| 154 std::vector<MatchReference> result_refs; | 156 std::vector<MatchReference> result_refs; |
| 155 result_refs.reserve(results_.size()); | 157 result_refs.reserve(results_.size()); |
| 156 for (size_t i = 0; i < results_.size(); i++) { | 158 |
| 157 MatchReference ref(&results_[i], CalculateRelevance(results_[i])); | 159 // Results are sorted in decreasing order so we run the loop backwards so that |
| 160 // the relevance increment favors the higher ranked results. |
| 161 for (std::vector<history::URLResult*>::const_reverse_iterator i = |
| 162 results_.rbegin(); i != results_.rend(); ++i) { |
| 163 history::URLResult* result = *i; |
| 164 MatchReference ref(result, CalculateRelevance(*result)); |
| 158 result_refs.push_back(ref); | 165 result_refs.push_back(ref); |
| 159 } | 166 } |
| 160 | 167 |
| 161 // Get the top matches and add them. Always do max number of matches the popup | 168 // Get the top matches and add them. Always do max number of matches the popup |
| 162 // will show plus one. This ensures that if the other providers provide the | 169 // will show plus one. This ensures that if the other providers provide the |
| 163 // exact same set of results, and the db only has max_matches + 1 results | 170 // exact same set of results, and the db only has max_matches + 1 results |
| 164 // available for this query, we know the last one. | 171 // available for this query, we know the last one. |
| 165 // | 172 // |
| 166 // This is done to avoid having the history search shortcut show | 173 // This is done to avoid having the history search shortcut show |
| 167 // 'See 1 previously viewed ...'. | 174 // 'See 1 previously viewed ...'. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 NOTREACHED(); | 275 NOTREACHED(); |
| 269 return 0; | 276 return 0; |
| 270 } | 277 } |
| 271 } | 278 } |
| 272 | 279 |
| 273 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { | 280 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { |
| 274 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); | 281 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); |
| 275 if (!bookmark_model) | 282 if (!bookmark_model) |
| 276 return; | 283 return; |
| 277 | 284 |
| 278 DCHECK(results_.size() == 0); // When we get here the results should be | 285 DCHECK(results_.empty()); |
| 279 // empty. | |
| 280 | 286 |
| 281 TimeTicks start_time = TimeTicks::Now(); | 287 TimeTicks start_time = TimeTicks::Now(); |
| 282 std::vector<bookmark_utils::TitleMatch> matches; | 288 std::vector<bookmark_utils::TitleMatch> matches; |
| 283 bookmark_model->GetBookmarksWithTitlesMatching(input.text(), max_matches(), | 289 bookmark_model->GetBookmarksWithTitlesMatching(input.text(), max_matches(), |
| 284 &matches); | 290 &matches); |
| 285 for (size_t i = 0; i < matches.size(); ++i) | 291 for (size_t i = 0; i < matches.size(); ++i) |
| 286 AddBookmarkTitleMatchToResults(matches[i]); | 292 AddBookmarkTitleMatchToResults(matches[i]); |
| 287 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", | 293 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", |
| 288 TimeTicks::Now() - start_time); | 294 TimeTicks::Now() - start_time); |
| 289 } | 295 } |
| 290 | 296 |
| 291 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 297 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
| 292 const bookmark_utils::TitleMatch& match) { | 298 const bookmark_utils::TitleMatch& match) { |
| 293 history::URLResult url_result(match.node->GetURL(), match.match_positions); | 299 history::URLResult url_result(match.node->GetURL(), match.match_positions); |
| 294 url_result.set_title(match.node->GetTitle()); | 300 url_result.set_title(match.node->GetTitle()); |
| 295 results_.AppendURLBySwapping(&url_result); | 301 results_.AppendURLBySwapping(&url_result); |
| 296 } | 302 } |
| OLD | NEW |