| 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/history/query_parser.h" | 9 #include "chrome/browser/history/query_parser.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 using history::HistoryDatabase; | 38 using history::HistoryDatabase; |
| 39 | 39 |
| 40 void HistoryContentsProvider::Start(const AutocompleteInput& input, | 40 void HistoryContentsProvider::Start(const AutocompleteInput& input, |
| 41 bool minimal_changes, | 41 bool minimal_changes, |
| 42 bool synchronous_only) { | 42 bool synchronous_only) { |
| 43 matches_.clear(); | 43 matches_.clear(); |
| 44 | 44 |
| 45 if (input.text().empty() || (input.type() == AutocompleteInput::INVALID) || | 45 if (input.text().empty() || (input.type() == AutocompleteInput::INVALID) || |
| 46 // The history service or bookmark bar model must exist. | 46 // The history service or bookmark bar model must exist. |
| 47 !(profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) || | 47 !(profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) || |
| 48 profile_->GetBookmarkBarModel())) { | 48 profile_->GetBookmarkModel())) { |
| 49 Stop(); | 49 Stop(); |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // TODO(pkasting): http://b/888148 We disallow URL input and "URL-like" input | 53 // TODO(pkasting): http://b/888148 We disallow URL input and "URL-like" input |
| 54 // (REQUESTED_URL or UNKNOWN with dots) because we get poor results for it, | 54 // (REQUESTED_URL or UNKNOWN with dots) because we get poor results for it, |
| 55 // but we could get better results if we did better tokenizing instead. | 55 // but we could get better results if we did better tokenizing instead. |
| 56 if ((input.type() == AutocompleteInput::URL) || | 56 if ((input.type() == AutocompleteInput::URL) || |
| 57 (((input.type() == AutocompleteInput::REQUESTED_URL) || | 57 (((input.type() == AutocompleteInput::REQUESTED_URL) || |
| 58 (input.type() == AutocompleteInput::UNKNOWN)) && | 58 (input.type() == AutocompleteInput::UNKNOWN)) && |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // TODO(sky): if matched title highlight matching words in title. | 184 // TODO(sky): if matched title highlight matching words in title. |
| 185 // Also show star in popup. | 185 // Also show star in popup. |
| 186 AutocompleteMatch match(this, score, false); | 186 AutocompleteMatch match(this, score, false); |
| 187 match.fill_into_edit = StringForURLDisplay(result.url(), true); | 187 match.fill_into_edit = StringForURLDisplay(result.url(), true); |
| 188 match.destination_url = UTF8ToWide(result.url().spec()); | 188 match.destination_url = UTF8ToWide(result.url().spec()); |
| 189 match.contents = match.fill_into_edit; | 189 match.contents = match.fill_into_edit; |
| 190 match.contents_class.push_back( | 190 match.contents_class.push_back( |
| 191 ACMatchClassification(0, ACMatchClassification::URL)); | 191 ACMatchClassification(0, ACMatchClassification::URL)); |
| 192 match.description = result.title(); | 192 match.description = result.title(); |
| 193 match.starred = | 193 match.starred = |
| 194 (profile_->GetBookmarkBarModel() && | 194 (profile_->GetBookmarkModel() && |
| 195 profile_->GetBookmarkBarModel()->IsBookmarked(result.url())); | 195 profile_->GetBookmarkModel()->IsBookmarked(result.url())); |
| 196 | 196 |
| 197 ClassifyDescription(result, &match); | 197 ClassifyDescription(result, &match); |
| 198 return match; | 198 return match; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void HistoryContentsProvider::ClassifyDescription( | 201 void HistoryContentsProvider::ClassifyDescription( |
| 202 const history::URLResult& result, | 202 const history::URLResult& result, |
| 203 AutocompleteMatch* match) const { | 203 AutocompleteMatch* match) const { |
| 204 const Snippet::MatchPositions& title_matches = result.title_match_positions(); | 204 const Snippet::MatchPositions& title_matches = result.title_match_positions(); |
| 205 | 205 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 220 if (offset != result.title().size()) { | 220 if (offset != result.title().size()) { |
| 221 match->description_class.push_back( | 221 match->description_class.push_back( |
| 222 ACMatchClassification(offset, ACMatchClassification::NONE)); | 222 ACMatchClassification(offset, ACMatchClassification::NONE)); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 int HistoryContentsProvider::CalculateRelevance( | 226 int HistoryContentsProvider::CalculateRelevance( |
| 227 const history::URLResult& result) { | 227 const history::URLResult& result) { |
| 228 bool in_title = !!result.title_match_positions().size(); | 228 bool in_title = !!result.title_match_positions().size(); |
| 229 bool is_starred = | 229 bool is_starred = |
| 230 (profile_->GetBookmarkBarModel() && | 230 (profile_->GetBookmarkModel() && |
| 231 profile_->GetBookmarkBarModel()->IsBookmarked(result.url())); | 231 profile_->GetBookmarkModel()->IsBookmarked(result.url())); |
| 232 | 232 |
| 233 switch (input_type_) { | 233 switch (input_type_) { |
| 234 case AutocompleteInput::UNKNOWN: | 234 case AutocompleteInput::UNKNOWN: |
| 235 case AutocompleteInput::REQUESTED_URL: | 235 case AutocompleteInput::REQUESTED_URL: |
| 236 if (is_starred) { | 236 if (is_starred) { |
| 237 return in_title ? 1000 + star_title_count_++ : | 237 return in_title ? 1000 + star_title_count_++ : |
| 238 550 + star_contents_count_++; | 238 550 + star_contents_count_++; |
| 239 } else { | 239 } else { |
| 240 return in_title ? 700 + title_count_++ : | 240 return in_title ? 700 + title_count_++ : |
| 241 500 + contents_count_++; | 241 500 + contents_count_++; |
| 242 } | 242 } |
| 243 | 243 |
| 244 case AutocompleteInput::QUERY: | 244 case AutocompleteInput::QUERY: |
| 245 case AutocompleteInput::FORCED_QUERY: | 245 case AutocompleteInput::FORCED_QUERY: |
| 246 if (is_starred) { | 246 if (is_starred) { |
| 247 return in_title ? 1200 + star_title_count_++ : | 247 return in_title ? 1200 + star_title_count_++ : |
| 248 750 + star_contents_count_++; | 248 750 + star_contents_count_++; |
| 249 } else { | 249 } else { |
| 250 return in_title ? 900 + title_count_++ : | 250 return in_title ? 900 + title_count_++ : |
| 251 700 + contents_count_++; | 251 700 + contents_count_++; |
| 252 } | 252 } |
| 253 | 253 |
| 254 default: | 254 default: |
| 255 NOTREACHED(); | 255 NOTREACHED(); |
| 256 return 0; | 256 return 0; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { | 260 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { |
| 261 BookmarkBarModel* bookmark_model = profile_->GetBookmarkBarModel(); | 261 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); |
| 262 if (!bookmark_model) | 262 if (!bookmark_model) |
| 263 return; | 263 return; |
| 264 | 264 |
| 265 DCHECK(results_.size() == 0); // When we get here the results should be | 265 DCHECK(results_.size() == 0); // When we get here the results should be |
| 266 // empty. | 266 // empty. |
| 267 | 267 |
| 268 TimeTicks start_time = TimeTicks::Now(); | 268 TimeTicks start_time = TimeTicks::Now(); |
| 269 std::vector<BookmarkBarModel::TitleMatch> matches; | 269 std::vector<BookmarkModel::TitleMatch> matches; |
| 270 bookmark_model->GetBookmarksMatchingText(input.text(), kMaxMatchCount, | 270 bookmark_model->GetBookmarksMatchingText(input.text(), kMaxMatchCount, |
| 271 &matches); | 271 &matches); |
| 272 for (size_t i = 0; i < matches.size(); ++i) | 272 for (size_t i = 0; i < matches.size(); ++i) |
| 273 AddBookmarkTitleMatchToResults(matches[i]); | 273 AddBookmarkTitleMatchToResults(matches[i]); |
| 274 UMA_HISTOGRAM_TIMES(L"Omnibox.QueryBookmarksTime", | 274 UMA_HISTOGRAM_TIMES(L"Omnibox.QueryBookmarksTime", |
| 275 TimeTicks::Now() - start_time); | 275 TimeTicks::Now() - start_time); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 278 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
| 279 const BookmarkBarModel::TitleMatch& match) { | 279 const BookmarkModel::TitleMatch& match) { |
| 280 history::URLResult url_result(match.node->GetURL(), match.match_positions); | 280 history::URLResult url_result(match.node->GetURL(), match.match_positions); |
| 281 url_result.set_title(match.node->GetTitle()); | 281 url_result.set_title(match.node->GetTitle()); |
| 282 results_.AppendURLBySwapping(&url_result); | 282 results_.AppendURLBySwapping(&url_result); |
| 283 } | 283 } |
| OLD | NEW |