bool /*minimal_changes*/) {
}
-void ZeroSuggestProvider::Stop(bool clear_cached_results) {
- if (have_pending_request_)
- LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED);
- have_pending_request_ = false;
- fetcher_.reset();
- done_ = true;
- if (clear_cached_results) {
- query_matches_map_.clear();
- navigation_results_.clear();
- current_query_.clear();
- matches_.clear();
- }
-}
-
-void ZeroSuggestProvider::AddProviderInfo(ProvidersInfo* provider_info) const {
- provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo());
- metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back();
- new_entry.set_provider(AsOmniboxEventProviderType());
- new_entry.set_provider_done(done_);
- std::vector<uint32> field_trial_hashes;
- OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes(&field_trial_hashes);
- for (size_t i = 0; i < field_trial_hashes.size(); ++i) {
- if (field_trial_triggered_)
- new_entry.mutable_field_trial_triggered()->Add(field_trial_hashes[i]);
- if (field_trial_triggered_in_session_) {
- new_entry.mutable_field_trial_triggered_in_session()->Add(
- field_trial_hashes[i]);
- }
- }
-}
-
void ZeroSuggestProvider::ResetSession() {
// The user has started editing in the omnibox, so leave
// |field_trial_triggered_in_session_| unchanged and set
source->GetStatus().is_success() && source->GetResponseCode() == 200;
if (request_succeeded) {
- scoped_ptr<base::Value> data(
- SearchProvider::DeserializeJsonData(json_data));
+ scoped_ptr<base::Value> data(DeserializeJsonData(json_data));
if (data.get())
ParseSuggestResults(*data.get());
}
search_term_args.current_page_url = current_query_;
GURL suggest_url(default_provider->suggestions_url_ref().
ReplaceSearchTerms(search_term_args));
- if (!SearchProvider::CanSendURL(
- current_page_url, suggest_url,
+ if (!CanSendURL(current_page_url, suggest_url,
template_url_service_->GetDefaultSearchProvider(),
page_classification, profile_) ||
!OmniboxFieldTrial::InZeroSuggestFieldTrial())
ZeroSuggestProvider::ZeroSuggestProvider(
AutocompleteProviderListener* listener,
Profile* profile)
- : AutocompleteProvider(listener, profile,
- AutocompleteProvider::TYPE_ZERO_SUGGEST),
+ : BaseSearchProvider(listener, profile,
+ AutocompleteProvider::TYPE_ZERO_SUGGEST),
template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)),
have_pending_request_(false),
verbatim_relevance_(kDefaultVerbatimZeroSuggestRelevance),
- field_trial_triggered_(false),
- field_trial_triggered_in_session_(false),
weak_ptr_factory_(this) {
}
ZeroSuggestProvider::~ZeroSuggestProvider() {
}
-void ZeroSuggestProvider::FillResults(
- const base::Value& root_val,
- int* verbatim_relevance,
- SearchProvider::SuggestResults* suggest_results,
- SearchProvider::NavigationResults* navigation_results) {
+const TemplateURL* ZeroSuggestProvider::GetTemplateURL(
+ const SuggestResult& result) const {
+ // Zero suggest provider should not receive keyword results.
+ DCHECK(!result.from_keyword_provider());
+ return template_url_service_->GetDefaultSearchProvider();
+}
+
+const AutocompleteInput ZeroSuggestProvider::GetInput(
+ const SuggestResult& result) const {
+ AutocompleteInput input;
+ // Set |input|'s text to be |query_string| to avoid bolding.
+ input.UpdateText(result.suggestion(), base::string16::npos, input.parts());
+ return input;
+}
+
+bool ZeroSuggestProvider::ShouldAppendExtraParams(
+ const SuggestResult& result) const {
+ // We always use the default provider for search, so append the params.
+ return true;
+}
+
+void ZeroSuggestProvider::StopSuggest() {
+ if (have_pending_request_)
+ LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED);
+ have_pending_request_ = false;
+ fetcher_.reset();
+}
+
+void ZeroSuggestProvider::ClearAllResults() {
+ query_matches_map_.clear();
+ navigation_results_.clear();
+ current_query_.clear();
+ matches_.clear();
+}
+
+void ZeroSuggestProvider::FillResults(const base::Value& root_val,
+ int* verbatim_relevance,
+ SuggestResults* suggest_results,
+ NavigationResults* navigation_results) {
base::string16 query;
const base::ListValue* root_list = NULL;
const base::ListValue* results = NULL;
if (url.is_valid()) {
if (descriptions != NULL)
descriptions->GetString(index, &title);
- navigation_results->push_back(SearchProvider::NavigationResult(
+ navigation_results->push_back(NavigationResult(
*this, url, title, false, relevance, relevances != NULL,
current_query_string16, languages));
}
} else {
- suggest_results->push_back(SearchProvider::SuggestResult(
+ suggest_results->push_back(SuggestResult(
result, AutocompleteMatchType::SEARCH_SUGGEST, result,
base::string16(), std::string(), std::string(), false, relevance,
relevances != NULL, false, current_query_string16));
}
void ZeroSuggestProvider::AddSuggestResultsToMap(
- const SearchProvider::SuggestResults& results,
- const TemplateURL* template_url,
- SearchProvider::MatchMap* map) {
+ const SuggestResults& results,
+ MatchMap* map) {
for (size_t i = 0; i < results.size(); ++i) {
- AddMatchToMap(results[i].relevance(), AutocompleteMatchType::SEARCH_SUGGEST,
- template_url, results[i].suggestion(), i, map);
+ const base::string16& query_string(results[i].suggestion());
+ // TODO(mariakhomenko): Do not reconstruct SuggestResult objects with
+ // a different query -- create correct objects to begin with.
+ const SuggestResult suggestion(
+ query_string, AutocompleteMatchType::SEARCH_SUGGEST, query_string,
+ base::string16(), std::string(), std::string(), false,
+ results[i].relevance(), true, false, query_string);
+ AddMatchToMap(suggestion, std::string(), i, map);
}
}
-void ZeroSuggestProvider::AddMatchToMap(int relevance,
- AutocompleteMatch::Type type,
- const TemplateURL* template_url,
- const base::string16& query_string,
- int accepted_suggestion,
- SearchProvider::MatchMap* map) {
- // Pass in query_string as the input_text to avoid bolding.
- SearchProvider::SuggestResult suggestion(
- query_string, type, query_string, base::string16(), std::string(),
- std::string(), false, relevance, true, false, query_string);
- // TODO(samarth|melevin): use the actual omnibox margin here as well instead
- // of passing in -1.
- AutocompleteMatch match = SearchProvider::CreateSearchSuggestion(
- this, AutocompleteInput(), query_string, suggestion, template_url,
- accepted_suggestion, -1, true);
- if (!match.destination_url.is_valid())
- return;
-
- // Try to add |match| to |map|. If a match for |query_string| is already in
- // |map|, replace it if |match| is more relevant.
- // NOTE: Keep this ToLower() call in sync with url_database.cc.
- SearchProvider::MatchKey match_key(
- std::make_pair(base::i18n::ToLower(query_string), std::string()));
- const std::pair<SearchProvider::MatchMap::iterator, bool> i(map->insert(
- std::make_pair(match_key, match)));
- // NOTE: We purposefully do a direct relevance comparison here instead of
- // using AutocompleteMatch::MoreRelevant(), so that we'll prefer "items added
- // first" rather than "items alphabetically first" when the scores are equal.
- // The only case this matters is when a user has results with the same score
- // that differ only by capitalization; because the history system returns
- // results sorted by recency, this means we'll pick the most recent such
- // result even if the precision of our relevance score is too low to
- // distinguish the two.
- if (!i.second && (match.relevance > i.first->second.relevance))
- i.first->second = match;
-}
-
AutocompleteMatch ZeroSuggestProvider::NavigationToMatch(
- const SearchProvider::NavigationResult& navigation) {
+ const NavigationResult& navigation) {
AutocompleteMatch match(this, navigation.relevance(), false,
AutocompleteMatchType::NAVSUGGEST);
match.destination_url = navigation.url();
}
void ZeroSuggestProvider::ParseSuggestResults(const base::Value& root_val) {
- SearchProvider::SuggestResults suggest_results;
+ SuggestResults suggest_results;
FillResults(root_val, &verbatim_relevance_,
&suggest_results, &navigation_results_);
query_matches_map_.clear();
- AddSuggestResultsToMap(suggest_results,
- template_url_service_->GetDefaultSearchProvider(),
- &query_matches_map_);
+ AddSuggestResultsToMap(suggest_results, &query_matches_map_);
}
void ZeroSuggestProvider::OnMostVisitedUrlsAvailable(
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
for (size_t i = 0; i < most_visited_urls_.size(); i++) {
const history::MostVisitedURL& url = most_visited_urls_[i];
- SearchProvider::NavigationResult nav(
- *this, url.url, url.title, false, relevance, true,
+ NavigationResult nav(*this, url.url, url.title, false, relevance, true,
current_query_string16, languages);
matches_.push_back(NavigationToMatch(nav));
--relevance;
// current typing in the omnibox.
matches_.push_back(current_url_match_);
- for (SearchProvider::MatchMap::const_iterator it(query_matches_map_.begin());
+ for (MatchMap::const_iterator it(query_matches_map_.begin());
it != query_matches_map_.end(); ++it)
matches_.push_back(it->second);
- for (SearchProvider::NavigationResults::const_iterator it(
- navigation_results_.begin()); it != navigation_results_.end(); ++it)
+ for (NavigationResults::const_iterator it(navigation_results_.begin());
+ it != navigation_results_.end(); ++it)
matches_.push_back(NavigationToMatch(*it));
}
AutocompleteMatch match;
AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(
- permanent_text_, false, true, &match, NULL);
+ permanent_text_, false, true, current_page_classification_, &match, NULL);
match.is_history_what_you_typed_match = false;
match.allowed_to_be_default_match = true;