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

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

Issue 13141002: Use Instant suggested match type for Instant temporary text. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: static Created 7 years, 7 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // 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
47 // matches (either synchronously or asynchronously). 47 // matches (either synchronously or asynchronously).
48 // 48 //
49 // 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
50 // 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
51 // comes back, the provider creates and returns matches for the best 51 // comes back, the provider creates and returns matches for the best
52 // suggestions. 52 // suggestions.
53 class SearchProvider : public AutocompleteProvider, 53 class SearchProvider : public AutocompleteProvider,
54 public net::URLFetcherDelegate { 54 public net::URLFetcherDelegate {
55 public: 55 public:
56 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers
57 // may be used:
58 // . The default provider. This corresponds to the user's default search
59 // engine. This is always used, except for the rare case of no default
60 // engine.
61 // . The keyword provider. This is used if the user has typed in a keyword.
62 class Providers {
63 public:
64 explicit Providers(TemplateURLService* template_url_service);
65
66 // Returns true if the specified providers match the two providers cached
67 // by this class.
68 bool equal(const string16& default_provider,
69 const string16& keyword_provider) const {
70 return (default_provider == default_provider_) &&
71 (keyword_provider == keyword_provider_);
72 }
73
74 // Resets the cached providers.
75 void set(const string16& default_provider,
76 const string16& keyword_provider) {
77 default_provider_ = default_provider;
78 keyword_provider_ = keyword_provider;
79 }
80
81 TemplateURLService* template_url_service() { return template_url_service_; }
82 const string16& default_provider() const { return default_provider_; }
83 const string16& keyword_provider() const { return keyword_provider_; }
84
85 // NOTE: These may return NULL even if the provider members are nonempty!
86 const TemplateURL* GetDefaultProviderURL() const;
87 const TemplateURL* GetKeywordProviderURL() const;
88
89 // Returns true if there is a valid keyword provider.
90 bool has_keyword_provider() const { return !keyword_provider_.empty(); }
91
92 private:
93 TemplateURLService* template_url_service_;
94
95 // Cached across the life of a query so we behave consistently even if the
96 // user changes their default while the query is running.
97 string16 default_provider_;
98 string16 keyword_provider_;
99 };
100
56 // ID used in creating URLFetcher for default provider's suggest results. 101 // ID used in creating URLFetcher for default provider's suggest results.
57 static const int kDefaultProviderURLFetcherID; 102 static const int kDefaultProviderURLFetcherID;
58 103
59 // ID used in creating URLFetcher for keyword provider's suggest results. 104 // ID used in creating URLFetcher for keyword provider's suggest results.
60 static const int kKeywordProviderURLFetcherID; 105 static const int kKeywordProviderURLFetcherID;
61 106
107 // Returns the default and keyword providers for |profile|. The keyword
108 // provider is set only if |keyword_input| is non-NULL. If |keyword_input|
109 // represents a valid keyword input, the keyword is stripped.
110 static Providers GetProviders(Profile* profile,
111 const AutocompleteInput& input,
112 AutocompleteInput* keyword_input);
113
114 static AutocompleteMatch CreateSearchSuggestion(
115 Profile* profile,
116 AutocompleteProvider* autocomplete_provider,
117 const Providers& search_providers,
118 const AutocompleteInput& input,
119 const string16& query_string,
120 const string16& input_text,
121 int relevance,
122 AutocompleteMatch::Type type,
123 int accepted_suggestion,
124 bool is_keyword);
125
62 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); 126 SearchProvider(AutocompleteProviderListener* listener, Profile* profile);
63 127
64 // Marks the instant query as done. If |input_text| is non-empty this changes 128 // Marks the instant query as done. If |input_text| is non-empty this changes
65 // the 'search what you typed' results text to |input_text| + 129 // the 'search what you typed' results text to |input_text| +
66 // |suggestion.text|. |input_text| is the text the user input into the edit. 130 // |suggestion.text|. |input_text| is the text the user input into the edit.
67 // |input_text| differs from |input_.text()| if the input contained 131 // |input_text| differs from |input_.text()| if the input contained
68 // whitespace. 132 // whitespace.
69 // 133 //
70 // This method also marks the search provider as no longer needing to wait for 134 // This method also marks the search provider as no longer needing to wait for
71 // the instant result. 135 // the instant result.
(...skipping 26 matching lines...) Expand all
98 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); 162 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring);
99 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); 163 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify);
100 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); 164 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL);
101 165
102 // The amount of time to wait before sending a new suggest request after 166 // The amount of time to wait before sending a new suggest request after
103 // the previous one. 167 // the previous one.
104 static int kMinimumTimeBetweenSuggestQueriesMs; 168 static int kMinimumTimeBetweenSuggestQueriesMs;
105 169
106 virtual ~SearchProvider(); 170 virtual ~SearchProvider();
107 171
108 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers
109 // may be used:
110 // . The default provider. This corresponds to the user's default search
111 // engine. This is always used, except for the rare case of no default
112 // engine.
113 // . The keyword provider. This is used if the user has typed in a keyword.
114 class Providers {
115 public:
116 explicit Providers(TemplateURLService* template_url_service);
117
118 // Returns true if the specified providers match the two providers cached
119 // by this class.
120 bool equal(const string16& default_provider,
121 const string16& keyword_provider) const {
122 return (default_provider == default_provider_) &&
123 (keyword_provider == keyword_provider_);
124 }
125
126 // Resets the cached providers.
127 void set(const string16& default_provider,
128 const string16& keyword_provider) {
129 default_provider_ = default_provider;
130 keyword_provider_ = keyword_provider;
131 }
132
133 TemplateURLService* template_url_service() { return template_url_service_; }
134 const string16& default_provider() const { return default_provider_; }
135 const string16& keyword_provider() const { return keyword_provider_; }
136
137 // NOTE: These may return NULL even if the provider members are nonempty!
138 const TemplateURL* GetDefaultProviderURL() const;
139 const TemplateURL* GetKeywordProviderURL() const;
140
141 // Returns true if there is a valid keyword provider.
142 bool has_keyword_provider() const { return !keyword_provider_.empty(); }
143
144 private:
145 TemplateURLService* template_url_service_;
146
147 // Cached across the life of a query so we behave consistently even if the
148 // user changes their default while the query is running.
149 string16 default_provider_;
150 string16 keyword_provider_;
151
152 DISALLOW_COPY_AND_ASSIGN(Providers);
153 };
154
155 // The Result classes are intermediate representations of AutocompleteMatches, 172 // The Result classes are intermediate representations of AutocompleteMatches,
156 // simply containing relevance-ranked search and navigation suggestions. 173 // simply containing relevance-ranked search and navigation suggestions.
157 // They may be cached to provide some synchronous matches while requests for 174 // They may be cached to provide some synchronous matches while requests for
158 // new suggestions from updated input are in flight. 175 // new suggestions from updated input are in flight.
159 // TODO(msw) Extend these classes to generate their corresponding matches and 176 // TODO(msw) Extend these classes to generate their corresponding matches and
160 // other requisite data, in order to consolidate and simplify the 177 // other requisite data, in order to consolidate and simplify the
161 // highly fragmented SearchProvider logic for each Result type. 178 // highly fragmented SearchProvider logic for each Result type.
162 class Result { 179 class Result {
163 public: 180 public:
164 // Takes whether the result is from the keyword provider and its 181 // Takes whether the result is from the keyword provider and its
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 bool field_trial_triggered_; 485 bool field_trial_triggered_;
469 486
470 // 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
471 // session. 488 // session.
472 bool field_trial_triggered_in_session_; 489 bool field_trial_triggered_in_session_;
473 490
474 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 491 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
475 }; 492 };
476 493
477 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 494 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/search_provider.cc » ('j') | chrome/browser/autocomplete/search_provider.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698