| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 // NOTE: This does not update |done_|. Callers must do so. | 324 // NOTE: This does not update |done_|. Callers must do so. |
| 351 void StopSuggest(); | 325 void StopSuggest(); |
| 352 | 326 |
| 353 // Clears the current results. | 327 // Clears the current results. |
| 354 void ClearAllResults(); | 328 void ClearAllResults(); |
| 355 | 329 |
| 356 // Removes stale results for both default and keyword providers. See comments | 330 // Removes stale results for both default and keyword providers. See comments |
| 357 // on RemoveStaleResults(). | 331 // on RemoveStaleResults(). |
| 358 void RemoveAllStaleResults(); | 332 void RemoveAllStaleResults(); |
| 359 | 333 |
| 360 // If |default_provider_suggestion_| (which was suggested for | |
| 361 // |previous_input|) is still applicable given the |current_input|, adjusts it | |
| 362 // so it can be reused. Otherwise, clears it. | |
| 363 void AdjustDefaultProviderSuggestion(const string16& previous_input, | |
| 364 const string16& current_input); | |
| 365 | |
| 366 // Apply calculated relevance scores to the current results. | 334 // Apply calculated relevance scores to the current results. |
| 367 void ApplyCalculatedRelevance(); | 335 void ApplyCalculatedRelevance(); |
| 368 void ApplyCalculatedSuggestRelevance(SuggestResults* list); | 336 void ApplyCalculatedSuggestRelevance(SuggestResults* list); |
| 369 void ApplyCalculatedNavigationRelevance(NavigationResults* list); | 337 void ApplyCalculatedNavigationRelevance(NavigationResults* list); |
| 370 | 338 |
| 371 // Starts a new URLFetcher requesting suggest results from |template_url|; | 339 // Starts a new URLFetcher requesting suggest results from |template_url|; |
| 372 // callers own the returned URLFetcher, which is NULL for invalid providers. | 340 // callers own the returned URLFetcher, which is NULL for invalid providers. |
| 373 net::URLFetcher* CreateSuggestFetcher(int id, | 341 net::URLFetcher* CreateSuggestFetcher(int id, |
| 374 const TemplateURL* template_url, | 342 const TemplateURL* template_url, |
| 375 const AutocompleteInput& input); | 343 const AutocompleteInput& input); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 base::TimeTicks time_suggest_request_sent_; | 469 base::TimeTicks time_suggest_request_sent_; |
| 502 | 470 |
| 503 // Fetchers used to retrieve results for the keyword and default providers. | 471 // Fetchers used to retrieve results for the keyword and default providers. |
| 504 scoped_ptr<net::URLFetcher> keyword_fetcher_; | 472 scoped_ptr<net::URLFetcher> keyword_fetcher_; |
| 505 scoped_ptr<net::URLFetcher> default_fetcher_; | 473 scoped_ptr<net::URLFetcher> default_fetcher_; |
| 506 | 474 |
| 507 // Results from the default and keyword search providers. | 475 // Results from the default and keyword search providers. |
| 508 Results default_results_; | 476 Results default_results_; |
| 509 Results keyword_results_; | 477 Results keyword_results_; |
| 510 | 478 |
| 511 // Has FinalizeInstantQuery been invoked since the last |Start|? | |
| 512 bool instant_finalized_; | |
| 513 | |
| 514 // The |suggestion| parameter passed to FinalizeInstantQuery. | |
| 515 InstantSuggestion default_provider_suggestion_; | |
| 516 | |
| 517 // Whether a field trial, if any, has triggered in the most recent | 479 // Whether a field trial, if any, has triggered in the most recent |
| 518 // autocomplete query. This field is set to false in Start() and may be set | 480 // autocomplete query. This field is set to false in Start() and may be set |
| 519 // to true if either the default provider or keyword provider has completed | 481 // to true if either the default provider or keyword provider has completed |
| 520 // and their corresponding suggest response contained | 482 // and their corresponding suggest response contained |
| 521 // '"google:fieldtrialtriggered":true'. | 483 // '"google:fieldtrialtriggered":true'. |
| 522 // If the autocomplete query has not returned, this field is set to false. | 484 // If the autocomplete query has not returned, this field is set to false. |
| 523 bool field_trial_triggered_; | 485 bool field_trial_triggered_; |
| 524 | 486 |
| 525 // Same as above except that it is maintained across the current Omnibox | 487 // Same as above except that it is maintained across the current Omnibox |
| 526 // session. | 488 // session. |
| 527 bool field_trial_triggered_in_session_; | 489 bool field_trial_triggered_in_session_; |
| 528 | 490 |
| 529 // If true, suppress search suggestions. Reset to false in Start(). | |
| 530 // See comments for SuppressSearchSuggestions(). | |
| 531 bool suppress_search_suggestions_; | |
| 532 | |
| 533 // Start margin of the omnibox. Used to construct search URLs. | 491 // Start margin of the omnibox. Used to construct search URLs. |
| 534 int omnibox_start_margin_; | 492 int omnibox_start_margin_; |
| 535 | 493 |
| 536 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 494 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
| 537 }; | 495 }; |
| 538 | 496 |
| 539 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 497 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
| OLD | NEW |