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

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

Issue 105193002: Replace string16 with base::string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // |input| and |is_keyword| are necessary for various other details, like 78 // |input| and |is_keyword| are necessary for various other details, like
79 // whether we should allow inline autocompletion and what the transition type 79 // whether we should allow inline autocompletion and what the transition type
80 // should be. |accepted_suggestion| and |omnibox_start_margin| are used along 80 // should be. |accepted_suggestion| and |omnibox_start_margin| are used along
81 // with |input_text| to generate Assisted Query Stats. 81 // with |input_text| to generate Assisted Query Stats.
82 // |append_extra_query_params| should be set if |template_url| is the default 82 // |append_extra_query_params| should be set if |template_url| is the default
83 // search engine, so the destination URL will contain any 83 // search engine, so the destination URL will contain any
84 // command-line-specified query params. 84 // command-line-specified query params.
85 static AutocompleteMatch CreateSearchSuggestion( 85 static AutocompleteMatch CreateSearchSuggestion(
86 AutocompleteProvider* autocomplete_provider, 86 AutocompleteProvider* autocomplete_provider,
87 const AutocompleteInput& input, 87 const AutocompleteInput& input,
88 const string16& input_text, 88 const base::string16& input_text,
89 int relevance, 89 int relevance,
90 AutocompleteMatch::Type type, 90 AutocompleteMatch::Type type,
91 bool is_keyword, 91 bool is_keyword,
92 const string16& match_contents, 92 const base::string16& match_contents,
93 const string16& annotation, 93 const base::string16& annotation,
94 const TemplateURL* template_url, 94 const TemplateURL* template_url,
95 const string16& query_string, 95 const base::string16& query_string,
96 const std::string& suggest_query_params, 96 const std::string& suggest_query_params,
97 int accepted_suggestion, 97 int accepted_suggestion,
98 int omnibox_start_margin, 98 int omnibox_start_margin,
99 bool append_extra_query_params); 99 bool append_extra_query_params);
100 100
101 // Returns whether the SearchProvider previously flagged |match| as a query 101 // Returns whether the SearchProvider previously flagged |match| as a query
102 // that should be prefetched. 102 // that should be prefetched.
103 static bool ShouldPrefetch(const AutocompleteMatch& match); 103 static bool ShouldPrefetch(const AutocompleteMatch& match);
104 104
105 // Extracts the suggest response metadata which SearchProvider previously 105 // Extracts the suggest response metadata which SearchProvider previously
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // . The default provider. This corresponds to the user's default search 144 // . The default provider. This corresponds to the user's default search
145 // engine. This is always used, except for the rare case of no default 145 // engine. This is always used, except for the rare case of no default
146 // engine. 146 // engine.
147 // . The keyword provider. This is used if the user has typed in a keyword. 147 // . The keyword provider. This is used if the user has typed in a keyword.
148 class Providers { 148 class Providers {
149 public: 149 public:
150 explicit Providers(TemplateURLService* template_url_service); 150 explicit Providers(TemplateURLService* template_url_service);
151 151
152 // Returns true if the specified providers match the two providers cached 152 // Returns true if the specified providers match the two providers cached
153 // by this class. 153 // by this class.
154 bool equal(const string16& default_provider, 154 bool equal(const base::string16& default_provider,
155 const string16& keyword_provider) const { 155 const base::string16& keyword_provider) const {
156 return (default_provider == default_provider_) && 156 return (default_provider == default_provider_) &&
157 (keyword_provider == keyword_provider_); 157 (keyword_provider == keyword_provider_);
158 } 158 }
159 159
160 // Resets the cached providers. 160 // Resets the cached providers.
161 void set(const string16& default_provider, 161 void set(const base::string16& default_provider,
162 const string16& keyword_provider) { 162 const base::string16& keyword_provider) {
163 default_provider_ = default_provider; 163 default_provider_ = default_provider;
164 keyword_provider_ = keyword_provider; 164 keyword_provider_ = keyword_provider;
165 } 165 }
166 166
167 TemplateURLService* template_url_service() { return template_url_service_; } 167 TemplateURLService* template_url_service() { return template_url_service_; }
168 const string16& default_provider() const { return default_provider_; } 168 const base::string16& default_provider() const { return default_provider_; }
169 const string16& keyword_provider() const { return keyword_provider_; } 169 const base::string16& keyword_provider() const { return keyword_provider_; }
170 170
171 // NOTE: These may return NULL even if the provider members are nonempty! 171 // NOTE: These may return NULL even if the provider members are nonempty!
172 const TemplateURL* GetDefaultProviderURL() const; 172 const TemplateURL* GetDefaultProviderURL() const;
173 const TemplateURL* GetKeywordProviderURL() const; 173 const TemplateURL* GetKeywordProviderURL() const;
174 174
175 // Returns true if there is a valid keyword provider. 175 // Returns true if there is a valid keyword provider.
176 bool has_keyword_provider() const { return !keyword_provider_.empty(); } 176 bool has_keyword_provider() const { return !keyword_provider_.empty(); }
177 177
178 private: 178 private:
179 TemplateURLService* template_url_service_; 179 TemplateURLService* template_url_service_;
180 180
181 // Cached across the life of a query so we behave consistently even if the 181 // Cached across the life of a query so we behave consistently even if the
182 // user changes their default while the query is running. 182 // user changes their default while the query is running.
183 string16 default_provider_; 183 base::string16 default_provider_;
184 string16 keyword_provider_; 184 base::string16 keyword_provider_;
185 185
186 DISALLOW_COPY_AND_ASSIGN(Providers); 186 DISALLOW_COPY_AND_ASSIGN(Providers);
187 }; 187 };
188 188
189 // The Result classes are intermediate representations of AutocompleteMatches, 189 // The Result classes are intermediate representations of AutocompleteMatches,
190 // simply containing relevance-ranked search and navigation suggestions. 190 // simply containing relevance-ranked search and navigation suggestions.
191 // They may be cached to provide some synchronous matches while requests for 191 // They may be cached to provide some synchronous matches while requests for
192 // new suggestions from updated input are in flight. 192 // new suggestions from updated input are in flight.
193 // TODO(msw) Extend these classes to generate their corresponding matches and 193 // TODO(msw) Extend these classes to generate their corresponding matches and
194 // other requisite data, in order to consolidate and simplify the 194 // other requisite data, in order to consolidate and simplify the
(...skipping 10 matching lines...) Expand all
205 int relevance() const { return relevance_; } 205 int relevance() const { return relevance_; }
206 void set_relevance(int relevance) { relevance_ = relevance; } 206 void set_relevance(int relevance) { relevance_ = relevance; }
207 207
208 bool relevance_from_server() const { return relevance_from_server_; } 208 bool relevance_from_server() const { return relevance_from_server_; }
209 void set_relevance_from_server(bool relevance_from_server) { 209 void set_relevance_from_server(bool relevance_from_server) {
210 relevance_from_server_ = relevance_from_server; 210 relevance_from_server_ = relevance_from_server;
211 } 211 }
212 212
213 // Returns if this result is inlineable against the current input |input|. 213 // Returns if this result is inlineable against the current input |input|.
214 // Non-inlineable results are stale. 214 // Non-inlineable results are stale.
215 virtual bool IsInlineable(const string16& input) const = 0; 215 virtual bool IsInlineable(const base::string16& input) const = 0;
216 216
217 // Returns the default relevance value for this result (which may 217 // Returns the default relevance value for this result (which may
218 // be left over from a previous omnibox input) given the current 218 // be left over from a previous omnibox input) given the current
219 // input and whether the current input caused a keyword provider 219 // input and whether the current input caused a keyword provider
220 // to be active. 220 // to be active.
221 virtual int CalculateRelevance(const AutocompleteInput& input, 221 virtual int CalculateRelevance(const AutocompleteInput& input,
222 bool keyword_provider_requested) const = 0; 222 bool keyword_provider_requested) const = 0;
223 223
224 protected: 224 protected:
225 // True if the result came from the keyword provider. 225 // True if the result came from the keyword provider.
226 bool from_keyword_provider_; 226 bool from_keyword_provider_;
227 227
228 // The relevance score. 228 // The relevance score.
229 int relevance_; 229 int relevance_;
230 230
231 private: 231 private:
232 // Whether this result's relevance score was fully or partly calculated 232 // Whether this result's relevance score was fully or partly calculated
233 // based on server information, and thus is assumed to be more accurate. 233 // based on server information, and thus is assumed to be more accurate.
234 // This is ultimately used in 234 // This is ultimately used in
235 // SearchProvider::ConvertResultsToAutocompleteMatches(), see comments 235 // SearchProvider::ConvertResultsToAutocompleteMatches(), see comments
236 // there. 236 // there.
237 bool relevance_from_server_; 237 bool relevance_from_server_;
238 }; 238 };
239 239
240 class SuggestResult : public Result { 240 class SuggestResult : public Result {
241 public: 241 public:
242 SuggestResult(const string16& suggestion, 242 SuggestResult(const base::string16& suggestion,
243 const string16& match_contents, 243 const base::string16& match_contents,
244 const string16& annotation, 244 const base::string16& annotation,
245 const std::string& suggest_query_params, 245 const std::string& suggest_query_params,
246 const std::string& deletion_url, 246 const std::string& deletion_url,
247 bool from_keyword_provider, 247 bool from_keyword_provider,
248 int relevance, 248 int relevance,
249 bool relevance_from_server, 249 bool relevance_from_server,
250 bool should_prefetch); 250 bool should_prefetch);
251 virtual ~SuggestResult(); 251 virtual ~SuggestResult();
252 252
253 const string16& suggestion() const { return suggestion_; } 253 const base::string16& suggestion() const { return suggestion_; }
254 const string16& match_contents() const { return match_contents_; } 254 const base::string16& match_contents() const { return match_contents_; }
255 const string16& annotation() const { return annotation_; } 255 const base::string16& annotation() const { return annotation_; }
256 const std::string& suggest_query_params() const { 256 const std::string& suggest_query_params() const {
257 return suggest_query_params_; 257 return suggest_query_params_;
258 } 258 }
259 const std::string& deletion_url() const { return deletion_url_; } 259 const std::string& deletion_url() const { return deletion_url_; }
260 bool should_prefetch() const { return should_prefetch_; } 260 bool should_prefetch() const { return should_prefetch_; }
261 261
262 // Result: 262 // Result:
263 virtual bool IsInlineable(const string16& input) const OVERRIDE; 263 virtual bool IsInlineable(const base::string16& input) const OVERRIDE;
264 virtual int CalculateRelevance( 264 virtual int CalculateRelevance(
265 const AutocompleteInput& input, 265 const AutocompleteInput& input,
266 bool keyword_provider_requested) const OVERRIDE; 266 bool keyword_provider_requested) const OVERRIDE;
267 267
268 private: 268 private:
269 // The search terms to be used for this suggestion. 269 // The search terms to be used for this suggestion.
270 string16 suggestion_; 270 base::string16 suggestion_;
271 271
272 // The contents to be displayed in the autocomplete match. 272 // The contents to be displayed in the autocomplete match.
273 string16 match_contents_; 273 base::string16 match_contents_;
274 274
275 // Optional annotation for the |match_contents_| for disambiguation. 275 // Optional annotation for the |match_contents_| for disambiguation.
276 // This may be displayed in the autocomplete match contents, but is defined 276 // This may be displayed in the autocomplete match contents, but is defined
277 // separately to facilitate different formatting. 277 // separately to facilitate different formatting.
278 string16 annotation_; 278 base::string16 annotation_;
279 279
280 // Optional additional parameters to be added to the search URL. 280 // Optional additional parameters to be added to the search URL.
281 std::string suggest_query_params_; 281 std::string suggest_query_params_;
282 282
283 // Optional deletion URL provided with suggestions. Fetching this URL 283 // Optional deletion URL provided with suggestions. Fetching this URL
284 // should result in some reasonable deletion behaviour on the server, 284 // should result in some reasonable deletion behaviour on the server,
285 // e.g. deleting this term out of a user's server-side search history. 285 // e.g. deleting this term out of a user's server-side search history.
286 std::string deletion_url_; 286 std::string deletion_url_;
287 287
288 // Should this result be prefetched? 288 // Should this result be prefetched?
289 bool should_prefetch_; 289 bool should_prefetch_;
290 }; 290 };
291 291
292 class NavigationResult : public Result { 292 class NavigationResult : public Result {
293 public: 293 public:
294 // |provider| is necessary to use StringForURLDisplay() in order to 294 // |provider| is necessary to use StringForURLDisplay() in order to
295 // compute |formatted_url_|. 295 // compute |formatted_url_|.
296 NavigationResult(const AutocompleteProvider& provider, 296 NavigationResult(const AutocompleteProvider& provider,
297 const GURL& url, 297 const GURL& url,
298 const string16& description, 298 const base::string16& description,
299 bool from_keyword_provider, 299 bool from_keyword_provider,
300 int relevance, 300 int relevance,
301 bool relevance_from_server); 301 bool relevance_from_server);
302 virtual ~NavigationResult(); 302 virtual ~NavigationResult();
303 303
304 const GURL& url() const { return url_; } 304 const GURL& url() const { return url_; }
305 const string16& description() const { return description_; } 305 const base::string16& description() const { return description_; }
306 const string16& formatted_url() const { return formatted_url_; } 306 const base::string16& formatted_url() const { return formatted_url_; }
307 307
308 // Result: 308 // Result:
309 virtual bool IsInlineable(const string16& input) const OVERRIDE; 309 virtual bool IsInlineable(const base::string16& input) const OVERRIDE;
310 virtual int CalculateRelevance( 310 virtual int CalculateRelevance(
311 const AutocompleteInput& input, 311 const AutocompleteInput& input,
312 bool keyword_provider_requested) const OVERRIDE; 312 bool keyword_provider_requested) const OVERRIDE;
313 313
314 private: 314 private:
315 // The suggested url for navigation. 315 // The suggested url for navigation.
316 GURL url_; 316 GURL url_;
317 317
318 // The properly formatted ("fixed up") URL string with equivalent meaning 318 // The properly formatted ("fixed up") URL string with equivalent meaning
319 // to the one in |url_|. 319 // to the one in |url_|.
320 string16 formatted_url_; 320 base::string16 formatted_url_;
321 321
322 // The suggested navigational result description; generally the site name. 322 // The suggested navigational result description; generally the site name.
323 string16 description_; 323 base::string16 description_;
324 }; 324 };
325 325
326 class CompareScoredResults; 326 class CompareScoredResults;
327 327
328 typedef std::vector<SuggestResult> SuggestResults; 328 typedef std::vector<SuggestResult> SuggestResults;
329 typedef std::vector<NavigationResult> NavigationResults; 329 typedef std::vector<NavigationResult> NavigationResults;
330 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; 330 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults;
331 typedef std::pair<string16, std::string> MatchKey; 331 typedef std::pair<string16, std::string> MatchKey;
332 typedef std::map<MatchKey, AutocompleteMatch> MatchMap; 332 typedef std::map<MatchKey, AutocompleteMatch> MatchMap;
333 typedef ScopedVector<SuggestionDeletionHandler> SuggestionDeletionHandlers; 333 typedef ScopedVector<SuggestionDeletionHandler> SuggestionDeletionHandlers;
(...skipping 28 matching lines...) Expand all
362 362
363 // The JSON metadata associated with this server response. 363 // The JSON metadata associated with this server response.
364 std::string metadata; 364 std::string metadata;
365 365
366 private: 366 private:
367 DISALLOW_COPY_AND_ASSIGN(Results); 367 DISALLOW_COPY_AND_ASSIGN(Results);
368 }; 368 };
369 369
370 // Removes non-inlineable results until either the top result can inline 370 // Removes non-inlineable results until either the top result can inline
371 // autocomplete the current input or verbatim outscores the top result. 371 // autocomplete the current input or verbatim outscores the top result.
372 static void RemoveStaleResults(const string16& input, 372 static void RemoveStaleResults(const base::string16& input,
373 int verbatim_relevance, 373 int verbatim_relevance,
374 SuggestResults* suggest_results, 374 SuggestResults* suggest_results,
375 NavigationResults* navigation_results); 375 NavigationResults* navigation_results);
376 376
377 // Calculates the relevance score for the keyword verbatim result (if the 377 // Calculates the relevance score for the keyword verbatim result (if the
378 // input matches one of the profile's keyword). 378 // input matches one of the profile's keyword).
379 static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type, 379 static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type,
380 bool prefer_keyword); 380 bool prefer_keyword);
381 381
382 // AutocompleteProvider: 382 // AutocompleteProvider:
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // whether the results correspond to the keyword provider or default provider. 486 // whether the results correspond to the keyword provider or default provider.
487 void AddHistoryResultsToMap(const HistoryResults& results, 487 void AddHistoryResultsToMap(const HistoryResults& results,
488 bool is_keyword, 488 bool is_keyword,
489 int did_not_accept_suggestion, 489 int did_not_accept_suggestion,
490 MatchMap* map); 490 MatchMap* map);
491 491
492 // Calculates relevance scores for all |results|. 492 // Calculates relevance scores for all |results|.
493 SuggestResults ScoreHistoryResults(const HistoryResults& results, 493 SuggestResults ScoreHistoryResults(const HistoryResults& results,
494 bool base_prevent_inline_autocomplete, 494 bool base_prevent_inline_autocomplete,
495 bool input_multiple_words, 495 bool input_multiple_words,
496 const string16& input_text, 496 const base::string16& input_text,
497 bool is_keyword); 497 bool is_keyword);
498 498
499 // Adds matches for |results| to |map|. 499 // Adds matches for |results| to |map|.
500 void AddSuggestResultsToMap(const SuggestResults& results, 500 void AddSuggestResultsToMap(const SuggestResults& results,
501 const std::string& metadata, 501 const std::string& metadata,
502 MatchMap* map); 502 MatchMap* map);
503 503
504 // Gets the relevance score for the verbatim result. This value may be 504 // Gets the relevance score for the verbatim result. This value may be
505 // provided by the suggest server or calculated locally; if 505 // provided by the suggest server or calculated locally; if
506 // |relevance_from_server| is non-NULL, it will be set to indicate which of 506 // |relevance_from_server| is non-NULL, it will be set to indicate which of
(...skipping 26 matching lines...) Expand all
533 // scores. When using the aggressive method, scores may exceed 1300 533 // scores. When using the aggressive method, scores may exceed 1300
534 // unless |prevent_search_history_inlining| is set. 534 // unless |prevent_search_history_inlining| is set.
535 int CalculateRelevanceForHistory(const base::Time& time, 535 int CalculateRelevanceForHistory(const base::Time& time,
536 bool is_keyword, 536 bool is_keyword,
537 bool use_aggressive_method, 537 bool use_aggressive_method,
538 bool prevent_search_history_inlining) const; 538 bool prevent_search_history_inlining) const;
539 539
540 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with 540 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with
541 // the supplied relevance. Adds this match to |map|; if such a match already 541 // the supplied relevance. Adds this match to |map|; if such a match already
542 // exists, whichever one has lower relevance is eliminated. 542 // exists, whichever one has lower relevance is eliminated.
543 void AddMatchToMap(const string16& input_text, 543 void AddMatchToMap(const base::string16& input_text,
544 int relevance, 544 int relevance,
545 bool relevance_from_server, 545 bool relevance_from_server,
546 bool should_prefetch, 546 bool should_prefetch,
547 const std::string& metadata, 547 const std::string& metadata,
548 AutocompleteMatch::Type type, 548 AutocompleteMatch::Type type,
549 bool is_keyword, 549 bool is_keyword,
550 const string16& match_contents, 550 const base::string16& match_contents,
551 const string16& annotation, 551 const base::string16& annotation,
552 const string16& query_string, 552 const base::string16& query_string,
553 int accepted_suggestion, 553 int accepted_suggestion,
554 const std::string& suggest_query_params, 554 const std::string& suggest_query_params,
555 const std::string& deletion_url, 555 const std::string& deletion_url,
556 MatchMap* map); 556 MatchMap* map);
557 557
558 // Returns an AutocompleteMatch for a navigational suggestion. 558 // Returns an AutocompleteMatch for a navigational suggestion.
559 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); 559 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation);
560 560
561 // Resets the scores of all |keyword_navigation_results_| matches to 561 // Resets the scores of all |keyword_navigation_results_| matches to
562 // be below that of the top keyword query match (the verbatim match 562 // be below that of the top keyword query match (the verbatim match
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 // If true, search history query suggestions will score low enough that 676 // If true, search history query suggestions will score low enough that
677 // they will not be inlined. 677 // they will not be inlined.
678 bool prevent_search_history_inlining_; 678 bool prevent_search_history_inlining_;
679 679
680 GURL current_page_url_; 680 GURL current_page_url_;
681 681
682 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 682 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
683 }; 683 };
684 684
685 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 685 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698