| 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_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 // | 502 // |
| 503 // We display this to the user when there's a reasonable chance they actually | 503 // We display this to the user when there's a reasonable chance they actually |
| 504 // care: | 504 // care: |
| 505 // * Their input can be opened as a URL, and | 505 // * Their input can be opened as a URL, and |
| 506 // * We parsed the input as a URL, or it starts with an explicit "http:" or | 506 // * We parsed the input as a URL, or it starts with an explicit "http:" or |
| 507 // "https:". | 507 // "https:". |
| 508 // that is when their input can be opened as a URL. | 508 // that is when their input can be opened as a URL. |
| 509 // Otherwise, this is just low-quality noise. In the cases where we've parsed | 509 // Otherwise, this is just low-quality noise. In the cases where we've parsed |
| 510 // as UNKNOWN, we'll still show an accidental search infobar if need be. | 510 // as UNKNOWN, we'll still show an accidental search infobar if need be. |
| 511 bool have_what_you_typed_match = | 511 bool have_what_you_typed_match = |
| 512 params->input.canonicalized_url().is_valid() && | |
| 513 (params->input.type() != AutocompleteInput::QUERY) && | 512 (params->input.type() != AutocompleteInput::QUERY) && |
| 514 ((params->input.type() != AutocompleteInput::UNKNOWN) || | 513 ((params->input.type() != AutocompleteInput::UNKNOWN) || |
| 515 (classifier.type() == VisitClassifier::UNVISITED_INTRANET) || | 514 (classifier.type() == VisitClassifier::UNVISITED_INTRANET) || |
| 516 !params->trim_http || | 515 !params->trim_http || |
| 517 (AutocompleteInput::NumNonHostComponents(params->input.parts()) > 0)); | 516 (AutocompleteInput::NumNonHostComponents(params->input.parts()) > 0)); |
| 518 AutocompleteMatch what_you_typed_match(SuggestExactInput( | 517 AutocompleteMatch what_you_typed_match(SuggestExactInput( |
| 519 params->input.text(), params->input.canonicalized_url(), | 518 params->input.text(), params->input.canonicalized_url(), |
| 520 params->trim_http)); | 519 params->trim_http)); |
| 521 what_you_typed_match.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); | 520 what_you_typed_match.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); |
| 522 | 521 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 if ((input.type() == AutocompleteInput::INVALID) || | 693 if ((input.type() == AutocompleteInput::INVALID) || |
| 695 (input.type() == AutocompleteInput::FORCED_QUERY)) | 694 (input.type() == AutocompleteInput::FORCED_QUERY)) |
| 696 return; | 695 return; |
| 697 | 696 |
| 698 // Create a match for exactly what the user typed. This will only be used as | 697 // Create a match for exactly what the user typed. This will only be used as |
| 699 // a fallback in case we can't get the history service or URL DB; otherwise, | 698 // a fallback in case we can't get the history service or URL DB; otherwise, |
| 700 // we'll run this again in DoAutocomplete() and use that result instead. | 699 // we'll run this again in DoAutocomplete() and use that result instead. |
| 701 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()); | 700 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()); |
| 702 // Don't do this for queries -- while we can sometimes mark up a match for | 701 // Don't do this for queries -- while we can sometimes mark up a match for |
| 703 // this, it's not what the user wants, and just adds noise. | 702 // this, it's not what the user wants, and just adds noise. |
| 704 if ((input.type() != AutocompleteInput::QUERY) && | 703 if (input.type() != AutocompleteInput::QUERY) { |
| 705 input.canonicalized_url().is_valid()) { | |
| 706 AutocompleteMatch what_you_typed(SuggestExactInput( | 704 AutocompleteMatch what_you_typed(SuggestExactInput( |
| 707 input.text(), input.canonicalized_url(), trim_http)); | 705 input.text(), input.canonicalized_url(), trim_http)); |
| 708 what_you_typed.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); | 706 what_you_typed.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); |
| 709 matches_.push_back(what_you_typed); | 707 matches_.push_back(what_you_typed); |
| 710 } | 708 } |
| 711 | 709 |
| 712 // We'll need the history service to run both passes, so try to obtain it. | 710 // We'll need the history service to run both passes, so try to obtain it. |
| 713 if (!profile_) | 711 if (!profile_) |
| 714 return; | 712 return; |
| 715 HistoryService* const history_service = | 713 HistoryService* const history_service = |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 // If HistoryURL retrieves any matches (and hence we reach this code), we | 1156 // If HistoryURL retrieves any matches (and hence we reach this code), we |
| 1159 // are guaranteed that the beginning of input_text must be a word break. | 1157 // are guaranteed that the beginning of input_text must be a word break. |
| 1160 history::WordStarts offsets(1, 0u); | 1158 history::WordStarts offsets(1, 0u); |
| 1161 description_matches = | 1159 description_matches = |
| 1162 history::ScoredHistoryMatch::FilterTermMatchesByWordStarts( | 1160 history::ScoredHistoryMatch::FilterTermMatchesByWordStarts( |
| 1163 description_matches, offsets, description_word_starts, 0, | 1161 description_matches, offsets, description_word_starts, 0, |
| 1164 std::string::npos); | 1162 std::string::npos); |
| 1165 return SpansFromTermMatch( | 1163 return SpansFromTermMatch( |
| 1166 description_matches, clean_description.length(), false); | 1164 description_matches, clean_description.length(), false); |
| 1167 } | 1165 } |
| OLD | NEW |