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

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

Issue 6306011: Remove wstring from autocomplete. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 non-keyword autocomplete entries that start with 6 // responsible for all non-keyword autocomplete entries that start with
7 // "Search <engine> for ...", including searching for the current input string, 7 // "Search <engine> for ...", including searching for the current input string,
8 // search history, and search suggestions. An instance of it gets created and 8 // search 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 #endif 53 #endif
54 54
55 // Marks the instant query as done. If |input_text| is non-empty this changes 55 // Marks the instant query as done. If |input_text| is non-empty this changes
56 // the 'search what you typed' results text to |input_text| + |suggest_text|. 56 // the 'search what you typed' results text to |input_text| + |suggest_text|.
57 // |input_text| is the text the user input into the edit. |input_text| differs 57 // |input_text| is the text the user input into the edit. |input_text| differs
58 // from |input_.text()| if the input contained whitespace. 58 // from |input_.text()| if the input contained whitespace.
59 // 59 //
60 // This method also marks the search provider as no longer needing to wait for 60 // This method also marks the search provider as no longer needing to wait for
61 // the instant result. 61 // the instant result.
62 void FinalizeInstantQuery(const std::wstring& input_text, 62 void FinalizeInstantQuery(const string16& input_text,
63 const std::wstring& suggest_text); 63 const string16& suggest_text);
64 64
65 // AutocompleteProvider 65 // AutocompleteProvider
66 virtual void Start(const AutocompleteInput& input, 66 virtual void Start(const AutocompleteInput& input,
67 bool minimal_changes); 67 bool minimal_changes);
68 virtual void Stop(); 68 virtual void Stop();
69 69
70 // URLFetcher::Delegate 70 // URLFetcher::Delegate
71 virtual void OnURLFetchComplete(const URLFetcher* source, 71 virtual void OnURLFetchComplete(const URLFetcher* source,
72 const GURL& url, 72 const GURL& url,
73 const net::URLRequestStatus& status, 73 const net::URLRequestStatus& status,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // user changes their default while the query is running. 145 // user changes their default while the query is running.
146 TemplateURL cached_default_provider_; 146 TemplateURL cached_default_provider_;
147 TemplateURL cached_keyword_provider_; 147 TemplateURL cached_keyword_provider_;
148 148
149 // TODO(pkasting): http://b/1162970 We shouldn't need these. 149 // TODO(pkasting): http://b/1162970 We shouldn't need these.
150 const TemplateURL* default_provider_; 150 const TemplateURL* default_provider_;
151 const TemplateURL* keyword_provider_; 151 const TemplateURL* keyword_provider_;
152 }; 152 };
153 153
154 struct NavigationResult { 154 struct NavigationResult {
155 NavigationResult(const GURL& url, const std::wstring& site_name) 155 NavigationResult(const GURL& url, const string16& site_name)
156 : url(url), 156 : url(url),
157 site_name(site_name) { 157 site_name(site_name) {
158 } 158 }
159 159
160 // The URL. 160 // The URL.
161 GURL url; 161 GURL url;
162 162
163 // Name for the site. 163 // Name for the site.
164 std::wstring site_name; 164 string16 site_name;
165 }; 165 };
166 166
167 typedef std::vector<std::wstring> SuggestResults; 167 typedef std::vector<string16> SuggestResults;
168 typedef std::vector<NavigationResult> NavigationResults; 168 typedef std::vector<NavigationResult> NavigationResults;
169 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; 169 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults;
170 typedef std::map<std::wstring, AutocompleteMatch> MatchMap; 170 typedef std::map<string16, AutocompleteMatch> MatchMap;
171 171
172 // Called when timer_ expires. 172 // Called when timer_ expires.
173 void Run(); 173 void Run();
174 174
175 // Runs the history query, if necessary. The history query is synchronous. 175 // Runs the history query, if necessary. The history query is synchronous.
176 // This does not update |done_|. 176 // This does not update |done_|.
177 void DoHistoryQuery(bool minimal_changes); 177 void DoHistoryQuery(bool minimal_changes);
178 178
179 // Determines whether an asynchronous subcomponent query should run for the 179 // Determines whether an asynchronous subcomponent query should run for the
180 // current input. If so, starts it if necessary; otherwise stops it. 180 // current input. If so, starts it if necessary; otherwise stops it.
181 // NOTE: This function does not update |done_|. Callers must do so. 181 // NOTE: This function does not update |done_|. Callers must do so.
182 void StartOrStopSuggestQuery(bool minimal_changes); 182 void StartOrStopSuggestQuery(bool minimal_changes);
183 183
184 // Returns true when the current query can be sent to the Suggest service. 184 // Returns true when the current query can be sent to the Suggest service.
185 // This will be false e.g. when Suggest is disabled, the query contains 185 // This will be false e.g. when Suggest is disabled, the query contains
186 // potentially private data, etc. 186 // potentially private data, etc.
187 bool IsQuerySuitableForSuggest() const; 187 bool IsQuerySuitableForSuggest() const;
188 188
189 // Stops the suggest query. 189 // Stops the suggest query.
190 // NOTE: This does not update |done_|. Callers must do so. 190 // NOTE: This does not update |done_|. Callers must do so.
191 void StopSuggest(); 191 void StopSuggest();
192 192
193 // Creates a URLFetcher requesting suggest results for the specified 193 // Creates a URLFetcher requesting suggest results for the specified
194 // TemplateURL. Ownership of the returned URLFetchet passes to the caller. 194 // TemplateURL. Ownership of the returned URLFetchet passes to the caller.
195 URLFetcher* CreateSuggestFetcher(int id, 195 URLFetcher* CreateSuggestFetcher(int id,
196 const TemplateURL& provider, 196 const TemplateURL& provider,
197 const std::wstring& text); 197 const string16& text);
198 198
199 // Parses the results from the Suggest server and stores up to kMaxMatches of 199 // Parses the results from the Suggest server and stores up to kMaxMatches of
200 // them in server_results_. Returns whether parsing succeeded. 200 // them in server_results_. Returns whether parsing succeeded.
201 bool ParseSuggestResults(Value* root_val, 201 bool ParseSuggestResults(Value* root_val,
202 bool is_keyword, 202 bool is_keyword,
203 const std::wstring& input_text, 203 const string16& input_text,
204 SuggestResults* suggest_results); 204 SuggestResults* suggest_results);
205 205
206 // Converts the parsed server results in server_results_ to a set of 206 // Converts the parsed server results in server_results_ to a set of
207 // AutocompleteMatches and adds them to |matches_|. This also sets |done_| 207 // AutocompleteMatches and adds them to |matches_|. This also sets |done_|
208 // correctly. 208 // correctly.
209 void ConvertResultsToAutocompleteMatches(); 209 void ConvertResultsToAutocompleteMatches();
210 210
211 // Converts the first navigation result in |navigation_results| to an 211 // Converts the first navigation result in |navigation_results| to an
212 // AutocompleteMatch and adds it to |matches_|. 212 // AutocompleteMatch and adds it to |matches_|.
213 void AddNavigationResultsToMatches( 213 void AddNavigationResultsToMatches(
(...skipping 30 matching lines...) Expand all
244 bool is_keyword) const; 244 bool is_keyword) const;
245 // |result_number| is same as above. |is_keyword| is true if the navigation 245 // |result_number| is same as above. |is_keyword| is true if the navigation
246 // result was suggested by the keyword provider. 246 // result was suggested by the keyword provider.
247 int CalculateRelevanceForNavigation(size_t num_results, 247 int CalculateRelevanceForNavigation(size_t num_results,
248 size_t result_number, 248 size_t result_number,
249 bool is_keyword) const; 249 bool is_keyword) const;
250 250
251 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with 251 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with
252 // the supplied relevance. Adds this match to |map|; if such a match already 252 // the supplied relevance. Adds this match to |map|; if such a match already
253 // exists, whichever one has lower relevance is eliminated. 253 // exists, whichever one has lower relevance is eliminated.
254 void AddMatchToMap(const std::wstring& query_string, 254 void AddMatchToMap(const string16& query_string,
255 const std::wstring& input_text, 255 const string16& input_text,
256 int relevance, 256 int relevance,
257 AutocompleteMatch::Type type, 257 AutocompleteMatch::Type type,
258 int accepted_suggestion, 258 int accepted_suggestion,
259 bool is_keyword, 259 bool is_keyword,
260 bool prevent_inline_autocomplete, 260 bool prevent_inline_autocomplete,
261 MatchMap* map); 261 MatchMap* map);
262 262
263 // Returns an AutocompleteMatch for a navigational suggestion. 263 // Returns an AutocompleteMatch for a navigational suggestion.
264 AutocompleteMatch NavigationToMatch(const NavigationResult& query_string, 264 AutocompleteMatch NavigationToMatch(const NavigationResult& query_string,
265 int relevance, 265 int relevance,
266 bool is_keyword); 266 bool is_keyword);
267 267
268 // Updates the value of |done_| from the internal state. 268 // Updates the value of |done_| from the internal state.
269 void UpdateDone(); 269 void UpdateDone();
270 270
271 // Updates the description/description_class of the first search match. 271 // Updates the description/description_class of the first search match.
272 void UpdateFirstSearchMatchDescription(); 272 void UpdateFirstSearchMatchDescription();
273 273
274 // Should we query for suggest results immediately? This is normally false, 274 // Should we query for suggest results immediately? This is normally false,
275 // but may be set to true during testing. 275 // but may be set to true during testing.
276 static bool query_suggest_immediately_; 276 static bool query_suggest_immediately_;
277 277
278 // Maintains the TemplateURLs used. 278 // Maintains the TemplateURLs used.
279 Providers providers_; 279 Providers providers_;
280 280
281 // The user's input. 281 // The user's input.
282 AutocompleteInput input_; 282 AutocompleteInput input_;
283 283
284 // Input text when searching against the keyword provider. 284 // Input text when searching against the keyword provider.
285 std::wstring keyword_input_text_; 285 string16 keyword_input_text_;
286 286
287 // Searches in the user's history that begin with the input text. 287 // Searches in the user's history that begin with the input text.
288 HistoryResults keyword_history_results_; 288 HistoryResults keyword_history_results_;
289 HistoryResults default_history_results_; 289 HistoryResults default_history_results_;
290 290
291 // Number of suggest results that haven't yet arrived. If greater than 0 it 291 // Number of suggest results that haven't yet arrived. If greater than 0 it
292 // indicates either |timer_| or one of the URLFetchers is still running. 292 // indicates either |timer_| or one of the URLFetchers is still running.
293 int suggest_results_pending_; 293 int suggest_results_pending_;
294 294
295 // A timer to start a query to the suggest server after the user has stopped 295 // A timer to start a query to the suggest server after the user has stopped
(...skipping 15 matching lines...) Expand all
311 NavigationResults keyword_navigation_results_; 311 NavigationResults keyword_navigation_results_;
312 NavigationResults default_navigation_results_; 312 NavigationResults default_navigation_results_;
313 313
314 // Whether suggest_results_ is valid. 314 // Whether suggest_results_ is valid.
315 bool have_suggest_results_; 315 bool have_suggest_results_;
316 316
317 // Has FinalizeInstantQuery been invoked since the last |Start|? 317 // Has FinalizeInstantQuery been invoked since the last |Start|?
318 bool instant_finalized_; 318 bool instant_finalized_;
319 319
320 // The |suggest_text| parameter passed to FinalizeInstantQuery. 320 // The |suggest_text| parameter passed to FinalizeInstantQuery.
321 std::wstring default_provider_suggest_text_; 321 string16 default_provider_suggest_text_;
322 322
323 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 323 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
324 }; 324 };
325 325
326 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 326 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698