Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: chrome/browser/autocomplete/search_provider.h

Issue 158053002: Part 4 of search provider refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 bool base_prevent_inline_autocomplete, 265 bool base_prevent_inline_autocomplete,
270 bool input_multiple_words, 266 bool input_multiple_words,
271 const base::string16& input_text, 267 const base::string16& input_text,
272 bool is_keyword); 268 bool is_keyword);
273 269
274 // Adds matches for |results| to |map|. 270 // Adds matches for |results| to |map|.
275 void AddSuggestResultsToMap(const SuggestResults& results, 271 void AddSuggestResultsToMap(const SuggestResults& results,
276 const std::string& metadata, 272 const std::string& metadata,
277 MatchMap* map); 273 MatchMap* map);
278 274
275 // Returns the AutocompleteInput object corresponding to the given |result|.
276 const AutocompleteInput GetInput(const SuggestResult& result) const;
Mark P 2014/02/10 23:25:55 possibly unnecessary. See comment elsewhere.
Maria 2014/02/11 21:42:32 Done.
277
278 // Returns the TemplateURL used to search for the |result|.
279 const TemplateURL* GetTemplateURL(const SuggestResult& result) const;
280
281 // Returns whether |result| is coming from the default search provider.
Mark P 2014/02/10 23:25:55 This comment is slightly wrong. It doesn't match
Maria 2014/02/11 21:42:32 Done.
282 bool IsDefaultSearchProviderResult(const SuggestResult& result) const;
283
279 // Gets the relevance score for the verbatim result. This value may be 284 // Gets the relevance score for the verbatim result. This value may be
280 // provided by the suggest server or calculated locally; if 285 // provided by the suggest server or calculated locally; if
281 // |relevance_from_server| is non-NULL, it will be set to indicate which of 286 // |relevance_from_server| is non-NULL, it will be set to indicate which of
282 // those is true. 287 // those is true.
283 int GetVerbatimRelevance(bool* relevance_from_server) const; 288 int GetVerbatimRelevance(bool* relevance_from_server) const;
284 289
285 // Calculates the relevance score for the verbatim result from the 290 // Calculates the relevance score for the verbatim result from the
286 // default search engine. This version takes into account context: 291 // default search engine. This version takes into account context:
287 // i.e., whether the user has entered a keyword-based search or not. 292 // i.e., whether the user has entered a keyword-based search or not.
288 int CalculateRelevanceForVerbatim() const; 293 int CalculateRelevanceForVerbatim() const;
(...skipping 16 matching lines...) Expand all
305 // indicates whether the results correspond to the keyword provider or default 310 // indicates whether the results correspond to the keyword provider or default
306 // provider. |use_aggressive_method| says whether this function can use a 311 // provider. |use_aggressive_method| says whether this function can use a
307 // method that gives high scores (1200+) rather than one that gives lower 312 // method that gives high scores (1200+) rather than one that gives lower
308 // scores. When using the aggressive method, scores may exceed 1300 313 // scores. When using the aggressive method, scores may exceed 1300
309 // unless |prevent_search_history_inlining| is set. 314 // unless |prevent_search_history_inlining| is set.
310 int CalculateRelevanceForHistory(const base::Time& time, 315 int CalculateRelevanceForHistory(const base::Time& time,
311 bool is_keyword, 316 bool is_keyword,
312 bool use_aggressive_method, 317 bool use_aggressive_method,
313 bool prevent_search_history_inlining) const; 318 bool prevent_search_history_inlining) const;
314 319
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. 320 // Returns an AutocompleteMatch for a navigational suggestion.
325 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); 321 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation);
326 322
327 // Resets the scores of all |keyword_navigation_results_| matches to 323 // Resets the scores of all |keyword_navigation_results_| matches to
328 // be below that of the top keyword query match (the verbatim match 324 // be below that of the top keyword query match (the verbatim match
329 // as expressed by |keyword_verbatim_relevance_| or keyword query 325 // as expressed by |keyword_verbatim_relevance_| or keyword query
330 // suggestions stored in |keyword_suggest_results_|). If there 326 // suggestions stored in |keyword_suggest_results_|). If there
331 // are no keyword suggestions and keyword verbatim is suppressed, 327 // are no keyword suggestions and keyword verbatim is suppressed,
332 // then drops the suggested relevance scores for the navsuggestions 328 // then drops the suggested relevance scores for the navsuggestions
333 // and drops the request to suppress verbatim, thereby introducing the 329 // and drops the request to suppress verbatim, thereby introducing the
334 // keyword verbatim match which will naturally outscore the navsuggestions. 330 // keyword verbatim match which will naturally outscore the navsuggestions.
335 void DemoteKeywordNavigationMatchesPastTopQuery(); 331 void DemoteKeywordNavigationMatchesPastTopQuery();
336 332
337 // Updates the value of |done_| from the internal state. 333 // Updates the value of |done_| from the internal state.
338 void UpdateDone(); 334 void UpdateDone();
339 335
340 // The amount of time to wait before sending a new suggest request after the 336 // 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. 337 // previous one. Non-const because some unittests modify this value.
342 static int kMinimumTimeBetweenSuggestQueriesMs; 338 static int kMinimumTimeBetweenSuggestQueriesMs;
343 339
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. 340 // Maintains the TemplateURLs used.
365 Providers providers_; 341 Providers providers_;
366 342
367 // The user's input. 343 // The user's input.
368 AutocompleteInput input_; 344 AutocompleteInput input_;
369 345
370 // Input when searching against the keyword provider. 346 // Input when searching against the keyword provider.
371 AutocompleteInput keyword_input_; 347 AutocompleteInput keyword_input_;
372 348
373 // Searches in the user's history that begin with the input text. 349 // Searches in the user's history that begin with the input text.
(...skipping 23 matching lines...) Expand all
397 // that a server delete a personalized suggestion. Making this a ScopedVector 373 // that a server delete a personalized suggestion. Making this a ScopedVector
398 // causes us to auto-cancel all such requests on shutdown. 374 // causes us to auto-cancel all such requests on shutdown.
399 SuggestionDeletionHandlers deletion_handlers_; 375 SuggestionDeletionHandlers deletion_handlers_;
400 376
401 GURL current_page_url_; 377 GURL current_page_url_;
402 378
403 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 379 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
404 }; 380 };
405 381
406 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 382 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698