Index: chrome/browser/autocomplete/search_provider.cc |
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc |
index 93f68ffbe89cd6d75f75a7421f9542fe475ca142..21fcad6887cea6f4328422da480b22558c866434 100644 |
--- a/chrome/browser/autocomplete/search_provider.cc |
+++ b/chrome/browser/autocomplete/search_provider.cc |
@@ -225,107 +225,17 @@ SearchProvider::SearchProvider(AutocompleteProviderListener* listener, |
AutocompleteProvider::TYPE_SEARCH), |
providers_(TemplateURLServiceFactory::GetForProfile(profile)), |
suggest_results_pending_(0), |
- instant_finalized_(false), |
field_trial_triggered_(false), |
field_trial_triggered_in_session_(false), |
- suppress_search_suggestions_(false), |
omnibox_start_margin_(-1) { |
} |
-void SearchProvider::FinalizeInstantQuery(const string16& input_text, |
- const InstantSuggestion& suggestion) { |
- if (done_ || instant_finalized_) |
- return; |
- |
- instant_finalized_ = true; |
- UpdateDone(); |
- |
- if (input_text.empty()) { |
- // We only need to update the listener if we're actually done. |
- if (done_) |
- listener_->OnProviderUpdate(false); |
- return; |
- } |
- |
- default_provider_suggestion_ = suggestion; |
- |
- string16 adjusted_input_text(input_text); |
- AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(), |
- &adjusted_input_text); |
- |
- const string16 text = adjusted_input_text + suggestion.text; |
- bool results_updated = false; |
- // Remove any matches that are identical to |text|. We don't use the |
- // destination_url for comparison as it varies depending upon the index passed |
- // to TemplateURL::ReplaceSearchTerms. |
- for (ACMatches::iterator i = matches_.begin(); i != matches_.end();) { |
- if (((i->type == AutocompleteMatchType::SEARCH_HISTORY) || |
- (i->type == AutocompleteMatchType::SEARCH_SUGGEST)) && |
- (i->fill_into_edit == text)) { |
- i = matches_.erase(i); |
- results_updated = true; |
- } else { |
- ++i; |
- } |
- } |
- |
- // Add the new Instant suggest result. |
- if (suggestion.type == INSTANT_SUGGESTION_SEARCH) { |
- // Instant has a query suggestion. Rank it higher than SEARCH_WHAT_YOU_TYPED |
- // so that it gets autocompleted. |
- const int verbatim_relevance = GetVerbatimRelevance(); |
- int did_not_accept_default_suggestion = |
- default_results_.suggest_results.empty() ? |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
- TemplateURLRef::NO_SUGGESTION_CHOSEN; |
- MatchMap match_map; |
- AddMatchToMap(text, adjusted_input_text, verbatim_relevance + 1, |
- AutocompleteMatchType::SEARCH_SUGGEST, |
- did_not_accept_default_suggestion, false, &match_map); |
- if (!match_map.empty()) { |
- matches_.push_back(match_map.begin()->second); |
- results_updated = true; |
- } |
- } else { |
- // Instant has a URL suggestion. Rank it higher than URL_WHAT_YOU_TYPED so |
- // it gets autocompleted; use kNonURLVerbatimRelevance rather than |
- // verbatim_relevance so that the score does not change if the user keeps |
- // typing and the input changes from type UNKNOWN to URL. |
- matches_.push_back(NavigationToMatch( |
- NavigationResult(*this, |
- GURL(UTF16ToUTF8(suggestion.text)), |
- string16(), |
- false, |
- kNonURLVerbatimRelevance + 1))); |
- results_updated = true; |
- } |
- |
- if (results_updated || done_) |
- listener_->OnProviderUpdate(results_updated); |
-} |
- |
-void SearchProvider::ClearInstantSuggestion() { |
- default_provider_suggestion_ = InstantSuggestion(); |
- if (done_ || instant_finalized_) |
- return; |
- instant_finalized_ = true; |
- UpdateMatches(); |
- listener_->OnProviderUpdate(true); |
-} |
- |
-void SearchProvider::SuppressSearchSuggestions() { |
- suppress_search_suggestions_ = true; |
-} |
- |
void SearchProvider::SetOmniboxStartMargin(int omnibox_start_margin) { |
omnibox_start_margin_ = omnibox_start_margin; |
} |
void SearchProvider::Start(const AutocompleteInput& input, |
bool minimal_changes) { |
- const bool suppress_search_suggestions = suppress_search_suggestions_; |
- suppress_search_suggestions_ = false; |
- |
// Do our best to load the model as early as possible. This will reduce |
// odds of having the model not ready when really needed (a non-empty input). |
TemplateURLService* model = providers_.template_url_service(); |
@@ -335,9 +245,6 @@ void SearchProvider::Start(const AutocompleteInput& input, |
matches_.clear(); |
field_trial_triggered_ = false; |
- instant_finalized_ = |
- (input.matches_requested() != AutocompleteInput::ALL_MATCHES); |
- |
// Can't return search/suggest results for bogus input or without a profile. |
if (!profile_ || (input.type() == AutocompleteInput::INVALID)) { |
Stop(false); |
@@ -374,23 +281,9 @@ void SearchProvider::Start(const AutocompleteInput& input, |
keyword_provider->keyword() : string16()); |
if (!minimal_changes || |
!providers_.equal(default_provider_keyword, keyword_provider_keyword)) { |
- // If Instant has not come back with a suggestion, adjust the previous |
- // suggestion if possible. If |instant_finalized| is true, we are looking |
- // for synchronous matches only, so the suggestion is cleared. |
- if (instant_finalized_) |
- default_provider_suggestion_ = InstantSuggestion(); |
- else |
- AdjustDefaultProviderSuggestion(input_.text(), input.text()); |
- |
// Cancel any in-flight suggest requests. |
- if (!done_) { |
- // The Stop(false) call below clears |default_provider_suggestion_|, but |
- // in this instance we do not want to clear cached results, so we |
- // restore it. |
- base::AutoReset<InstantSuggestion> reset(&default_provider_suggestion_, |
- InstantSuggestion()); |
+ if (!done_) |
Stop(false); |
- } |
} |
providers_.set(default_provider_keyword, keyword_provider_keyword); |
@@ -413,10 +306,8 @@ void SearchProvider::Start(const AutocompleteInput& input, |
input_ = input; |
- if (!suppress_search_suggestions) { |
- DoHistoryQuery(minimal_changes); |
- StartOrStopSuggestQuery(minimal_changes); |
- } |
+ DoHistoryQuery(minimal_changes); |
+ StartOrStopSuggestQuery(minimal_changes); |
UpdateMatches(); |
} |
@@ -521,7 +412,6 @@ void SearchProvider::Run() { |
void SearchProvider::Stop(bool clear_cached_results) { |
StopSuggest(); |
done_ = true; |
- default_provider_suggestion_ = InstantSuggestion(); |
if (clear_cached_results) |
ClearAllResults(); |
@@ -611,7 +501,7 @@ void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
listener_->OnProviderUpdate(results_updated); |
} |
-bool SearchProvider::IsNonInstantSearchDone() const { |
+bool SearchProvider::IsDone() const { |
Peter Kasting
2013/06/18 19:01:32
Nit: Eliminate this function and inline its conten
Jered
2013/06/18 21:05:50
Done.
|
return !timer_.IsRunning() && (suggest_results_pending_ == 0); |
} |
@@ -844,42 +734,6 @@ void SearchProvider::RemoveStaleResults(const string16& input, |
} |
} |
-void SearchProvider::AdjustDefaultProviderSuggestion( |
- const string16& previous_input, |
- const string16& current_input) { |
- if (default_provider_suggestion_.type == INSTANT_SUGGESTION_URL) { |
- // Description and relevance do not matter in the check for staleness. |
- NavigationResult result(*this, |
- GURL(default_provider_suggestion_.text), |
- string16(), |
- false, |
- 100); |
- // If navigation suggestion is stale, clear |default_provider_suggestion_|. |
- if (!result.IsInlineable(current_input)) |
- default_provider_suggestion_ = InstantSuggestion(); |
- } else { |
- DCHECK(default_provider_suggestion_.type == INSTANT_SUGGESTION_SEARCH); |
- // InstantSuggestion of type SEARCH contain only the suggested text, and not |
- // the full text of the query. This looks at the current and previous input |
- // to determine if the user is typing forward, and if the new input is |
- // contained in |default_provider_suggestion_|. If so, the suggestion is |
- // adjusted and can be kept. Otherwise, it is reset. |
- if (!previous_input.empty() && |
- StartsWith(current_input, previous_input, false)) { |
- // User is typing forward; verify if new input is part of the suggestion. |
- const string16 new_text = string16(current_input, previous_input.size()); |
- if (StartsWith(default_provider_suggestion_.text, new_text, false)) { |
- // New input is a prefix to the previous suggestion, adjust the |
- // suggestion to strip the prefix. |
- default_provider_suggestion_.text.erase(0, new_text.size()); |
- return; |
- } |
- } |
- // If we are here, the search suggestion is stale; reset it. |
- default_provider_suggestion_ = InstantSuggestion(); |
- } |
-} |
- |
void SearchProvider::ApplyCalculatedRelevance() { |
ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); |
ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); |
@@ -1073,14 +927,6 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { |
} |
} |
const size_t verbatim_matches_size = map.size(); |
- if (!default_provider_suggestion_.text.empty() && |
- default_provider_suggestion_.type == INSTANT_SUGGESTION_SEARCH && |
- !input_.prevent_inline_autocomplete()) |
- AddMatchToMap(input_.text() + default_provider_suggestion_.text, |
- input_.text(), verbatim_relevance + 1, |
- AutocompleteMatchType::SEARCH_SUGGEST, |
- did_not_accept_default_suggestion, false, &map); |
- |
AddHistoryResultsToMap(keyword_history_results_, true, |
did_not_accept_keyword_suggestion, &map); |
AddHistoryResultsToMap(default_history_results_, false, |
@@ -1094,18 +940,6 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { |
for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
matches_.push_back(i->second); |
- if (!default_provider_suggestion_.text.empty() && |
- default_provider_suggestion_.type == INSTANT_SUGGESTION_URL && |
- !input_.prevent_inline_autocomplete()) { |
- // See comment in FinalizeInstantQuery() for why we don't use |
- // |verbatim_relevance| here. |
- matches_.push_back(NavigationToMatch( |
- NavigationResult(*this, |
- GURL(UTF16ToUTF8(default_provider_suggestion_.text)), |
- string16(), |
- false, |
- kNonURLVerbatimRelevance + 1))); |
- } |
AddNavigationResultsToMatches(keyword_results_.navigation_results, true); |
AddNavigationResultsToMatches(default_results_.navigation_results, false); |
@@ -1610,6 +1444,5 @@ void SearchProvider::DemoteKeywordNavigationMatchesPastTopQuery() { |
void SearchProvider::UpdateDone() { |
// We're done when the timer isn't running, there are no suggest queries |
// pending, and we're not waiting on Instant. |
- done_ = IsNonInstantSearchDone() && |
- (instant_finalized_ || !chrome::IsInstantEnabled(profile_)); |
+ done_ = IsDone(); |
} |