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" | |
29 #include "net/url_request/url_fetcher_delegate.h" | 28 #include "net/url_request/url_fetcher_delegate.h" |
30 | 29 |
31 class Profile; | 30 class Profile; |
32 class SearchProviderTest; | 31 class SearchProviderTest; |
33 class TemplateURLService; | 32 class TemplateURLService; |
34 | 33 |
35 namespace base { | 34 namespace base { |
36 class Value; | 35 class Value; |
37 } | 36 } |
38 | 37 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 AutocompleteMatch::Type type, | 76 AutocompleteMatch::Type type, |
78 int accepted_suggestion, | 77 int accepted_suggestion, |
79 bool is_keyword, | 78 bool is_keyword, |
80 const string16& keyword, | 79 const string16& keyword, |
81 int omnibox_start_margin); | 80 int omnibox_start_margin); |
82 | 81 |
83 // AutocompleteProvider: | 82 // AutocompleteProvider: |
84 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; | 83 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; |
85 virtual void ResetSession() OVERRIDE; | 84 virtual void ResetSession() OVERRIDE; |
86 | 85 |
87 // Marks the instant query as done. If |input_text| is non-empty this changes | |
88 // the 'search what you typed' results text to |input_text| + | |
89 // |suggestion.text|. |input_text| is the text the user input into the edit. | |
90 // |input_text| differs from |input_.text()| if the input contained | |
91 // whitespace. | |
92 // | |
93 // This method also marks the search provider as no longer needing to wait for | |
94 // the instant result. | |
95 void FinalizeInstantQuery(const string16& input_text, | |
96 const InstantSuggestion& suggestion); | |
97 void ClearInstantSuggestion(); | |
98 | |
99 // If called, SearchProvider will not fetch any search suggestions for the | |
100 // next call to Start(). Used with InstantExtended where Instant fetches its | |
101 // own search suggestions. | |
102 // | |
103 // Note that this only applies to the next call to Start() and so this must be | |
104 // called repeatedly before Start() if you wish to continually suppress search | |
105 // suggestions. | |
106 void SuppressSearchSuggestions(); | |
107 | |
108 // Update the omnibox start margin used to generate search suggestion URLs. | 86 // Update the omnibox start margin used to generate search suggestion URLs. |
109 void SetOmniboxStartMargin(int omnibox_start_margin); | 87 void SetOmniboxStartMargin(int omnibox_start_margin); |
110 | 88 |
111 // Returns whether the provider is done processing the query with the | |
112 // exception of waiting for Instant to finish. | |
113 bool IsNonInstantSearchDone() const; | |
114 | |
115 bool field_trial_triggered_in_session() const { | 89 bool field_trial_triggered_in_session() const { |
116 return field_trial_triggered_in_session_; | 90 return field_trial_triggered_in_session_; |
117 } | 91 } |
118 | 92 |
119 private: | 93 private: |
120 // TODO(hfung): Remove ZeroSuggestProvider as a friend class after | 94 // TODO(hfung): Remove ZeroSuggestProvider as a friend class after |
121 // refactoring common code to a new base class. | 95 // refactoring common code to a new base class. |
122 friend class ZeroSuggestProvider; | 96 friend class ZeroSuggestProvider; |
123 friend class SearchProviderTest; | 97 friend class SearchProviderTest; |
124 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); | 98 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // NOTE: This does not update |done_|. Callers must do so. | 337 // NOTE: This does not update |done_|. Callers must do so. |
364 void StopSuggest(); | 338 void StopSuggest(); |
365 | 339 |
366 // Clears the current results. | 340 // Clears the current results. |
367 void ClearAllResults(); | 341 void ClearAllResults(); |
368 | 342 |
369 // Removes stale results for both default and keyword providers. See comments | 343 // Removes stale results for both default and keyword providers. See comments |
370 // on RemoveStaleResults(). | 344 // on RemoveStaleResults(). |
371 void RemoveAllStaleResults(); | 345 void RemoveAllStaleResults(); |
372 | 346 |
373 // If |default_provider_suggestion_| (which was suggested for | |
374 // |previous_input|) is still applicable given the |current_input|, adjusts it | |
375 // so it can be reused. Otherwise, clears it. | |
376 void AdjustDefaultProviderSuggestion(const string16& previous_input, | |
377 const string16& current_input); | |
378 | |
379 // Apply calculated relevance scores to the current results. | 347 // Apply calculated relevance scores to the current results. |
380 void ApplyCalculatedRelevance(); | 348 void ApplyCalculatedRelevance(); |
381 void ApplyCalculatedSuggestRelevance(SuggestResults* list); | 349 void ApplyCalculatedSuggestRelevance(SuggestResults* list); |
382 void ApplyCalculatedNavigationRelevance(NavigationResults* list); | 350 void ApplyCalculatedNavigationRelevance(NavigationResults* list); |
383 | 351 |
384 // Starts a new URLFetcher requesting suggest results from |template_url|; | 352 // Starts a new URLFetcher requesting suggest results from |template_url|; |
385 // callers own the returned URLFetcher, which is NULL for invalid providers. | 353 // callers own the returned URLFetcher, which is NULL for invalid providers. |
386 net::URLFetcher* CreateSuggestFetcher(int id, | 354 net::URLFetcher* CreateSuggestFetcher(int id, |
387 const TemplateURL* template_url, | 355 const TemplateURL* template_url, |
388 const AutocompleteInput& input); | 356 const AutocompleteInput& input); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 base::TimeTicks time_suggest_request_sent_; | 494 base::TimeTicks time_suggest_request_sent_; |
527 | 495 |
528 // Fetchers used to retrieve results for the keyword and default providers. | 496 // Fetchers used to retrieve results for the keyword and default providers. |
529 scoped_ptr<net::URLFetcher> keyword_fetcher_; | 497 scoped_ptr<net::URLFetcher> keyword_fetcher_; |
530 scoped_ptr<net::URLFetcher> default_fetcher_; | 498 scoped_ptr<net::URLFetcher> default_fetcher_; |
531 | 499 |
532 // Results from the default and keyword search providers. | 500 // Results from the default and keyword search providers. |
533 Results default_results_; | 501 Results default_results_; |
534 Results keyword_results_; | 502 Results keyword_results_; |
535 | 503 |
536 // Has FinalizeInstantQuery been invoked since the last |Start|? | |
537 bool instant_finalized_; | |
538 | |
539 // The |suggestion| parameter passed to FinalizeInstantQuery. | |
540 InstantSuggestion default_provider_suggestion_; | |
541 | |
542 // Whether a field trial, if any, has triggered in the most recent | 504 // Whether a field trial, if any, has triggered in the most recent |
543 // autocomplete query. This field is set to false in Start() and may be set | 505 // autocomplete query. This field is set to false in Start() and may be set |
544 // to true if either the default provider or keyword provider has completed | 506 // to true if either the default provider or keyword provider has completed |
545 // and their corresponding suggest response contained | 507 // and their corresponding suggest response contained |
546 // '"google:fieldtrialtriggered":true'. | 508 // '"google:fieldtrialtriggered":true'. |
547 // If the autocomplete query has not returned, this field is set to false. | 509 // If the autocomplete query has not returned, this field is set to false. |
548 bool field_trial_triggered_; | 510 bool field_trial_triggered_; |
549 | 511 |
550 // Same as above except that it is maintained across the current Omnibox | 512 // Same as above except that it is maintained across the current Omnibox |
551 // session. | 513 // session. |
552 bool field_trial_triggered_in_session_; | 514 bool field_trial_triggered_in_session_; |
553 | 515 |
554 // If true, suppress search suggestions. Reset to false in Start(). | |
555 // See comments for SuppressSearchSuggestions(). | |
556 bool suppress_search_suggestions_; | |
557 | |
558 // Start margin of the omnibox. Used to construct search URLs. | 516 // Start margin of the omnibox. Used to construct search URLs. |
559 int omnibox_start_margin_; | 517 int omnibox_start_margin_; |
560 | 518 |
561 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 519 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
562 }; | 520 }; |
563 | 521 |
564 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 522 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
OLD | NEW |