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 class contains common functionality for search-based autocomplete | 5 // This class contains common functionality for search-based autocomplete |
6 // providers. Search provider and zero suggest provider both use it for common | 6 // providers. Search provider and zero suggest provider both use it for common |
7 // functionality. | 7 // functionality. |
8 | 8 |
9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 static const int kDeletionURLFetcherID; | 50 static const int kDeletionURLFetcherID; |
51 | 51 |
52 BaseSearchProvider(TemplateURLService* template_url_service, | 52 BaseSearchProvider(TemplateURLService* template_url_service, |
53 Profile* profile, | 53 Profile* profile, |
54 AutocompleteProvider::Type type); | 54 AutocompleteProvider::Type type); |
55 | 55 |
56 // Returns whether |match| is flagged as a query that should be prefetched. | 56 // Returns whether |match| is flagged as a query that should be prefetched. |
57 static bool ShouldPrefetch(const AutocompleteMatch& match); | 57 static bool ShouldPrefetch(const AutocompleteMatch& match); |
58 | 58 |
59 // Returns a simpler AutocompleteMatch suitable for persistence like in | 59 // Returns a simpler AutocompleteMatch suitable for persistence like in |
60 // ShortcutsDatabase. | 60 // ShortcutsDatabase. This wrapper function uses a number of default values |
| 61 // that may or may not be appropriate for your needs. |
61 // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion | 62 // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion |
62 // with protected access. | 63 // with protected access. |
63 static AutocompleteMatch CreateSearchSuggestion( | 64 static AutocompleteMatch CreateSearchSuggestion( |
64 const base::string16& suggestion, | 65 const base::string16& suggestion, |
65 AutocompleteMatchType::Type type, | 66 AutocompleteMatchType::Type type, |
66 bool from_keyword_provider, | 67 bool from_keyword_provider, |
67 const TemplateURL* template_url, | 68 const TemplateURL* template_url, |
68 const SearchTermsData& search_terms_data); | 69 const SearchTermsData& search_terms_data); |
69 | 70 |
70 // AutocompleteProvider: | 71 // AutocompleteProvider: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Returns an AutocompleteMatch with the given |autocomplete_provider| | 107 // Returns an AutocompleteMatch with the given |autocomplete_provider| |
107 // for the search |suggestion|, which represents a search via |template_url|. | 108 // for the search |suggestion|, which represents a search via |template_url|. |
108 // If |template_url| is NULL, returns a match with an invalid destination URL. | 109 // If |template_url| is NULL, returns a match with an invalid destination URL. |
109 // | 110 // |
110 // |input| is the original user input. Text in the input is used to highlight | 111 // |input| is the original user input. Text in the input is used to highlight |
111 // portions of the match contents to distinguish locally-typed text from | 112 // portions of the match contents to distinguish locally-typed text from |
112 // suggested text. | 113 // suggested text. |
113 // | 114 // |
114 // |input| is also necessary for various other details, like whether we should | 115 // |input| is also necessary for various other details, like whether we should |
115 // allow inline autocompletion and what the transition type should be. | 116 // allow inline autocompletion and what the transition type should be. |
| 117 // |in_keyword_mode| helps guarantee a non-keyword suggestion does not |
| 118 // appear as the default match when the user is in keyword mode. |
116 // |accepted_suggestion| is used to generate Assisted Query Stats. | 119 // |accepted_suggestion| is used to generate Assisted Query Stats. |
117 // |append_extra_query_params| should be set if |template_url| is the default | 120 // |append_extra_query_params| should be set if |template_url| is the default |
118 // search engine, so the destination URL will contain any | 121 // search engine, so the destination URL will contain any |
119 // command-line-specified query params. | 122 // command-line-specified query params. |
120 static AutocompleteMatch CreateSearchSuggestion( | 123 static AutocompleteMatch CreateSearchSuggestion( |
121 AutocompleteProvider* autocomplete_provider, | 124 AutocompleteProvider* autocomplete_provider, |
122 const AutocompleteInput& input, | 125 const AutocompleteInput& input, |
| 126 const bool in_keyword_mode, |
123 const SearchSuggestionParser::SuggestResult& suggestion, | 127 const SearchSuggestionParser::SuggestResult& suggestion, |
124 const TemplateURL* template_url, | 128 const TemplateURL* template_url, |
125 const SearchTermsData& search_terms_data, | 129 const SearchTermsData& search_terms_data, |
126 int accepted_suggestion, | 130 int accepted_suggestion, |
127 bool append_extra_query_params); | 131 bool append_extra_query_params); |
128 | 132 |
129 // Returns whether the requirements for requesting zero suggest results | 133 // Returns whether the requirements for requesting zero suggest results |
130 // are met. The requirements are | 134 // are met. The requirements are |
131 // * The user is enrolled in a zero suggest experiment. | 135 // * The user is enrolled in a zero suggest experiment. |
132 // * The user is not on the NTP. | 136 // * The user is not on the NTP. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // the key |kDeletionUrlKey|. | 177 // the key |kDeletionUrlKey|. |
174 void SetDeletionURL(const std::string& deletion_url, | 178 void SetDeletionURL(const std::string& deletion_url, |
175 AutocompleteMatch* match); | 179 AutocompleteMatch* match); |
176 | 180 |
177 // Creates an AutocompleteMatch from |result| to search for the query in | 181 // Creates an AutocompleteMatch from |result| to search for the query in |
178 // |result|. Adds the created match to |map|; if such a match | 182 // |result|. Adds the created match to |map|; if such a match |
179 // already exists, whichever one has lower relevance is eliminated. | 183 // already exists, whichever one has lower relevance is eliminated. |
180 // |metadata| and |accepted_suggestion| are used for generating an | 184 // |metadata| and |accepted_suggestion| are used for generating an |
181 // AutocompleteMatch. | 185 // AutocompleteMatch. |
182 // |mark_as_deletable| indicates whether the match should be marked deletable. | 186 // |mark_as_deletable| indicates whether the match should be marked deletable. |
| 187 // |in_keyword_mode| helps guarantee a non-keyword suggestion does not |
| 188 // appear as the default match when the user is in keyword mode. |
183 // NOTE: Any result containing a deletion URL is always marked deletable. | 189 // NOTE: Any result containing a deletion URL is always marked deletable. |
184 void AddMatchToMap(const SearchSuggestionParser::SuggestResult& result, | 190 void AddMatchToMap(const SearchSuggestionParser::SuggestResult& result, |
185 const std::string& metadata, | 191 const std::string& metadata, |
186 int accepted_suggestion, | 192 int accepted_suggestion, |
187 bool mark_as_deletable, | 193 bool mark_as_deletable, |
| 194 bool in_keyword_mode, |
188 MatchMap* map); | 195 MatchMap* map); |
189 | 196 |
190 // Parses results from the suggest server and updates the appropriate suggest | 197 // Parses results from the suggest server and updates the appropriate suggest |
191 // and navigation result lists in |results|. |default_result_relevance| is | 198 // and navigation result lists in |results|. |default_result_relevance| is |
192 // the relevance to use if it was not explicitly set by the server. | 199 // the relevance to use if it was not explicitly set by the server. |
193 // |is_keyword_result| indicates whether the response was received from the | 200 // |is_keyword_result| indicates whether the response was received from the |
194 // keyword provider. | 201 // keyword provider. |
195 // Returns whether the appropriate result list members were updated. | 202 // Returns whether the appropriate result list members were updated. |
196 bool ParseSuggestResults(const base::Value& root_val, | 203 bool ParseSuggestResults(const base::Value& root_val, |
197 int default_result_relevance, | 204 int default_result_relevance, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 260 |
254 // Each deletion handler in this vector corresponds to an outstanding request | 261 // Each deletion handler in this vector corresponds to an outstanding request |
255 // that a server delete a personalized suggestion. Making this a ScopedVector | 262 // that a server delete a personalized suggestion. Making this a ScopedVector |
256 // causes us to auto-cancel all such requests on shutdown. | 263 // causes us to auto-cancel all such requests on shutdown. |
257 SuggestionDeletionHandlers deletion_handlers_; | 264 SuggestionDeletionHandlers deletion_handlers_; |
258 | 265 |
259 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); | 266 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); |
260 }; | 267 }; |
261 | 268 |
262 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 269 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
OLD | NEW |