OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 Stop(); | 75 Stop(); |
76 return; | 76 return; |
77 } | 77 } |
78 | 78 |
79 // TODO(pkasting): http://b/888148 We disallow URL input and "URL-like" input | 79 // TODO(pkasting): http://b/888148 We disallow URL input and "URL-like" input |
80 // (REQUESTED_URL or UNKNOWN with dots) because we get poor results for it, | 80 // (REQUESTED_URL or UNKNOWN with dots) because we get poor results for it, |
81 // but we could get better results if we did better tokenizing instead. | 81 // but we could get better results if we did better tokenizing instead. |
82 if ((input.type() == AutocompleteInput::URL) || | 82 if ((input.type() == AutocompleteInput::URL) || |
83 (((input.type() == AutocompleteInput::REQUESTED_URL) || | 83 (((input.type() == AutocompleteInput::REQUESTED_URL) || |
84 (input.type() == AutocompleteInput::UNKNOWN)) && | 84 (input.type() == AutocompleteInput::UNKNOWN)) && |
85 (input.text().find('.') != std::wstring::npos))) { | 85 (input.text().find('.') != string16::npos))) { |
86 Stop(); | 86 Stop(); |
87 return; | 87 return; |
88 } | 88 } |
89 | 89 |
90 // Change input type so matches will be marked up properly. | 90 // Change input type so matches will be marked up properly. |
91 input_type_ = input.type(); | 91 input_type_ = input.type(); |
92 trim_http_ = !HasHTTPScheme(input.text()); | 92 trim_http_ = !HasHTTPScheme(input.text()); |
93 | 93 |
94 // Decide what to do about any previous query/results. | 94 // Decide what to do about any previous query/results. |
95 if (!minimal_changes) { | 95 if (!minimal_changes) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 if (!input.synchronous_only()) { | 128 if (!input.synchronous_only()) { |
129 HistoryService* history = | 129 HistoryService* history = |
130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
131 if (history) { | 131 if (history) { |
132 done_ = false; | 132 done_ = false; |
133 | 133 |
134 history::QueryOptions options; | 134 history::QueryOptions options; |
135 options.SetRecentDayRange(kDaysToSearch); | 135 options.SetRecentDayRange(kDaysToSearch); |
136 options.max_count = kMaxMatches; | 136 options.max_count = kMaxMatches; |
137 history->QueryHistory(WideToUTF16(input.text()), options, | 137 history->QueryHistory(input.text(), options, |
138 &request_consumer_, | 138 &request_consumer_, |
139 NewCallback(this, &HistoryContentsProvider::QueryComplete)); | 139 NewCallback(this, &HistoryContentsProvider::QueryComplete)); |
140 } | 140 } |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 void HistoryContentsProvider::Stop() { | 144 void HistoryContentsProvider::Stop() { |
145 done_ = true; | 145 done_ = true; |
146 request_consumer_.CancelAllRequests(); | 146 request_consumer_.CancelAllRequests(); |
147 | 147 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // Also show star in popup. | 205 // Also show star in popup. |
206 AutocompleteMatch match(this, score, true, MatchInTitle(result) ? | 206 AutocompleteMatch match(this, score, true, MatchInTitle(result) ? |
207 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); | 207 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); |
208 match.contents = StringForURLDisplay(result.url(), true, trim_http_); | 208 match.contents = StringForURLDisplay(result.url(), true, trim_http_); |
209 match.fill_into_edit = | 209 match.fill_into_edit = |
210 AutocompleteInput::FormattedStringWithEquivalentMeaning(result.url(), | 210 AutocompleteInput::FormattedStringWithEquivalentMeaning(result.url(), |
211 match.contents); | 211 match.contents); |
212 match.destination_url = result.url(); | 212 match.destination_url = result.url(); |
213 match.contents_class.push_back( | 213 match.contents_class.push_back( |
214 ACMatchClassification(0, ACMatchClassification::URL)); | 214 ACMatchClassification(0, ACMatchClassification::URL)); |
215 match.description = UTF16ToWide(result.title()); | 215 match.description = result.title(); |
216 match.starred = | 216 match.starred = |
217 (profile_->GetBookmarkModel() && | 217 (profile_->GetBookmarkModel() && |
218 profile_->GetBookmarkModel()->IsBookmarked(result.url())); | 218 profile_->GetBookmarkModel()->IsBookmarked(result.url())); |
219 | 219 |
220 ClassifyDescription(result, &match); | 220 ClassifyDescription(result, &match); |
221 return match; | 221 return match; |
222 } | 222 } |
223 | 223 |
224 void HistoryContentsProvider::ClassifyDescription( | 224 void HistoryContentsProvider::ClassifyDescription( |
225 const history::URLResult& result, | 225 const history::URLResult& result, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { | 259 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { |
260 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); | 260 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); |
261 if (!bookmark_model) | 261 if (!bookmark_model) |
262 return; | 262 return; |
263 | 263 |
264 DCHECK(results_.empty()); | 264 DCHECK(results_.empty()); |
265 | 265 |
266 TimeTicks start_time = TimeTicks::Now(); | 266 TimeTicks start_time = TimeTicks::Now(); |
267 std::vector<bookmark_utils::TitleMatch> matches; | 267 std::vector<bookmark_utils::TitleMatch> matches; |
268 bookmark_model->GetBookmarksWithTitlesMatching(WideToUTF16Hack(input.text()), | 268 bookmark_model->GetBookmarksWithTitlesMatching(input.text(), |
269 kMaxMatches, &matches); | 269 kMaxMatches, &matches); |
270 for (size_t i = 0; i < matches.size(); ++i) | 270 for (size_t i = 0; i < matches.size(); ++i) |
271 AddBookmarkTitleMatchToResults(matches[i]); | 271 AddBookmarkTitleMatchToResults(matches[i]); |
272 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", | 272 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", |
273 TimeTicks::Now() - start_time); | 273 TimeTicks::Now() - start_time); |
274 } | 274 } |
275 | 275 |
276 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 276 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
277 const bookmark_utils::TitleMatch& match) { | 277 const bookmark_utils::TitleMatch& match) { |
278 history::URLResult url_result(match.node->GetURL(), match.match_positions); | 278 history::URLResult url_result(match.node->GetURL(), match.match_positions); |
279 url_result.set_title(match.node->GetTitle()); | 279 url_result.set_title(match.node->GetTitle()); |
280 results_.AppendURLBySwapping(&url_result); | 280 results_.AppendURLBySwapping(&url_result); |
281 } | 281 } |
OLD | NEW |