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 // This file contains the Search autocomplete provider. This provider is | 5 // This file contains the Search autocomplete provider. This provider is |
6 // responsible for all autocomplete entries that start with "Search <engine> | 6 // responsible for all autocomplete entries that start with "Search <engine> |
7 // for ...", including searching for the current input string, search | 7 // for ...", including searching for the current input string, search |
8 // history, and search suggestions. An instance of it gets created and | 8 // history, and search suggestions. An instance of it gets created and |
9 // managed by the autocomplete controller. | 9 // managed by the autocomplete controller. |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 static const int kDefaultProviderURLFetcherID; | 50 static const int kDefaultProviderURLFetcherID; |
51 | 51 |
52 // ID used in creating URLFetcher for keyword provider's suggest results. | 52 // ID used in creating URLFetcher for keyword provider's suggest results. |
53 static const int kKeywordProviderURLFetcherID; | 53 static const int kKeywordProviderURLFetcherID; |
54 | 54 |
55 // ID used in creating URLFetcher for deleting suggestion results. | 55 // ID used in creating URLFetcher for deleting suggestion results. |
56 static const int kDeletionURLFetcherID; | 56 static const int kDeletionURLFetcherID; |
57 | 57 |
58 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); | 58 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); |
59 | 59 |
60 // Returns whether the SearchProvider previously flagged |match| as a query | |
61 // that should be prefetched. | |
62 static bool ShouldPrefetch(const AutocompleteMatch& match); | |
63 | |
64 // Extracts the suggest response metadata which SearchProvider previously | 60 // Extracts the suggest response metadata which SearchProvider previously |
65 // stored for |match|. | 61 // stored for |match|. |
66 static std::string GetSuggestMetadata(const AutocompleteMatch& match); | 62 static std::string GetSuggestMetadata(const AutocompleteMatch& match); |
67 | 63 |
68 // AutocompleteProvider: | 64 // AutocompleteProvider: |
69 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 65 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
70 virtual void ResetSession() OVERRIDE; | 66 virtual void ResetSession() OVERRIDE; |
71 | 67 |
72 // This URL may be sent with suggest requests; see comments on CanSendURL(). | 68 // This URL may be sent with suggest requests; see comments on CanSendURL(). |
73 void set_current_page_url(const GURL& current_page_url) { | 69 void set_current_page_url(const GURL& current_page_url) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 bool prefer_keyword); | 156 bool prefer_keyword); |
161 | 157 |
162 // AutocompleteProvider: | 158 // AutocompleteProvider: |
163 virtual void Start(const AutocompleteInput& input, | 159 virtual void Start(const AutocompleteInput& input, |
164 bool minimal_changes) OVERRIDE; | 160 bool minimal_changes) OVERRIDE; |
165 virtual void Stop(bool clear_cached_results) OVERRIDE; | 161 virtual void Stop(bool clear_cached_results) OVERRIDE; |
166 | 162 |
167 // net::URLFetcherDelegate: | 163 // net::URLFetcherDelegate: |
168 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 164 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
169 | 165 |
166 // BaseSearchProvider: | |
167 virtual bool ShouldAppendExtraParams( | |
168 const SuggestResult& result) const OVERRIDE; | |
169 | |
170 // This gets called when we have requested a suggestion deletion from the | 170 // This gets called when we have requested a suggestion deletion from the |
171 // server to handle the results of the deletion. | 171 // server to handle the results of the deletion. |
172 void OnDeletionComplete(bool success, | 172 void OnDeletionComplete(bool success, |
173 SuggestionDeletionHandler* handler); | 173 SuggestionDeletionHandler* handler); |
174 | 174 |
175 // Records in UMA whether the deletion request resulted in success. | 175 // Records in UMA whether the deletion request resulted in success. |
176 // This is virtual so test code can override it to check that we | 176 // This is virtual so test code can override it to check that we |
177 // correctly handle the request result. | 177 // correctly handle the request result. |
178 virtual void RecordDeletionResult(bool success); | 178 virtual void RecordDeletionResult(bool success); |
179 | 179 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 bool base_prevent_inline_autocomplete, | 269 bool base_prevent_inline_autocomplete, |
270 bool input_multiple_words, | 270 bool input_multiple_words, |
271 const base::string16& input_text, | 271 const base::string16& input_text, |
272 bool is_keyword); | 272 bool is_keyword); |
273 | 273 |
274 // Adds matches for |results| to |map|. | 274 // Adds matches for |results| to |map|. |
275 void AddSuggestResultsToMap(const SuggestResults& results, | 275 void AddSuggestResultsToMap(const SuggestResults& results, |
276 const std::string& metadata, | 276 const std::string& metadata, |
277 MatchMap* map); | 277 MatchMap* map); |
278 | 278 |
279 // Returns the AutocompleteInput object corresponding to the given |result|. | |
Mark P
2014/02/12 23:35:49
Can we try a comment that makes it clearer most pr
Maria
2014/02/13 21:07:36
I decided to change this to take is_keyword instea
| |
280 const AutocompleteInput GetInput(const SuggestResult& result) const; | |
281 | |
282 // Returns the TemplateURL used to search for the |result|. | |
283 const TemplateURL* GetTemplateURL(const SuggestResult& result) const; | |
H Fung
2014/02/13 01:43:33
Maybe consider moving this into BaseSearchProvider
msw
2014/02/13 02:43:50
+1
Maria
2014/02/13 21:07:36
Done.
| |
284 | |
279 // Gets the relevance score for the verbatim result. This value may be | 285 // Gets the relevance score for the verbatim result. This value may be |
280 // provided by the suggest server or calculated locally; if | 286 // provided by the suggest server or calculated locally; if |
281 // |relevance_from_server| is non-NULL, it will be set to indicate which of | 287 // |relevance_from_server| is non-NULL, it will be set to indicate which of |
282 // those is true. | 288 // those is true. |
283 int GetVerbatimRelevance(bool* relevance_from_server) const; | 289 int GetVerbatimRelevance(bool* relevance_from_server) const; |
284 | 290 |
285 // Calculates the relevance score for the verbatim result from the | 291 // Calculates the relevance score for the verbatim result from the |
286 // default search engine. This version takes into account context: | 292 // default search engine. This version takes into account context: |
287 // i.e., whether the user has entered a keyword-based search or not. | 293 // i.e., whether the user has entered a keyword-based search or not. |
288 int CalculateRelevanceForVerbatim() const; | 294 int CalculateRelevanceForVerbatim() const; |
(...skipping 16 matching lines...) Expand all Loading... | |
305 // indicates whether the results correspond to the keyword provider or default | 311 // indicates whether the results correspond to the keyword provider or default |
306 // provider. |use_aggressive_method| says whether this function can use a | 312 // provider. |use_aggressive_method| says whether this function can use a |
307 // method that gives high scores (1200+) rather than one that gives lower | 313 // method that gives high scores (1200+) rather than one that gives lower |
308 // scores. When using the aggressive method, scores may exceed 1300 | 314 // scores. When using the aggressive method, scores may exceed 1300 |
309 // unless |prevent_search_history_inlining| is set. | 315 // unless |prevent_search_history_inlining| is set. |
310 int CalculateRelevanceForHistory(const base::Time& time, | 316 int CalculateRelevanceForHistory(const base::Time& time, |
311 bool is_keyword, | 317 bool is_keyword, |
312 bool use_aggressive_method, | 318 bool use_aggressive_method, |
313 bool prevent_search_history_inlining) const; | 319 bool prevent_search_history_inlining) const; |
314 | 320 |
315 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with | |
316 // the supplied details. Adds this match to |map|; if such a match already | |
317 // exists, whichever one has lower relevance is eliminated. | |
318 void AddMatchToMap(const SuggestResult& result, | |
319 const base::string16& input_text, | |
320 const std::string& metadata, | |
321 int accepted_suggestion, | |
322 MatchMap* map); | |
323 | |
324 // Returns an AutocompleteMatch for a navigational suggestion. | 321 // Returns an AutocompleteMatch for a navigational suggestion. |
325 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); | 322 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); |
326 | 323 |
327 // Resets the scores of all |keyword_navigation_results_| matches to | 324 // Resets the scores of all |keyword_navigation_results_| matches to |
328 // be below that of the top keyword query match (the verbatim match | 325 // be below that of the top keyword query match (the verbatim match |
329 // as expressed by |keyword_verbatim_relevance_| or keyword query | 326 // as expressed by |keyword_verbatim_relevance_| or keyword query |
330 // suggestions stored in |keyword_suggest_results_|). If there | 327 // suggestions stored in |keyword_suggest_results_|). If there |
331 // are no keyword suggestions and keyword verbatim is suppressed, | 328 // are no keyword suggestions and keyword verbatim is suppressed, |
332 // then drops the suggested relevance scores for the navsuggestions | 329 // then drops the suggested relevance scores for the navsuggestions |
333 // and drops the request to suppress verbatim, thereby introducing the | 330 // and drops the request to suppress verbatim, thereby introducing the |
334 // keyword verbatim match which will naturally outscore the navsuggestions. | 331 // keyword verbatim match which will naturally outscore the navsuggestions. |
335 void DemoteKeywordNavigationMatchesPastTopQuery(); | 332 void DemoteKeywordNavigationMatchesPastTopQuery(); |
336 | 333 |
337 // Updates the value of |done_| from the internal state. | 334 // Updates the value of |done_| from the internal state. |
338 void UpdateDone(); | 335 void UpdateDone(); |
339 | 336 |
340 // The amount of time to wait before sending a new suggest request after the | 337 // The amount of time to wait before sending a new suggest request after the |
341 // previous one. Non-const because some unittests modify this value. | 338 // previous one. Non-const because some unittests modify this value. |
342 static int kMinimumTimeBetweenSuggestQueriesMs; | 339 static int kMinimumTimeBetweenSuggestQueriesMs; |
343 | 340 |
344 // The following keys are used to record additional information on matches. | |
345 | |
346 // We annotate our AutocompleteMatches with whether their relevance scores | |
347 // were server-provided using this key in the |additional_info| field. | |
348 static const char kRelevanceFromServerKey[]; | |
349 | |
350 // Indicates whether the server said a match should be prefetched. | |
351 static const char kShouldPrefetchKey[]; | |
352 | |
353 // Used to store metadata from the server response, which is needed for | |
354 // prefetching. | |
355 static const char kSuggestMetadataKey[]; | |
356 | |
357 // Used to store a deletion request url for server-provided suggestions. | |
358 static const char kDeletionUrlKey[]; | |
359 | |
360 // These are the values for the above keys. | |
361 static const char kTrue[]; | |
362 static const char kFalse[]; | |
363 | |
364 // Maintains the TemplateURLs used. | 341 // Maintains the TemplateURLs used. |
365 Providers providers_; | 342 Providers providers_; |
366 | 343 |
367 // The user's input. | 344 // The user's input. |
368 AutocompleteInput input_; | 345 AutocompleteInput input_; |
369 | 346 |
370 // Input when searching against the keyword provider. | 347 // Input when searching against the keyword provider. |
371 AutocompleteInput keyword_input_; | 348 AutocompleteInput keyword_input_; |
372 | 349 |
373 // Searches in the user's history that begin with the input text. | 350 // Searches in the user's history that begin with the input text. |
(...skipping 23 matching lines...) Expand all Loading... | |
397 // that a server delete a personalized suggestion. Making this a ScopedVector | 374 // that a server delete a personalized suggestion. Making this a ScopedVector |
398 // causes us to auto-cancel all such requests on shutdown. | 375 // causes us to auto-cancel all such requests on shutdown. |
399 SuggestionDeletionHandlers deletion_handlers_; | 376 SuggestionDeletionHandlers deletion_handlers_; |
400 | 377 |
401 GURL current_page_url_; | 378 GURL current_page_url_; |
402 | 379 |
403 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 380 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
404 }; | 381 }; |
405 | 382 |
406 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 383 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
OLD | NEW |