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

Side by Side Diff: components/omnibox/browser/history_url_provider.cc

Issue 2048693003: Misc. omnibox cleanup: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resync Created 4 years, 6 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
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 "components/omnibox/browser/history_url_provider.h" 5 #include "components/omnibox/browser/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if ((score_buckets.relevance_cap() != -1) && 120 if ((score_buckets.relevance_cap() != -1) &&
121 (undecayed_relevance >= score_buckets.relevance_cap())) 121 (undecayed_relevance >= score_buckets.relevance_cap()))
122 return undecayed_relevance; 122 return undecayed_relevance;
123 123
124 // Time based decay using half-life time. 124 // Time based decay using half-life time.
125 double decayed_count = undecayed_count; 125 double decayed_count = undecayed_count;
126 double decay_factor = score_buckets.HalfLifeTimeDecay(time_since_last_visit); 126 double decay_factor = score_buckets.HalfLifeTimeDecay(time_since_last_visit);
127 if (decayed_count > 0) 127 if (decayed_count > 0)
128 decayed_count *= decay_factor; 128 decayed_count *= decay_factor;
129 129
130 const HUPScoringParams::ScoreBuckets::CountMaxRelevance* score_bucket = NULL; 130 const HUPScoringParams::ScoreBuckets::CountMaxRelevance* score_bucket =
131 nullptr;
131 const double factor = (score_buckets.use_decay_factor() ? 132 const double factor = (score_buckets.use_decay_factor() ?
132 decay_factor : decayed_count); 133 decay_factor : decayed_count);
133 for (size_t i = 0; i < score_buckets.buckets().size(); ++i) { 134 for (size_t i = 0; i < score_buckets.buckets().size(); ++i) {
134 score_bucket = &score_buckets.buckets()[i]; 135 score_bucket = &score_buckets.buckets()[i];
135 if (factor >= score_bucket->first) 136 if (factor >= score_bucket->first)
136 break; 137 break;
137 } 138 }
138 139
139 return (score_bucket && (undecayed_relevance > score_bucket->second)) ? 140 return (score_bucket && (undecayed_relevance > score_bucket->second)) ?
140 score_bucket->second : undecayed_relevance; 141 score_bucket->second : undecayed_relevance;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 const SearchTermsData& search_terms_data) 428 const SearchTermsData& search_terms_data)
428 : message_loop(base::MessageLoop::current()), 429 : message_loop(base::MessageLoop::current()),
429 input(input), 430 input(input),
430 prevent_inline_autocomplete(input.prevent_inline_autocomplete()), 431 prevent_inline_autocomplete(input.prevent_inline_autocomplete()),
431 trim_http(trim_http), 432 trim_http(trim_http),
432 what_you_typed_match(what_you_typed_match), 433 what_you_typed_match(what_you_typed_match),
433 failed(false), 434 failed(false),
434 exact_suggestion_is_in_history(false), 435 exact_suggestion_is_in_history(false),
435 promote_type(NEITHER), 436 promote_type(NEITHER),
436 default_search_provider(default_search_provider ? 437 default_search_provider(default_search_provider ?
437 new TemplateURL(default_search_provider->data()) : NULL), 438 new TemplateURL(default_search_provider->data()) : nullptr),
438 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { 439 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) {
439 } 440 }
440 441
441 HistoryURLProviderParams::~HistoryURLProviderParams() { 442 HistoryURLProviderParams::~HistoryURLProviderParams() {
442 } 443 }
443 444
444 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, 445 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client,
445 AutocompleteProviderListener* listener) 446 AutocompleteProviderListener* listener)
446 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client), 447 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client),
447 listener_(listener), 448 listener_(listener),
448 params_(NULL), 449 params_(nullptr),
449 search_url_database_(OmniboxFieldTrial::HUPSearchDatabase()) { 450 search_url_database_(OmniboxFieldTrial::HUPSearchDatabase()) {
450 // Initialize the default HUP scoring params. 451 // Initialize the default HUP scoring params.
451 OmniboxFieldTrial::GetDefaultHUPScoringParams(&scoring_params_); 452 OmniboxFieldTrial::GetDefaultHUPScoringParams(&scoring_params_);
452 // Initialize HUP scoring params based on the current experiment. 453 // Initialize HUP scoring params based on the current experiment.
453 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); 454 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_);
454 } 455 }
455 456
456 void HistoryURLProvider::Start(const AutocompleteInput& input, 457 void HistoryURLProvider::Start(const AutocompleteInput& input,
457 bool minimal_changes) { 458 bool minimal_changes) {
458 TRACE_EVENT0("omnibox", "HistoryURLProvider::Start"); 459 TRACE_EVENT0("omnibox", "HistoryURLProvider::Start");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 matches_.push_back(what_you_typed_match); 499 matches_.push_back(what_you_typed_match);
499 500
500 // We'll need the history service to run both passes, so try to obtain it. 501 // We'll need the history service to run both passes, so try to obtain it.
501 history::HistoryService* const history_service = 502 history::HistoryService* const history_service =
502 client()->GetHistoryService(); 503 client()->GetHistoryService();
503 if (!history_service) 504 if (!history_service)
504 return; 505 return;
505 506
506 // Get the default search provider and search terms data now since we have to 507 // Get the default search provider and search terms data now since we have to
507 // retrieve these on the UI thread, and the second pass runs on the history 508 // retrieve these on the UI thread, and the second pass runs on the history
508 // thread. |template_url_service| can be NULL when testing. 509 // thread. |template_url_service| can be null when testing.
509 TemplateURLService* template_url_service = client()->GetTemplateURLService(); 510 TemplateURLService* template_url_service = client()->GetTemplateURLService();
510 TemplateURL* default_search_provider = template_url_service ? 511 TemplateURL* default_search_provider = template_url_service ?
511 template_url_service->GetDefaultSearchProvider() : NULL; 512 template_url_service->GetDefaultSearchProvider() : nullptr;
512 513
513 // Create the data structure for the autocomplete passes. We'll save this off 514 // Create the data structure for the autocomplete passes. We'll save this off
514 // onto the |params_| member for later deletion below if we need to run pass 515 // onto the |params_| member for later deletion below if we need to run pass
515 // 2. 516 // 2.
516 std::unique_ptr<HistoryURLProviderParams> params(new HistoryURLProviderParams( 517 std::unique_ptr<HistoryURLProviderParams> params(new HistoryURLProviderParams(
517 fixed_up_input, trim_http, what_you_typed_match, default_search_provider, 518 fixed_up_input, trim_http, what_you_typed_match, default_search_provider,
518 client()->GetSearchTermsData())); 519 client()->GetSearchTermsData()));
519 // Note that we use the non-fixed-up input here, since fixup may strip 520 // Note that we use the non-fixed-up input here, since fixup may strip
520 // trailing whitespace. 521 // trailing whitespace.
521 params->prevent_inline_autocomplete = PreventInlineAutocomplete(input); 522 params->prevent_inline_autocomplete = PreventInlineAutocomplete(input);
522 523
523 // Pass 1: Get the in-memory URL database, and use it to find and promote 524 // Pass 1: Get the in-memory URL database, and use it to find and promote
524 // the inline autocomplete match, if any. 525 // the inline autocomplete match, if any.
525 history::URLDatabase* url_db = history_service->InMemoryDatabase(); 526 history::URLDatabase* url_db = history_service->InMemoryDatabase();
526 // url_db can be NULL if it hasn't finished initializing (or failed to 527 // url_db can be null if it hasn't finished initializing (or failed to
527 // initialize). In this case all we can do is fall back on the second 528 // initialize). In this case all we can do is fall back on the second pass.
528 // pass.
529 // 529 //
530 // TODO(pkasting): We should just block here until this loads. Any time 530 // TODO(pkasting): We should just block here until this loads. Any time
531 // someone unloads the history backend, we'll get inconsistent inline 531 // someone unloads the history backend, we'll get inconsistent inline
532 // autocomplete behavior here. 532 // autocomplete behavior here.
533 if (url_db) { 533 if (url_db) {
534 DoAutocomplete(NULL, url_db, params.get()); 534 DoAutocomplete(nullptr, url_db, params.get());
535 matches_.clear(); 535 matches_.clear();
536 PromoteMatchesIfNecessary(*params); 536 PromoteMatchesIfNecessary(*params);
537 // NOTE: We don't reset |params| here since at least the |promote_type| 537 // NOTE: We don't reset |params| here since at least the |promote_type|
538 // field on it will be read by the second pass -- see comments in 538 // field on it will be read by the second pass -- see comments in
539 // DoAutocomplete(). 539 // DoAutocomplete().
540 } 540 }
541 541
542 // Pass 2: Ask the history service to call us back on the history thread, 542 // Pass 2: Ask the history service to call us back on the history thread,
543 // where we can read the full on-disk DB. 543 // where we can read the full on-disk DB.
544 if (search_url_database_ && input.want_asynchronous_matches()) { 544 if (search_url_database_ && input.want_asynchronous_matches()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 // it's surprising and annoying. 594 // it's surprising and annoying.
595 595
596 // Try to highlight "innermost" match location. If we fix up "w" into 596 // Try to highlight "innermost" match location. If we fix up "w" into
597 // "www.w.com", we want to highlight the fifth character, not the first. 597 // "www.w.com", we want to highlight the fifth character, not the first.
598 // This relies on match.destination_url being the non-prefix-trimmed version 598 // This relies on match.destination_url being the non-prefix-trimmed version
599 // of match.contents. 599 // of match.contents.
600 match.contents = display_string; 600 match.contents = display_string;
601 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix( 601 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(
602 base::UTF8ToUTF16(destination_url.spec()), input.text()); 602 base::UTF8ToUTF16(destination_url.spec()), input.text());
603 // It's possible for match.destination_url to not contain the user's input 603 // It's possible for match.destination_url to not contain the user's input
604 // at all (so |best_prefix| is NULL), for example if the input is 604 // at all (so |best_prefix| is null), for example if the input is
605 // "view-source:x" and |destination_url| has an inserted "http://" in the 605 // "view-source:x" and |destination_url| has an inserted "http://" in the
606 // middle. 606 // middle.
607 if (best_prefix == NULL) { 607 if (!best_prefix) {
608 AutocompleteMatch::ClassifyMatchInString(input.text(), 608 AutocompleteMatch::ClassifyMatchInString(input.text(),
609 match.contents, 609 match.contents,
610 ACMatchClassification::URL, 610 ACMatchClassification::URL,
611 &match.contents_class); 611 &match.contents_class);
612 } else { 612 } else {
613 AutocompleteMatch::ClassifyLocationInString( 613 AutocompleteMatch::ClassifyLocationInString(
614 best_prefix->prefix.length() - offset, input.text().length(), 614 best_prefix->prefix.length() - offset, input.text().length(),
615 match.contents.length(), ACMatchClassification::URL, 615 match.contents.length(), ACMatchClassification::URL,
616 &match.contents_class); 616 &match.contents_class);
617 } 617 }
618 } 618 }
619 619
620 return match; 620 return match;
621 } 621 }
622 622
623 void HistoryURLProvider::ExecuteWithDB(HistoryURLProviderParams* params, 623 void HistoryURLProvider::ExecuteWithDB(HistoryURLProviderParams* params,
624 history::HistoryBackend* backend, 624 history::HistoryBackend* backend,
625 history::URLDatabase* db) { 625 history::URLDatabase* db) {
626 // We may get called with a NULL database if it couldn't be properly 626 // We may get called with a null database if it couldn't be properly
627 // initialized. 627 // initialized.
628 if (!db) { 628 if (!db) {
629 params->failed = true; 629 params->failed = true;
630 } else if (!params->cancel_flag.IsSet()) { 630 } else if (!params->cancel_flag.IsSet()) {
631 base::TimeTicks beginning_time = base::TimeTicks::Now(); 631 base::TimeTicks beginning_time = base::TimeTicks::Now();
632 632
633 DoAutocomplete(backend, db, params); 633 DoAutocomplete(backend, db, params);
634 634
635 UMA_HISTOGRAM_TIMES("Autocomplete.HistoryAsyncQueryTime", 635 UMA_HISTOGRAM_TIMES("Autocomplete.HistoryAsyncQueryTime",
636 base::TimeTicks::Now() - beginning_time); 636 base::TimeTicks::Now() - beginning_time);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 839
840 void HistoryURLProvider::QueryComplete( 840 void HistoryURLProvider::QueryComplete(
841 HistoryURLProviderParams* params_gets_deleted) { 841 HistoryURLProviderParams* params_gets_deleted) {
842 TRACE_EVENT0("omnibox", "HistoryURLProvider::QueryComplete"); 842 TRACE_EVENT0("omnibox", "HistoryURLProvider::QueryComplete");
843 // Ensure |params_gets_deleted| gets deleted on exit. 843 // Ensure |params_gets_deleted| gets deleted on exit.
844 std::unique_ptr<HistoryURLProviderParams> params(params_gets_deleted); 844 std::unique_ptr<HistoryURLProviderParams> params(params_gets_deleted);
845 845
846 // If the user hasn't already started another query, clear our member pointer 846 // If the user hasn't already started another query, clear our member pointer
847 // so we can't write into deleted memory. 847 // so we can't write into deleted memory.
848 if (params_ == params_gets_deleted) 848 if (params_ == params_gets_deleted)
849 params_ = NULL; 849 params_ = nullptr;
850 850
851 // Don't send responses for queries that have been canceled. 851 // Don't send responses for queries that have been canceled.
852 if (params->cancel_flag.IsSet()) 852 if (params->cancel_flag.IsSet())
853 return; // Already set done_ when we canceled, no need to set it again. 853 return; // Already set done_ when we canceled, no need to set it again.
854 854
855 // Don't modify |matches_| if the query failed, since it might have a default 855 // Don't modify |matches_| if the query failed, since it might have a default
856 // match in it, whereas |params->matches| will be empty. 856 // match in it, whereas |params->matches| will be empty.
857 if (!params->failed) { 857 if (!params->failed) {
858 matches_.clear(); 858 matches_.clear();
859 PromoteMatchesIfNecessary(*params); 859 PromoteMatchesIfNecessary(*params);
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, 1191 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0,
1192 match.contents.length(), ACMatchClassification::URL, 1192 match.contents.length(), ACMatchClassification::URL,
1193 &match.contents_class); 1193 &match.contents_class);
1194 } 1194 }
1195 match.description = info.title(); 1195 match.description = info.title();
1196 match.description_class = 1196 match.description_class =
1197 ClassifyDescription(params.input.text(), match.description); 1197 ClassifyDescription(params.input.text(), match.description);
1198 RecordAdditionalInfoFromUrlRow(info, &match); 1198 RecordAdditionalInfoFromUrlRow(info, &match);
1199 return match; 1199 return match;
1200 } 1200 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/autocomplete_controller.cc ('k') | components/omnibox/browser/omnibox_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698