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

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

Issue 11198074: Initial implementation of dedupping search provider's URLs. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add a missing include. Created 8 years, 1 month 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 #include "chrome/browser/autocomplete/autocomplete_controller.h" 5 #include "chrome/browser/autocomplete/autocomplete_controller.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // the providers again. 271 // the providers again.
272 UpdateResult(false); 272 UpdateResult(false);
273 } 273 }
274 274
275 void AutocompleteController::OnProviderUpdate(bool updated_matches) { 275 void AutocompleteController::OnProviderUpdate(bool updated_matches) {
276 if (in_zero_suggest_) { 276 if (in_zero_suggest_) {
277 // We got ZeroSuggest results before Start(). Show only those results, 277 // We got ZeroSuggest results before Start(). Show only those results,
278 // because results from other providers are stale. 278 // because results from other providers are stale.
279 result_.Reset(); 279 result_.Reset();
280 result_.AppendMatches(zero_suggest_provider_->matches()); 280 result_.AppendMatches(zero_suggest_provider_->matches());
281 result_.SortAndCull(input_); 281 result_.SortAndCull(input_, profile_);
282 NotifyChanged(true); 282 NotifyChanged(true);
283 } else { 283 } else {
284 CheckIfDone(); 284 CheckIfDone();
285 // Multiple providers may provide synchronous results, so we only update the 285 // Multiple providers may provide synchronous results, so we only update the
286 // results if we're not in Start(). 286 // results if we're not in Start().
287 if (!in_start_ && (updated_matches || done_)) 287 if (!in_start_ && (updated_matches || done_))
288 UpdateResult(false); 288 UpdateResult(false);
289 } 289 }
290 } 290 }
291 291
(...skipping 12 matching lines...) Expand all
304 304
305 void AutocompleteController::UpdateResult(bool is_synchronous_pass) { 305 void AutocompleteController::UpdateResult(bool is_synchronous_pass) {
306 AutocompleteResult last_result; 306 AutocompleteResult last_result;
307 last_result.Swap(&result_); 307 last_result.Swap(&result_);
308 308
309 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); 309 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end();
310 ++i) 310 ++i)
311 result_.AppendMatches((*i)->matches()); 311 result_.AppendMatches((*i)->matches());
312 312
313 // Sort the matches and trim to a small number of "best" matches. 313 // Sort the matches and trim to a small number of "best" matches.
314 result_.SortAndCull(input_); 314 result_.SortAndCull(input_, profile_);
315 315
316 // Need to validate before invoking CopyOldMatches as the old matches are not 316 // Need to validate before invoking CopyOldMatches as the old matches are not
317 // valid against the current input. 317 // valid against the current input.
318 #ifndef NDEBUG 318 #ifndef NDEBUG
319 result_.Validate(); 319 result_.Validate();
320 #endif 320 #endif
321 321
322 if (!done_) { 322 if (!done_) {
323 // This conditional needs to match the conditional in Start that invokes 323 // This conditional needs to match the conditional in Start that invokes
324 // StartExpireTimer. 324 // StartExpireTimer.
325 result_.CopyOldMatches(input_, last_result); 325 result_.CopyOldMatches(input_, last_result, profile_);
326 } 326 }
327 327
328 UpdateKeywordDescriptions(&result_); 328 UpdateKeywordDescriptions(&result_);
329 UpdateAssociatedKeywords(&result_); 329 UpdateAssociatedKeywords(&result_);
330 UpdateAssistedQueryStats(&result_); 330 UpdateAssistedQueryStats(&result_);
331 331
332 bool notify_default_match = is_synchronous_pass; 332 bool notify_default_match = is_synchronous_pass;
333 if (!is_synchronous_pass) { 333 if (!is_synchronous_pass) {
334 const bool last_default_was_valid = 334 const bool last_default_was_valid =
335 last_result.default_match() != last_result.end(); 335 last_result.default_match() != last_result.end();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } else { 402 } else {
403 count++; 403 count++;
404 } 404 }
405 last_type = type; 405 last_type = type;
406 } 406 }
407 AppendAvailableAutocompletion(last_type, count, &autocompletions); 407 AppendAvailableAutocompletion(last_type, count, &autocompletions);
408 408
409 // Go over all matches and set AQS if the match supports it. 409 // Go over all matches and set AQS if the match supports it.
410 for (size_t index = 0; index < result->size(); ++index) { 410 for (size_t index = 0; index < result->size(); ++index) {
411 AutocompleteMatch* match = result->match_at(index); 411 AutocompleteMatch* match = result->match_at(index);
412 const TemplateURL* template_url = match->GetTemplateURL(profile_); 412 const TemplateURL* template_url = match->GetTemplateURL(profile_, false);
413 if (!template_url || !match->search_terms_args.get()) 413 if (!template_url || !match->search_terms_args.get())
414 continue; 414 continue;
415 match->search_terms_args->assisted_query_stats = 415 match->search_terms_args->assisted_query_stats =
416 base::StringPrintf("chrome.%" PRIuS ".%s", 416 base::StringPrintf("chrome.%" PRIuS ".%s",
417 index, 417 index,
418 autocompletions.c_str()); 418 autocompletions.c_str());
419 match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms( 419 match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms(
420 *match->search_terms_args)); 420 *match->search_terms_args));
421 } 421 }
422 } 422 }
423 423
424 void AutocompleteController::UpdateKeywordDescriptions( 424 void AutocompleteController::UpdateKeywordDescriptions(
425 AutocompleteResult* result) { 425 AutocompleteResult* result) {
426 string16 last_keyword; 426 string16 last_keyword;
427 for (AutocompleteResult::iterator i(result->begin()); i != result->end(); 427 for (AutocompleteResult::iterator i(result->begin()); i != result->end();
428 ++i) { 428 ++i) {
429 if ((i->provider->type() == AutocompleteProvider::TYPE_KEYWORD && 429 if ((i->provider->type() == AutocompleteProvider::TYPE_KEYWORD &&
430 !i->keyword.empty()) || 430 !i->keyword.empty()) ||
431 (i->provider->type() == AutocompleteProvider::TYPE_SEARCH && 431 (i->provider->type() == AutocompleteProvider::TYPE_SEARCH &&
432 AutocompleteMatch::IsSearchType(i->type))) { 432 AutocompleteMatch::IsSearchType(i->type))) {
433 i->description.clear(); 433 i->description.clear();
434 i->description_class.clear(); 434 i->description_class.clear();
435 DCHECK(!i->keyword.empty()); 435 DCHECK(!i->keyword.empty());
436 if (i->keyword != last_keyword) { 436 if (i->keyword != last_keyword) {
437 const TemplateURL* template_url = i->GetTemplateURL(profile_); 437 const TemplateURL* template_url = i->GetTemplateURL(profile_, false);
438 if (template_url) { 438 if (template_url) {
439 i->description = l10n_util::GetStringFUTF16( 439 i->description = l10n_util::GetStringFUTF16(
440 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, 440 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION,
441 template_url->AdjustedShortNameForLocaleDirection()); 441 template_url->AdjustedShortNameForLocaleDirection());
442 i->description_class.push_back( 442 i->description_class.push_back(
443 ACMatchClassification(0, ACMatchClassification::DIM)); 443 ACMatchClassification(0, ACMatchClassification::DIM));
444 } 444 }
445 last_keyword = i->keyword; 445 last_keyword = i->keyword;
446 } 446 }
447 } else { 447 } else {
(...skipping 23 matching lines...) Expand all
471 } 471 }
472 done_ = true; 472 done_ = true;
473 } 473 }
474 474
475 void AutocompleteController::StartExpireTimer() { 475 void AutocompleteController::StartExpireTimer() {
476 if (result_.HasCopiedMatches()) 476 if (result_.HasCopiedMatches())
477 expire_timer_.Start(FROM_HERE, 477 expire_timer_.Start(FROM_HERE,
478 base::TimeDelta::FromMilliseconds(kExpireTimeMS), 478 base::TimeDelta::FromMilliseconds(kExpireTimeMS),
479 this, &AutocompleteController::ExpireCopiedEntries); 479 this, &AutocompleteController::ExpireCopiedEntries);
480 } 480 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_browsertest.cc ('k') | chrome/browser/autocomplete/autocomplete_match.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698