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 |
11 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 11 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
12 #define CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 12 #define CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/time.h" | 21 #include "base/time.h" |
22 #include "base/timer.h" | 22 #include "base/timer.h" |
23 #include "chrome/browser/autocomplete/autocomplete_input.h" | 23 #include "chrome/browser/autocomplete/autocomplete_input.h" |
24 #include "chrome/browser/autocomplete/autocomplete_match.h" | 24 #include "chrome/browser/autocomplete/autocomplete_match.h" |
25 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 25 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
26 #include "chrome/browser/history/history_types.h" | 26 #include "chrome/browser/history/history_types.h" |
27 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
28 #include "chrome/common/instant_types.h" | 28 #include "chrome/common/instant_types.h" |
msw
2013/06/18 19:24:30
nit: remove this.
| |
29 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
30 | 30 |
31 class Profile; | 31 class Profile; |
32 class SearchProviderTest; | 32 class SearchProviderTest; |
33 class TemplateURLService; | 33 class TemplateURLService; |
34 | 34 |
35 namespace base { | 35 namespace base { |
36 class Value; | 36 class Value; |
37 } | 37 } |
38 | 38 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 const string16& input_text, | 73 const string16& input_text, |
74 int relevance, | 74 int relevance, |
75 AutocompleteMatch::Type type, | 75 AutocompleteMatch::Type type, |
76 int accepted_suggestion, | 76 int accepted_suggestion, |
77 bool is_keyword, | 77 bool is_keyword, |
78 const string16& keyword, | 78 const string16& keyword, |
79 int omnibox_start_margin); | 79 int omnibox_start_margin); |
80 | 80 |
81 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); | 81 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); |
82 | 82 |
83 // Marks the instant query as done. If |input_text| is non-empty this changes | |
84 // the 'search what you typed' results text to |input_text| + | |
85 // |suggestion.text|. |input_text| is the text the user input into the edit. | |
86 // |input_text| differs from |input_.text()| if the input contained | |
87 // whitespace. | |
88 // | |
89 // This method also marks the search provider as no longer needing to wait for | |
90 // the instant result. | |
91 void FinalizeInstantQuery(const string16& input_text, | |
92 const InstantSuggestion& suggestion); | |
93 void ClearInstantSuggestion(); | |
94 | |
95 // If called, SearchProvider will not fetch any search suggestions for the | |
96 // next call to Start(). Used with InstantExtended where Instant fetches its | |
97 // own search suggestions. | |
98 // | |
99 // Note that this only applies to the next call to Start() and so this must be | |
100 // called repeatedly before Start() if you wish to continually suppress search | |
101 // suggestions. | |
102 void SuppressSearchSuggestions(); | |
103 | |
104 // Update the omnibox start margin used to generate search suggestion URLs. | 83 // Update the omnibox start margin used to generate search suggestion URLs. |
105 void SetOmniboxStartMargin(int omnibox_start_margin); | 84 void SetOmniboxStartMargin(int omnibox_start_margin); |
106 | 85 |
107 // AutocompleteProvider: | 86 // AutocompleteProvider: |
108 virtual void Start(const AutocompleteInput& input, | 87 virtual void Start(const AutocompleteInput& input, |
109 bool minimal_changes) OVERRIDE; | 88 bool minimal_changes) OVERRIDE; |
110 virtual void Stop(bool clear_cached_results) OVERRIDE; | 89 virtual void Stop(bool clear_cached_results) OVERRIDE; |
111 | 90 |
112 // Adds search-provider-specific information to omnibox event logs. | 91 // Adds search-provider-specific information to omnibox event logs. |
113 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; | 92 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; |
114 | 93 |
115 // Sets |field_trial_triggered_in_session_| to false. | 94 // Sets |field_trial_triggered_in_session_| to false. |
116 virtual void ResetSession() OVERRIDE; | 95 virtual void ResetSession() OVERRIDE; |
117 | 96 |
118 // net::URLFetcherDelegate | 97 // net::URLFetcherDelegate |
119 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 98 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
120 | 99 |
121 // Returns whether the provider is done processing the query with the | 100 // Returns whether the provider is done processing the query. |
122 // exception of waiting for Instant to finish. | 101 bool IsDone() const; |
123 bool IsNonInstantSearchDone() const; | |
124 | 102 |
125 bool field_trial_triggered_in_session() const { | 103 bool field_trial_triggered_in_session() const { |
126 return field_trial_triggered_in_session_; | 104 return field_trial_triggered_in_session_; |
127 } | 105 } |
128 | 106 |
129 private: | 107 private: |
130 // TODO(hfung): Remove ZeroSuggestProvider as a friend class after | 108 // TODO(hfung): Remove ZeroSuggestProvider as a friend class after |
131 // refactoring common code to a new base class. | 109 // refactoring common code to a new base class. |
132 friend class ZeroSuggestProvider; | 110 friend class ZeroSuggestProvider; |
133 friend class SearchProviderTest; | 111 friend class SearchProviderTest; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 void ClearAllResults(); | 325 void ClearAllResults(); |
348 | 326 |
349 // Removes non-inlineable results until either the top result can inline | 327 // Removes non-inlineable results until either the top result can inline |
350 // autocomplete the current input or verbatim outscores the top result. | 328 // autocomplete the current input or verbatim outscores the top result. |
351 void RemoveAllStaleResults(); | 329 void RemoveAllStaleResults(); |
352 static void RemoveStaleResults(const string16& input, | 330 static void RemoveStaleResults(const string16& input, |
353 int verbatim_relevance, | 331 int verbatim_relevance, |
354 SuggestResults* suggest_results, | 332 SuggestResults* suggest_results, |
355 NavigationResults* navigation_results); | 333 NavigationResults* navigation_results); |
356 | 334 |
357 // If |default_provider_suggestion_| (which was suggested for | |
358 // |previous_input|) is still applicable given the |current_input|, adjusts it | |
359 // so it can be reused. Otherwise, clears it. | |
360 void AdjustDefaultProviderSuggestion(const string16& previous_input, | |
361 const string16& current_input); | |
362 | |
363 // Apply calculated relevance scores to the current results. | 335 // Apply calculated relevance scores to the current results. |
364 void ApplyCalculatedRelevance(); | 336 void ApplyCalculatedRelevance(); |
365 void ApplyCalculatedSuggestRelevance(SuggestResults* list); | 337 void ApplyCalculatedSuggestRelevance(SuggestResults* list); |
366 void ApplyCalculatedNavigationRelevance(NavigationResults* list); | 338 void ApplyCalculatedNavigationRelevance(NavigationResults* list); |
367 | 339 |
368 // Starts a new URLFetcher requesting suggest results from |template_url|; | 340 // Starts a new URLFetcher requesting suggest results from |template_url|; |
369 // callers own the returned URLFetcher, which is NULL for invalid providers. | 341 // callers own the returned URLFetcher, which is NULL for invalid providers. |
370 net::URLFetcher* CreateSuggestFetcher(int id, | 342 net::URLFetcher* CreateSuggestFetcher(int id, |
371 const TemplateURL* template_url, | 343 const TemplateURL* template_url, |
372 const AutocompleteInput& input); | 344 const AutocompleteInput& input); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 base::TimeTicks time_suggest_request_sent_; | 470 base::TimeTicks time_suggest_request_sent_; |
499 | 471 |
500 // Fetchers used to retrieve results for the keyword and default providers. | 472 // Fetchers used to retrieve results for the keyword and default providers. |
501 scoped_ptr<net::URLFetcher> keyword_fetcher_; | 473 scoped_ptr<net::URLFetcher> keyword_fetcher_; |
502 scoped_ptr<net::URLFetcher> default_fetcher_; | 474 scoped_ptr<net::URLFetcher> default_fetcher_; |
503 | 475 |
504 // Results from the default and keyword search providers. | 476 // Results from the default and keyword search providers. |
505 Results default_results_; | 477 Results default_results_; |
506 Results keyword_results_; | 478 Results keyword_results_; |
507 | 479 |
508 // Has FinalizeInstantQuery been invoked since the last |Start|? | |
509 bool instant_finalized_; | |
510 | |
511 // The |suggestion| parameter passed to FinalizeInstantQuery. | |
512 InstantSuggestion default_provider_suggestion_; | |
513 | |
514 // Whether a field trial, if any, has triggered in the most recent | 480 // Whether a field trial, if any, has triggered in the most recent |
515 // autocomplete query. This field is set to false in Start() and may be set | 481 // autocomplete query. This field is set to false in Start() and may be set |
516 // to true if either the default provider or keyword provider has completed | 482 // to true if either the default provider or keyword provider has completed |
517 // and their corresponding suggest response contained | 483 // and their corresponding suggest response contained |
518 // '"google:fieldtrialtriggered":true'. | 484 // '"google:fieldtrialtriggered":true'. |
519 // If the autocomplete query has not returned, this field is set to false. | 485 // If the autocomplete query has not returned, this field is set to false. |
520 bool field_trial_triggered_; | 486 bool field_trial_triggered_; |
521 | 487 |
522 // Same as above except that it is maintained across the current Omnibox | 488 // Same as above except that it is maintained across the current Omnibox |
523 // session. | 489 // session. |
524 bool field_trial_triggered_in_session_; | 490 bool field_trial_triggered_in_session_; |
525 | 491 |
526 // If true, suppress search suggestions. Reset to false in Start(). | |
527 // See comments for SuppressSearchSuggestions(). | |
528 bool suppress_search_suggestions_; | |
529 | |
530 // Start margin of the omnibox. Used to construct search URLs. | 492 // Start margin of the omnibox. Used to construct search URLs. |
531 int omnibox_start_margin_; | 493 int omnibox_start_margin_; |
532 | 494 |
533 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 495 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
534 }; | 496 }; |
535 | 497 |
536 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 498 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
OLD | NEW |