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

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

Issue 18119005: Misc. cleanup: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 5 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 AutocompleteProvider::TYPE_SEARCH), 249 AutocompleteProvider::TYPE_SEARCH),
250 providers_(TemplateURLServiceFactory::GetForProfile(profile)), 250 providers_(TemplateURLServiceFactory::GetForProfile(profile)),
251 suggest_results_pending_(0), 251 suggest_results_pending_(0),
252 field_trial_triggered_(false), 252 field_trial_triggered_(false),
253 field_trial_triggered_in_session_(false), 253 field_trial_triggered_in_session_(false),
254 omnibox_start_margin_(-1) { 254 omnibox_start_margin_(-1) {
255 } 255 }
256 256
257 // static 257 // static
258 AutocompleteMatch SearchProvider::CreateSearchSuggestion( 258 AutocompleteMatch SearchProvider::CreateSearchSuggestion(
259 Profile* profile,
260 AutocompleteProvider* autocomplete_provider, 259 AutocompleteProvider* autocomplete_provider,
261 const AutocompleteInput& input, 260 int relevance,
261 AutocompleteMatch::Type type,
262 const TemplateURL* template_url,
262 const string16& query_string, 263 const string16& query_string,
263 const string16& input_text, 264 const string16& input_text,
264 int relevance, 265 const AutocompleteInput& input,
265 AutocompleteMatch::Type type, 266 bool is_keyword,
266 int accepted_suggestion, 267 int accepted_suggestion,
267 bool is_keyword,
268 const string16& keyword,
269 int omnibox_start_margin) { 268 int omnibox_start_margin) {
270 AutocompleteMatch match(autocomplete_provider, relevance, false, type); 269 AutocompleteMatch match(autocomplete_provider, relevance, false, type);
271 270
272 // Bail out now if we don't actually have a valid provider. 271 if (!template_url)
273 match.keyword = keyword;
274 const TemplateURL* provider_url = match.GetTemplateURL(profile, false);
275 if (provider_url == NULL)
276 return match; 272 return match;
273 match.keyword = template_url->keyword();
277 274
278 match.contents.assign(query_string); 275 match.contents.assign(query_string);
279 // We do intra-string highlighting for suggestions - the suggested segment 276 // We do intra-string highlighting for suggestions - the suggested segment
280 // will be highlighted, e.g. for input_text = "you" the suggestion may be 277 // will be highlighted, e.g. for input_text = "you" the suggestion may be
281 // "youtube", so we'll bold the "tube" section: you*tube*. 278 // "youtube", so we'll bold the "tube" section: you*tube*.
282 if (input_text != query_string) { 279 if (input_text != query_string) {
283 size_t input_position = match.contents.find(input_text); 280 size_t input_position = match.contents.find(input_text);
284 if (input_position == string16::npos) { 281 if (input_position == string16::npos) {
285 // The input text is not a substring of the query string, e.g. input 282 // The input text is not a substring of the query string, e.g. input
286 // text is "slasdot" and the query string is "slashdot", so we bold the 283 // text is "slasdot" and the query string is "slashdot", so we bold the
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 match.fill_into_edit.assign(ASCIIToUTF16("?")); 319 match.fill_into_edit.assign(ASCIIToUTF16("?"));
323 if (is_keyword) 320 if (is_keyword)
324 match.fill_into_edit.append(match.keyword + char16(' ')); 321 match.fill_into_edit.append(match.keyword + char16(' '));
325 if (!input.prevent_inline_autocomplete() && 322 if (!input.prevent_inline_autocomplete() &&
326 StartsWith(query_string, input_text, false)) { 323 StartsWith(query_string, input_text, false)) {
327 match.inline_autocomplete_offset = 324 match.inline_autocomplete_offset =
328 match.fill_into_edit.length() + input_text.length(); 325 match.fill_into_edit.length() + input_text.length();
329 } 326 }
330 match.fill_into_edit.append(query_string); 327 match.fill_into_edit.append(query_string);
331 328
332 const TemplateURLRef& search_url = provider_url->url_ref(); 329 const TemplateURLRef& search_url = template_url->url_ref();
333 DCHECK(search_url.SupportsReplacement()); 330 DCHECK(search_url.SupportsReplacement());
334 match.search_terms_args.reset( 331 match.search_terms_args.reset(
335 new TemplateURLRef::SearchTermsArgs(query_string)); 332 new TemplateURLRef::SearchTermsArgs(query_string));
336 match.search_terms_args->original_query = input_text; 333 match.search_terms_args->original_query = input_text;
337 match.search_terms_args->accepted_suggestion = accepted_suggestion; 334 match.search_terms_args->accepted_suggestion = accepted_suggestion;
338 match.search_terms_args->omnibox_start_margin = omnibox_start_margin; 335 match.search_terms_args->omnibox_start_margin = omnibox_start_margin;
339 // This is the destination URL sans assisted query stats. This must be set 336 // This is the destination URL sans assisted query stats. This must be set
340 // so the AutocompleteController can properly de-dupe; the controller will 337 // so the AutocompleteController can properly de-dupe; the controller will
341 // eventually overwrite it before it reaches the user. 338 // eventually overwrite it before it reaches the user.
342 match.destination_url = 339 match.destination_url =
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 } 1363 }
1367 1364
1368 void SearchProvider::AddMatchToMap(const string16& query_string, 1365 void SearchProvider::AddMatchToMap(const string16& query_string,
1369 const string16& input_text, 1366 const string16& input_text,
1370 int relevance, 1367 int relevance,
1371 bool relevance_from_server, 1368 bool relevance_from_server,
1372 AutocompleteMatch::Type type, 1369 AutocompleteMatch::Type type,
1373 int accepted_suggestion, 1370 int accepted_suggestion,
1374 bool is_keyword, 1371 bool is_keyword,
1375 MatchMap* map) { 1372 MatchMap* map) {
1376 const string16& keyword = is_keyword ? 1373 const TemplateURL* template_url = is_keyword ?
1377 providers_.keyword_provider() : providers_.default_provider(); 1374 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL();
1378 AutocompleteMatch match = CreateSearchSuggestion(profile_, this, input_, 1375 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type,
1379 query_string, input_text, relevance, type, accepted_suggestion, 1376 template_url, query_string, input_text, input_, is_keyword,
1380 is_keyword, keyword, omnibox_start_margin_); 1377 accepted_suggestion, omnibox_start_margin_);
1381 if (!match.destination_url.is_valid()) 1378 if (!match.destination_url.is_valid())
1382 return; 1379 return;
1383 match.RecordAdditionalInfo(kRelevanceFromServerKey, 1380 match.RecordAdditionalInfo(kRelevanceFromServerKey,
1384 relevance_from_server ? kTrue : kFalse); 1381 relevance_from_server ? kTrue : kFalse);
1385 1382
1386 // Try to add |match| to |map|. If a match for |query_string| is already in 1383 // Try to add |match| to |map|. If a match for |query_string| is already in
1387 // |map|, replace it if |match| is more relevant. 1384 // |map|, replace it if |match| is more relevant.
1388 // NOTE: Keep this ToLower() call in sync with url_database.cc. 1385 // NOTE: Keep this ToLower() call in sync with url_database.cc.
1389 const std::pair<MatchMap::iterator, bool> i( 1386 const std::pair<MatchMap::iterator, bool> i(
1390 map->insert(std::make_pair(base::i18n::ToLower(query_string), match))); 1387 map->insert(std::make_pair(base::i18n::ToLower(query_string), match)));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 it->set_relevance(max_query_relevance); 1501 it->set_relevance(max_query_relevance);
1505 it->set_relevance_from_server(relevance_from_server); 1502 it->set_relevance_from_server(relevance_from_server);
1506 } 1503 }
1507 } 1504 }
1508 1505
1509 void SearchProvider::UpdateDone() { 1506 void SearchProvider::UpdateDone() {
1510 // We're done when the timer isn't running, there are no suggest queries 1507 // We're done when the timer isn't running, there are no suggest queries
1511 // pending, and we're not waiting on Instant. 1508 // pending, and we're not waiting on Instant.
1512 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1509 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1513 } 1510 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.h ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698