| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // This file contains the keyword autocomplete provider. The keyword provider | 5 // This file contains the keyword autocomplete provider. The keyword provider |
| 6 // is responsible for remembering/suggesting user "search keyword queries" | 6 // is responsible for remembering/suggesting user "search keyword queries" |
| 7 // (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An | 7 // (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An |
| 8 // instance of it gets created and managed by the autocomplete controller. | 8 // instance of it gets created and managed by the autocomplete controller. |
| 9 // KeywordProvider uses a TemplateURLService to find the set of keywords. | 9 // KeywordProvider uses a TemplateURLService to find the set of keywords. |
| 10 | 10 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // is valid and has a keyword. This makes use of SplitKeywordFromInput to | 104 // is valid and has a keyword. This makes use of SplitKeywordFromInput to |
| 105 // extract the keyword and remaining string, and uses | 105 // extract the keyword and remaining string, and uses |
| 106 // TemplateURLService::CleanUserInputKeyword to remove unnecessary characters. | 106 // TemplateURLService::CleanUserInputKeyword to remove unnecessary characters. |
| 107 // In general use this instead of SplitKeywordFromInput. | 107 // In general use this instead of SplitKeywordFromInput. |
| 108 // Leading whitespace in |*remaining_input| will be trimmed. | 108 // Leading whitespace in |*remaining_input| will be trimmed. |
| 109 static bool ExtractKeywordFromInput(const AutocompleteInput& input, | 109 static bool ExtractKeywordFromInput(const AutocompleteInput& input, |
| 110 base::string16* keyword, | 110 base::string16* keyword, |
| 111 base::string16* remaining_input); | 111 base::string16* remaining_input); |
| 112 | 112 |
| 113 // Determines the relevance for some input, given its type, whether the user | 113 // Determines the relevance for some input, given its type, whether the user |
| 114 // typed the complete keyword, and whether the user is in "prefer keyword | 114 // typed the complete keyword (or close to it), and whether the user is in |
| 115 // matches" mode, and whether the keyword supports replacement. | 115 // "prefer keyword matches" mode, and whether the keyword supports |
| 116 // If |allow_exact_keyword_match| is false, the relevance for complete | 116 // replacement. If |allow_exact_keyword_match| is false, the relevance for |
| 117 // keywords that support replacements is degraded. | 117 // complete keywords that support replacements is degraded. |
| 118 static int CalculateRelevance(metrics::OmniboxInputType::Type type, | 118 static int CalculateRelevance(metrics::OmniboxInputType::Type type, |
| 119 bool complete, | 119 bool complete, |
| 120 bool sufficiently_complete, |
| 120 bool support_replacement, | 121 bool support_replacement, |
| 121 bool prefer_keyword, | 122 bool prefer_keyword, |
| 122 bool allow_exact_keyword_match); | 123 bool allow_exact_keyword_match); |
| 123 | 124 |
| 124 // Creates a fully marked-up AutocompleteMatch from the user's input. | 125 // Creates a fully marked-up AutocompleteMatch from the user's input. |
| 125 // If |relevance| is negative, calculate a relevance based on heuristics. | 126 // If |relevance| is negative, calculate a relevance based on heuristics. |
| 126 AutocompleteMatch CreateAutocompleteMatch( | 127 AutocompleteMatch CreateAutocompleteMatch( |
| 127 const TemplateURL* template_url, | 128 const TemplateURL* template_url, |
| 129 const size_t meaningful_keyword_length, |
| 128 const AutocompleteInput& input, | 130 const AutocompleteInput& input, |
| 129 size_t prefix_length, | 131 size_t prefix_length, |
| 130 const base::string16& remaining_input, | 132 const base::string16& remaining_input, |
| 131 bool allowed_to_be_default_match, | 133 bool allowed_to_be_default_match, |
| 132 int relevance); | 134 int relevance); |
| 133 | 135 |
| 134 // Fills in the "destination_url" and "contents" fields of |match| with the | 136 // Fills in the "destination_url" and "contents" fields of |match| with the |
| 135 // provided user input and keyword data. | 137 // provided user input and keyword data. |
| 136 void FillInURLAndContents(const base::string16& remaining_input, | 138 void FillInURLAndContents(const base::string16& remaining_input, |
| 137 const TemplateURL* element, | 139 const TemplateURL* element, |
| 138 AutocompleteMatch* match) const; | 140 AutocompleteMatch* match) const; |
| 139 | 141 |
| 140 TemplateURLService* GetTemplateURLService() const; | 142 TemplateURLService* GetTemplateURLService() const; |
| 141 | 143 |
| 142 AutocompleteProviderListener* listener_; | 144 AutocompleteProviderListener* listener_; |
| 143 | 145 |
| 144 // Model for the keywords. | 146 // Model for the keywords. |
| 145 TemplateURLService* model_; | 147 TemplateURLService* model_; |
| 146 | 148 |
| 147 // Delegate to handle the extensions-only logic for KeywordProvider. | 149 // Delegate to handle the extensions-only logic for KeywordProvider. |
| 148 // NULL when extensions are not enabled. May be NULL for tests. | 150 // NULL when extensions are not enabled. May be NULL for tests. |
| 149 scoped_ptr<KeywordExtensionsDelegate> extensions_delegate_; | 151 scoped_ptr<KeywordExtensionsDelegate> extensions_delegate_; |
| 150 | 152 |
| 151 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); | 153 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); |
| 152 }; | 154 }; |
| 153 | 155 |
| 154 #endif // COMPONENTS_OMNIBOX_BROWSER_KEYWORD_PROVIDER_H_ | 156 #endif // COMPONENTS_OMNIBOX_BROWSER_KEYWORD_PROVIDER_H_ |
| OLD | NEW |