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 11 matching lines...) Expand all Loading... |
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" |
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 TemplateURLService; | 33 class TemplateURLService; |
33 | 34 |
34 namespace base { | 35 namespace base { |
35 class Value; | 36 class Value; |
36 } | 37 } |
37 | 38 |
38 namespace net { | 39 namespace net { |
39 class URLFetcher; | 40 class URLFetcher; |
40 } | 41 } |
41 | 42 |
42 // Autocomplete provider for searches and suggestions from a search engine. | 43 // Autocomplete provider for searches and suggestions from a search engine. |
43 // | 44 // |
44 // After construction, the autocomplete controller repeatedly calls Start() | 45 // After construction, the autocomplete controller repeatedly calls Start() |
45 // with some user input, each time expecting to receive a small set of the best | 46 // with some user input, each time expecting to receive a small set of the best |
46 // matches (either synchronously or asynchronously). | 47 // matches (either synchronously or asynchronously). |
47 // | 48 // |
48 // Initially the provider creates a match that searches for the current input | 49 // Initially the provider creates a match that searches for the current input |
49 // text. It also starts a task to query the Suggest servers. When that data | 50 // text. It also starts a task to query the Suggest servers. When that data |
50 // comes back, the provider creates and returns matches for the best | 51 // comes back, the provider creates and returns matches for the best |
51 // suggestions. | 52 // suggestions. |
52 class SearchProvider : public AutocompleteProvider, | 53 class SearchProvider : public AutocompleteProvider, |
53 public net::URLFetcherDelegate { | 54 public net::URLFetcherDelegate { |
54 public: | 55 public: |
| 56 // ID used in creating URLFetcher for default provider's suggest results. |
| 57 static const int kDefaultProviderURLFetcherID; |
| 58 |
| 59 // ID used in creating URLFetcher for keyword provider's suggest results. |
| 60 static const int kKeywordProviderURLFetcherID; |
| 61 |
55 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); | 62 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); |
56 | 63 |
57 // Marks the instant query as done. If |input_text| is non-empty this changes | 64 // Marks the instant query as done. If |input_text| is non-empty this changes |
58 // the 'search what you typed' results text to |input_text| + | 65 // the 'search what you typed' results text to |input_text| + |
59 // |suggestion.text|. |input_text| is the text the user input into the edit. | 66 // |suggestion.text|. |input_text| is the text the user input into the edit. |
60 // |input_text| differs from |input_.text()| if the input contained | 67 // |input_text| differs from |input_.text()| if the input contained |
61 // whitespace. | 68 // whitespace. |
62 // | 69 // |
63 // This method also marks the search provider as no longer needing to wait for | 70 // This method also marks the search provider as no longer needing to wait for |
64 // the instant result. | 71 // the instant result. |
(...skipping 12 matching lines...) Expand all Loading... |
77 // Sets |field_trial_triggered_in_session_| to false. | 84 // Sets |field_trial_triggered_in_session_| to false. |
78 virtual void ResetSession() OVERRIDE; | 85 virtual void ResetSession() OVERRIDE; |
79 | 86 |
80 // net::URLFetcherDelegate | 87 // net::URLFetcherDelegate |
81 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 88 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
82 | 89 |
83 bool field_trial_triggered_in_session() const { | 90 bool field_trial_triggered_in_session() const { |
84 return field_trial_triggered_in_session_; | 91 return field_trial_triggered_in_session_; |
85 } | 92 } |
86 | 93 |
87 // ID used in creating URLFetcher for default provider's suggest results. | |
88 static const int kDefaultProviderURLFetcherID; | |
89 | |
90 // ID used in creating URLFetcher for keyword provider's suggest results. | |
91 static const int kKeywordProviderURLFetcherID; | |
92 | |
93 private: | 94 private: |
| 95 friend class SearchProviderTest; |
94 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment); | 96 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment); |
95 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); | 97 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); |
96 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); | 98 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); |
97 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); | 99 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); |
98 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); | 100 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); |
99 | 101 |
| 102 // The amount of time to wait before sending a new suggest request after |
| 103 // the previous one. |
| 104 static int kMinimumTimeBetweenSuggestQueriesMs; |
| 105 |
100 virtual ~SearchProvider(); | 106 virtual ~SearchProvider(); |
101 | 107 |
102 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers | 108 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers |
103 // may be used: | 109 // may be used: |
104 // . The default provider. This corresponds to the user's default search | 110 // . The default provider. This corresponds to the user's default search |
105 // engine. This is always used, except for the rare case of no default | 111 // engine. This is always used, except for the rare case of no default |
106 // engine. | 112 // engine. |
107 // . The keyword provider. This is used if the user has typed in a keyword. | 113 // . The keyword provider. This is used if the user has typed in a keyword. |
108 class Providers { | 114 class Providers { |
109 public: | 115 public: |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 bool field_trial_triggered_; | 468 bool field_trial_triggered_; |
463 | 469 |
464 // Same as above except that it is maintained across the current Omnibox | 470 // Same as above except that it is maintained across the current Omnibox |
465 // session. | 471 // session. |
466 bool field_trial_triggered_in_session_; | 472 bool field_trial_triggered_in_session_; |
467 | 473 |
468 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 474 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
469 }; | 475 }; |
470 | 476 |
471 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 477 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
OLD | NEW |