| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); | 687 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); |
| 688 int did_not_accept_default_suggestion = | 688 int did_not_accept_default_suggestion = |
| 689 default_results_.suggest_results.empty() ? | 689 default_results_.suggest_results.empty() ? |
| 690 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 690 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
| 691 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 691 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
| 692 if (verbatim_relevance > 0) { | 692 if (verbatim_relevance > 0) { |
| 693 const base::string16& trimmed_verbatim = | 693 const base::string16& trimmed_verbatim = |
| 694 base::CollapseWhitespace(input_.text(), false); | 694 base::CollapseWhitespace(input_.text(), false); |
| 695 SuggestResult verbatim( | 695 SuggestResult verbatim( |
| 696 trimmed_verbatim, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 696 trimmed_verbatim, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 697 trimmed_verbatim, base::string16(), base::string16(), std::string(), | 697 trimmed_verbatim, base::string16(), base::string16(), base::string16(), |
| 698 std::string(), false, verbatim_relevance, relevance_from_server, false, | 698 base::string16(), std::string(), std::string(), false, |
| 699 verbatim_relevance, relevance_from_server, false, |
| 699 trimmed_verbatim); | 700 trimmed_verbatim); |
| 700 AddMatchToMap(verbatim, std::string(), did_not_accept_default_suggestion, | 701 AddMatchToMap(verbatim, std::string(), did_not_accept_default_suggestion, |
| 701 false, &map); | 702 false, &map); |
| 702 } | 703 } |
| 703 if (!keyword_input_.text().empty()) { | 704 if (!keyword_input_.text().empty()) { |
| 704 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 705 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
| 705 // We only create the verbatim search query match for a keyword | 706 // We only create the verbatim search query match for a keyword |
| 706 // if it's not an extension keyword. Extension keywords are handled | 707 // if it's not an extension keyword. Extension keywords are handled |
| 707 // in KeywordProvider::Start(). (Extensions are complicated...) | 708 // in KeywordProvider::Start(). (Extensions are complicated...) |
| 708 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond | 709 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond |
| 709 // to the keyword verbatim search query. Do not create other matches | 710 // to the keyword verbatim search query. Do not create other matches |
| 710 // of type SEARCH_OTHER_ENGINE. | 711 // of type SEARCH_OTHER_ENGINE. |
| 711 if (keyword_url && | 712 if (keyword_url && |
| 712 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { | 713 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 713 bool keyword_relevance_from_server; | 714 bool keyword_relevance_from_server; |
| 714 const int keyword_verbatim_relevance = | 715 const int keyword_verbatim_relevance = |
| 715 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); | 716 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); |
| 716 if (keyword_verbatim_relevance > 0) { | 717 if (keyword_verbatim_relevance > 0) { |
| 717 const base::string16& trimmed_verbatim = | 718 const base::string16& trimmed_verbatim = |
| 718 base::CollapseWhitespace(keyword_input_.text(), false); | 719 base::CollapseWhitespace(keyword_input_.text(), false); |
| 719 SuggestResult verbatim( | 720 SuggestResult verbatim( |
| 720 trimmed_verbatim, AutocompleteMatchType::SEARCH_OTHER_ENGINE, | 721 trimmed_verbatim, AutocompleteMatchType::SEARCH_OTHER_ENGINE, |
| 721 trimmed_verbatim, base::string16(), base::string16(), | 722 trimmed_verbatim, base::string16(), base::string16(), |
| 722 std::string(), std::string(), true, keyword_verbatim_relevance, | 723 base::string16(), base::string16(), std::string(), std::string(), |
| 723 keyword_relevance_from_server, false, trimmed_verbatim); | 724 true, keyword_verbatim_relevance, keyword_relevance_from_server, |
| 725 false, trimmed_verbatim); |
| 724 AddMatchToMap(verbatim, std::string(), | 726 AddMatchToMap(verbatim, std::string(), |
| 725 did_not_accept_keyword_suggestion, false, &map); | 727 did_not_accept_keyword_suggestion, false, &map); |
| 726 } | 728 } |
| 727 } | 729 } |
| 728 } | 730 } |
| 729 AddHistoryResultsToMap(keyword_history_results_, true, | 731 AddHistoryResultsToMap(keyword_history_results_, true, |
| 730 did_not_accept_keyword_suggestion, &map); | 732 did_not_accept_keyword_suggestion, &map); |
| 731 AddHistoryResultsToMap(default_history_results_, false, | 733 AddHistoryResultsToMap(default_history_results_, false, |
| 732 did_not_accept_default_suggestion, &map); | 734 did_not_accept_default_suggestion, &map); |
| 733 | 735 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 input_.current_page_classification(), &match, NULL); | 917 input_.current_page_classification(), &match, NULL); |
| 916 prevent_inline_autocomplete = | 918 prevent_inline_autocomplete = |
| 917 !AutocompleteMatch::IsSearchType(match.type); | 919 !AutocompleteMatch::IsSearchType(match.type); |
| 918 } | 920 } |
| 919 | 921 |
| 920 int relevance = CalculateRelevanceForHistory( | 922 int relevance = CalculateRelevanceForHistory( |
| 921 i->time, is_keyword, !prevent_inline_autocomplete, | 923 i->time, is_keyword, !prevent_inline_autocomplete, |
| 922 prevent_search_history_inlining); | 924 prevent_search_history_inlining); |
| 923 scored_results.push_back(SuggestResult( | 925 scored_results.push_back(SuggestResult( |
| 924 trimmed_suggestion, AutocompleteMatchType::SEARCH_HISTORY, | 926 trimmed_suggestion, AutocompleteMatchType::SEARCH_HISTORY, |
| 925 trimmed_suggestion, base::string16(), base::string16(), std::string(), | 927 trimmed_suggestion, base::string16(), base::string16(), |
| 926 std::string(), is_keyword, relevance, false, false, trimmed_input)); | 928 base::string16(), base::string16(), std::string(), std::string(), |
| 929 is_keyword, relevance, false, false, trimmed_input)); |
| 927 } | 930 } |
| 928 | 931 |
| 929 // History returns results sorted for us. However, we may have docked some | 932 // History returns results sorted for us. However, we may have docked some |
| 930 // results' scores, so things are no longer in order. Do a stable sort to get | 933 // results' scores, so things are no longer in order. Do a stable sort to get |
| 931 // things back in order without otherwise disturbing results with equal | 934 // things back in order without otherwise disturbing results with equal |
| 932 // scores, then force the scores to be unique, so that the order in which | 935 // scores, then force the scores to be unique, so that the order in which |
| 933 // they're shown is deterministic. | 936 // they're shown is deterministic. |
| 934 std::stable_sort(scored_results.begin(), scored_results.end(), | 937 std::stable_sort(scored_results.begin(), scored_results.end(), |
| 935 CompareScoredResults()); | 938 CompareScoredResults()); |
| 936 int last_relevance = 0; | 939 int last_relevance = 0; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 std::string raw_data; | 1147 std::string raw_data; |
| 1145 base::RandBytes(WriteInto(&raw_data, kTokenBytes + 1), kTokenBytes); | 1148 base::RandBytes(WriteInto(&raw_data, kTokenBytes + 1), kTokenBytes); |
| 1146 base::Base64Encode(raw_data, ¤t_token_); | 1149 base::Base64Encode(raw_data, ¤t_token_); |
| 1147 } | 1150 } |
| 1148 | 1151 |
| 1149 // Extend expiration time another 60 seconds. | 1152 // Extend expiration time another 60 seconds. |
| 1150 token_expiration_time_ = current_time + base::TimeDelta::FromSeconds(60); | 1153 token_expiration_time_ = current_time + base::TimeDelta::FromSeconds(60); |
| 1151 | 1154 |
| 1152 return current_token_; | 1155 return current_token_; |
| 1153 } | 1156 } |
| OLD | NEW |