| OLD | NEW |
| 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { | 454 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { |
| 455 } | 455 } |
| 456 | 456 |
| 457 HistoryURLProviderParams::~HistoryURLProviderParams() { | 457 HistoryURLProviderParams::~HistoryURLProviderParams() { |
| 458 } | 458 } |
| 459 | 459 |
| 460 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, | 460 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, |
| 461 AutocompleteProviderListener* listener) | 461 AutocompleteProviderListener* listener) |
| 462 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client), | 462 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client), |
| 463 listener_(listener), | 463 listener_(listener), |
| 464 params_(NULL) { | 464 params_(NULL), |
| 465 search_url_database_(OmniboxFieldTrial::HUPSearchDatabase()) { |
| 465 // Initialize the default HUP scoring params. | 466 // Initialize the default HUP scoring params. |
| 466 OmniboxFieldTrial::GetDefaultHUPScoringParams(&scoring_params_); | 467 OmniboxFieldTrial::GetDefaultHUPScoringParams(&scoring_params_); |
| 467 // Initialize HUP scoring params based on the current experiment. | 468 // Initialize HUP scoring params based on the current experiment. |
| 468 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); | 469 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); |
| 469 } | 470 } |
| 470 | 471 |
| 471 void HistoryURLProvider::Start(const AutocompleteInput& input, | 472 void HistoryURLProvider::Start(const AutocompleteInput& input, |
| 472 bool minimal_changes) { | 473 bool minimal_changes) { |
| 473 // NOTE: We could try hard to do less work in the |minimal_changes| case | 474 // NOTE: We could try hard to do less work in the |minimal_changes| case |
| 474 // here; some clever caching would let us reuse the raw matches from the | 475 // here; some clever caching would let us reuse the raw matches from the |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 DoAutocomplete(NULL, url_db, params.get()); | 551 DoAutocomplete(NULL, url_db, params.get()); |
| 551 matches_.clear(); | 552 matches_.clear(); |
| 552 PromoteMatchesIfNecessary(*params); | 553 PromoteMatchesIfNecessary(*params); |
| 553 // NOTE: We don't reset |params| here since at least the |promote_type| | 554 // NOTE: We don't reset |params| here since at least the |promote_type| |
| 554 // field on it will be read by the second pass -- see comments in | 555 // field on it will be read by the second pass -- see comments in |
| 555 // DoAutocomplete(). | 556 // DoAutocomplete(). |
| 556 } | 557 } |
| 557 | 558 |
| 558 // Pass 2: Ask the history service to call us back on the history thread, | 559 // Pass 2: Ask the history service to call us back on the history thread, |
| 559 // where we can read the full on-disk DB. | 560 // where we can read the full on-disk DB. |
| 560 if (input.want_asynchronous_matches()) { | 561 if (search_url_database_ && input.want_asynchronous_matches()) { |
| 561 done_ = false; | 562 done_ = false; |
| 562 params_ = params.release(); // This object will be destroyed in | 563 params_ = params.release(); // This object will be destroyed in |
| 563 // QueryComplete() once we're done with it. | 564 // QueryComplete() once we're done with it. |
| 564 history_service->ScheduleAutocomplete( | 565 history_service->ScheduleAutocomplete( |
| 565 base::Bind(&HistoryURLProvider::ExecuteWithDB, this, params_)); | 566 base::Bind(&HistoryURLProvider::ExecuteWithDB, this, params_)); |
| 566 } | 567 } |
| 567 } | 568 } |
| 568 | 569 |
| 569 void HistoryURLProvider::Stop(bool clear_cached_results, | 570 void HistoryURLProvider::Stop(bool clear_cached_results, |
| 570 bool due_to_user_inactivity) { | 571 bool due_to_user_inactivity) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 return SpansFromTermMatch( | 706 return SpansFromTermMatch( |
| 706 description_matches, clean_description.length(), false); | 707 description_matches, clean_description.length(), false); |
| 707 } | 708 } |
| 708 | 709 |
| 709 void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, | 710 void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, |
| 710 history::URLDatabase* db, | 711 history::URLDatabase* db, |
| 711 HistoryURLProviderParams* params) { | 712 HistoryURLProviderParams* params) { |
| 712 // Get the matching URLs from the DB. | 713 // Get the matching URLs from the DB. |
| 713 params->matches.clear(); | 714 params->matches.clear(); |
| 714 history::URLRows url_matches; | 715 history::URLRows url_matches; |
| 715 const URLPrefixes& prefixes = URLPrefix::GetURLPrefixes(); | |
| 716 for (URLPrefixes::const_iterator i(prefixes.begin()); i != prefixes.end(); | |
| 717 ++i) { | |
| 718 if (params->cancel_flag.IsSet()) | |
| 719 return; // Canceled in the middle of a query, give up. | |
| 720 | 716 |
| 721 // We only need kMaxMatches results in the end, but before we get there we | 717 if (search_url_database_) { |
| 722 // need to promote lower-quality matches that are prefixes of higher-quality | 718 const URLPrefixes& prefixes = URLPrefix::GetURLPrefixes(); |
| 723 // matches, and remove lower-quality redirects. So we ask for more results | 719 for (URLPrefixes::const_iterator i(prefixes.begin()); i != prefixes.end(); |
| 724 // than we need, of every prefix type, in hopes this will give us far more | 720 ++i) { |
| 725 // than enough to work with. CullRedirects() will then reduce the list to | 721 if (params->cancel_flag.IsSet()) |
| 726 // the best kMaxMatches results. | 722 return; // Canceled in the middle of a query, give up. |
| 727 db->AutocompleteForPrefix( | 723 |
| 728 base::UTF16ToUTF8(i->prefix + params->input.text()), kMaxMatches * 2, | 724 // We only need kMaxMatches results in the end, but before we get there we |
| 729 !backend, &url_matches); | 725 // need to promote lower-quality matches that are prefixes of higher- |
| 730 for (history::URLRows::const_iterator j(url_matches.begin()); | 726 // quality matches, and remove lower-quality redirects. So we ask for |
| 731 j != url_matches.end(); ++j) { | 727 // more results than we need, of every prefix type, in hopes this will |
| 732 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix( | 728 // give us far more than enough to work with. CullRedirects() will then |
| 733 base::UTF8ToUTF16(j->url().spec()), base::string16()); | 729 // reduce the list to the best kMaxMatches results. |
| 734 DCHECK(best_prefix); | 730 db->AutocompleteForPrefix( |
| 735 params->matches.push_back(history::HistoryMatch( | 731 base::UTF16ToUTF8(i->prefix + params->input.text()), kMaxMatches * 2, |
| 736 *j, i->prefix.length(), !i->num_components, | 732 !backend, &url_matches); |
| 737 i->num_components >= best_prefix->num_components)); | 733 for (history::URLRows::const_iterator j(url_matches.begin()); |
| 734 j != url_matches.end(); ++j) { |
| 735 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix( |
| 736 base::UTF8ToUTF16(j->url().spec()), base::string16()); |
| 737 DCHECK(best_prefix); |
| 738 params->matches.push_back(history::HistoryMatch( |
| 739 *j, i->prefix.length(), !i->num_components, |
| 740 i->num_components >= best_prefix->num_components)); |
| 741 } |
| 738 } | 742 } |
| 743 |
| 744 // Create sorted list of suggestions. |
| 745 CullPoorMatches(params); |
| 746 SortAndDedupMatches(¶ms->matches); |
| 739 } | 747 } |
| 740 | 748 |
| 741 // Create sorted list of suggestions. | |
| 742 CullPoorMatches(params); | |
| 743 SortAndDedupMatches(¶ms->matches); | |
| 744 | |
| 745 // Try to create a shorter suggestion from the best match. | 749 // Try to create a shorter suggestion from the best match. |
| 746 // We consider the what you typed match eligible for display when it's | 750 // We consider the what you typed match eligible for display when it's |
| 747 // navigable and there's a reasonable chance the user intended to do | 751 // navigable and there's a reasonable chance the user intended to do |
| 748 // something other than search. We use a variety of heuristics to determine | 752 // something other than search. We use a variety of heuristics to determine |
| 749 // this, e.g. whether the user explicitly typed a scheme, or if omnibox | 753 // this, e.g. whether the user explicitly typed a scheme, or if omnibox |
| 750 // searching has been disabled by policy. In the cases where we've parsed as | 754 // searching has been disabled by policy. In the cases where we've parsed as |
| 751 // UNKNOWN, we'll still show an accidental search infobar if need be. | 755 // UNKNOWN, we'll still show an accidental search infobar if need be. |
| 752 VisitClassifier classifier(this, params->input, db); | 756 VisitClassifier classifier(this, params->input, db); |
| 753 params->have_what_you_typed_match = | 757 params->have_what_you_typed_match = |
| 754 (params->input.type() != metrics::OmniboxInputType::QUERY) && | 758 (params->input.type() != metrics::OmniboxInputType::QUERY) && |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1204 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 1201 match.contents.length(), ACMatchClassification::URL, | 1205 match.contents.length(), ACMatchClassification::URL, |
| 1202 &match.contents_class); | 1206 &match.contents_class); |
| 1203 } | 1207 } |
| 1204 match.description = info.title(); | 1208 match.description = info.title(); |
| 1205 match.description_class = | 1209 match.description_class = |
| 1206 ClassifyDescription(params.input.text(), match.description); | 1210 ClassifyDescription(params.input.text(), match.description); |
| 1207 RecordAdditionalInfoFromUrlRow(info, &match); | 1211 RecordAdditionalInfoFromUrlRow(info, &match); |
| 1208 return match; | 1212 return match; |
| 1209 } | 1213 } |
| OLD | NEW |