Remove BaseSearchProvider::set_in_app_list

Instead, app_list::OmniboxProvider is responsible to set true to SearchTermsArgs::from_app_list.

BUG=388515

Review URL: https://codereview.chromium.org/399063002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285565 0039d316-1c4b-4281-b951-d872f2087c98
parent b0ec7c06
......@@ -222,6 +222,15 @@ public class AutocompleteController {
isDeletable);
}
/**
* Use updateMatchDestinationUrlWithQueryFormulationTime instead.
*/
@Deprecated
public String updateMatchDestinationUrl(int selectedIndex, long elapsedTimeSinceInputChange) {
return updateMatchDestinationUrlWithQueryFormulationTime(selectedIndex,
elapsedTimeSinceInputChange);
}
/**
* Updates aqs parameters on the selected match that we will navigate to and returns the
* updated URL. |selected_index| is the position of the selected match and
......@@ -235,9 +244,10 @@ public class AutocompleteController {
* @return The url to navigate to for this match with aqs parameter updated, if we are
* making a Google search query.
*/
public String updateMatchDestinationUrl(int selectedIndex, long elapsedTimeSinceInputChange) {
return nativeUpdateMatchDestinationURL(mNativeAutocompleteControllerAndroid, selectedIndex,
elapsedTimeSinceInputChange);
public String updateMatchDestinationUrlWithQueryFormulationTime(int selectedIndex,
long elapsedTimeSinceInputChange) {
return nativeUpdateMatchDestinationURLWithQueryFormulationTime(
mNativeAutocompleteControllerAndroid, selectedIndex, elapsedTimeSinceInputChange);
}
/**
......@@ -265,8 +275,9 @@ public class AutocompleteController {
boolean focusedFromFakebox);
private native void nativeDeleteSuggestion(long nativeAutocompleteControllerAndroid,
int selectedIndex);
private native String nativeUpdateMatchDestinationURL(long nativeAutocompleteControllerAndroid,
int selectedIndex, long elapsedTimeSinceInputChange);
private native String nativeUpdateMatchDestinationURLWithQueryFormulationTime(
long nativeAutocompleteControllerAndroid, int selectedIndex,
long elapsedTimeSinceInputChange);
private native OmniboxSuggestion nativeGetTopSynchronousMatch(
long nativeAutocompleteControllerAndroid, String query);
......
......@@ -243,12 +243,12 @@ void AutocompleteControllerAndroid::DeleteSuggestion(JNIEnv* env,
autocomplete_controller_->DeleteMatch(match);
}
ScopedJavaLocalRef<jstring>
AutocompleteControllerAndroid::UpdateMatchDestinationURL(
JNIEnv* env,
jobject obj,
jint selected_index,
jlong elapsed_time_since_input_change) {
ScopedJavaLocalRef<jstring> AutocompleteControllerAndroid::
UpdateMatchDestinationURLWithQueryFormulationTime(
JNIEnv* env,
jobject obj,
jint selected_index,
jlong elapsed_time_since_input_change) {
// In rare cases, we navigate to cached matches and the underlying result
// has already been cleared, in that case ignore the URL update.
if (autocomplete_controller_->result().empty())
......@@ -256,7 +256,7 @@ AutocompleteControllerAndroid::UpdateMatchDestinationURL(
AutocompleteMatch match(
autocomplete_controller_->result().match_at(selected_index));
autocomplete_controller_->UpdateMatchDestinationURL(
autocomplete_controller_->UpdateMatchDestinationURLWithQueryFormulationTime(
base::TimeDelta::FromMilliseconds(elapsed_time_since_input_change),
&match);
return ConvertUTF8ToJavaString(env, match.destination_url.spec());
......
......@@ -62,11 +62,12 @@ class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
jlong elapsed_time_since_first_modified,
jobject j_web_contents);
void DeleteSuggestion(JNIEnv* env, jobject obj, int selected_index);
base::android::ScopedJavaLocalRef<jstring> UpdateMatchDestinationURL(
JNIEnv* env,
jobject obj,
jint selected_index,
jlong elapsed_time_since_input_change);
base::android::ScopedJavaLocalRef<jstring>
UpdateMatchDestinationURLWithQueryFormulationTime(
JNIEnv* env,
jobject obj,
jint selected_index,
jlong elapsed_time_since_input_change);
base::android::ScopedJavaLocalRef<jobject> GetTopSynchronousMatch(
JNIEnv* env,
......
......@@ -389,12 +389,10 @@ void AutocompleteController::ResetSession() {
(*i)->ResetSession();
}
void AutocompleteController::UpdateMatchDestinationURL(
void AutocompleteController::UpdateMatchDestinationURLWithQueryFormulationTime(
base::TimeDelta query_formulation_time,
AutocompleteMatch* match) const {
TemplateURL* template_url = match->GetTemplateURL(
template_url_service_, false);
if (!template_url || !match->search_terms_args.get() ||
if (!match->search_terms_args.get() ||
match->search_terms_args->assisted_query_stats.empty())
return;
......@@ -410,6 +408,17 @@ void AutocompleteController::UpdateMatchDestinationURL(
(zero_suggest_provider_ &&
zero_suggest_provider_->field_trial_triggered_in_session()),
input_.current_page_classification());
UpdateMatchDestinationURL(search_terms_args, match);
}
void AutocompleteController::UpdateMatchDestinationURL(
const TemplateURLRef::SearchTermsArgs& search_terms_args,
AutocompleteMatch* match) const {
TemplateURL* template_url = match->GetTemplateURL(
template_url_service_, false);
if (!template_url)
return;
match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms(
search_terms_args, template_url_service_->search_terms_data()));
}
......
......@@ -114,8 +114,15 @@ class AutocompleteController : public AutocompleteProviderListener {
// parameters otherwise not available at initial construction time. This
// method should be called from OmniboxEditModel::OpenMatch() before the user
// navigates to the selected match.
void UpdateMatchDestinationURL(base::TimeDelta query_formulation_time,
AutocompleteMatch* match) const;
void UpdateMatchDestinationURLWithQueryFormulationTime(
base::TimeDelta query_formulation_time,
AutocompleteMatch* match) const;
// Constructs the final destination URL for a given match using additional
// parameters otherwise not available at initial construction time.
void UpdateMatchDestinationURL(
const TemplateURLRef::SearchTermsArgs& search_terms_args,
AutocompleteMatch* match) const;
HistoryURLProvider* history_url_provider() const {
return history_url_provider_;
......
......@@ -452,7 +452,8 @@ void AutocompleteProviderTest::CopyResults() {
GURL AutocompleteProviderTest::GetDestinationURL(
AutocompleteMatch match,
base::TimeDelta query_formulation_time) const {
controller_->UpdateMatchDestinationURL(query_formulation_time, &match);
controller_->UpdateMatchDestinationURLWithQueryFormulationTime(
query_formulation_time, &match);
return match.destination_url;
}
......
......@@ -133,8 +133,7 @@ BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener,
profile_(profile),
field_trial_triggered_(false),
field_trial_triggered_in_session_(false),
suggest_results_pending_(0),
in_app_list_(false) {
suggest_results_pending_(0) {
}
// static
......@@ -154,7 +153,7 @@ AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
suggestion, type, suggestion, base::string16(), base::string16(),
base::string16(), base::string16(), std::string(), std::string(),
from_keyword_provider, 0, false, false, base::string16()),
template_url, search_terms_data, 0, false, false);
template_url, search_terms_data, 0, false);
}
void BaseSearchProvider::Stop(bool clear_cached_results) {
......@@ -482,8 +481,7 @@ AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
const TemplateURL* template_url,
const SearchTermsData& search_terms_data,
int accepted_suggestion,
bool append_extra_query_params,
bool from_app_list) {
bool append_extra_query_params) {
AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false,
suggestion.type());
......@@ -540,7 +538,6 @@ AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
suggestion.suggest_query_params();
match.search_terms_args->append_extra_query_params =
append_extra_query_params;
match.search_terms_args->from_app_list = from_app_list;
// This is the destination URL sans assisted query stats. This must be set
// so the AutocompleteController can properly de-dupe; the controller will
// eventually overwrite it before it reaches the user.
......@@ -716,7 +713,7 @@ void BaseSearchProvider::AddMatchToMap(const SuggestResult& result,
this, GetInput(result.from_keyword_provider()), result,
GetTemplateURL(result.from_keyword_provider()),
UIThreadSearchTermsData(profile_), accepted_suggestion,
ShouldAppendExtraParams(result), in_app_list_);
ShouldAppendExtraParams(result));
if (!match.destination_url.is_valid())
return;
match.search_terms_args->bookmark_bar_pinned =
......
......@@ -76,8 +76,6 @@ class BaseSearchProvider : public AutocompleteProvider,
return field_trial_triggered_in_session_;
}
void set_in_app_list() { in_app_list_ = true; }
protected:
// The following keys are used to record additional information on matches.
......@@ -340,7 +338,6 @@ class BaseSearchProvider : public AutocompleteProvider,
// |append_extra_query_params| should be set if |template_url| is the default
// search engine, so the destination URL will contain any
// command-line-specified query params.
// |from_app_list| should be set if the search was made from the app list.
static AutocompleteMatch CreateSearchSuggestion(
AutocompleteProvider* autocomplete_provider,
const AutocompleteInput& input,
......@@ -348,8 +345,7 @@ class BaseSearchProvider : public AutocompleteProvider,
const TemplateURL* template_url,
const SearchTermsData& search_terms_data,
int accepted_suggestion,
bool append_extra_query_params,
bool from_app_list);
bool append_extra_query_params);
// Parses JSON response received from the provider, stripping XSSI
// protection if needed. Returns the parsed data if successful, NULL
......@@ -517,11 +513,6 @@ class BaseSearchProvider : public AutocompleteProvider,
// causes us to auto-cancel all such requests on shutdown.
SuggestionDeletionHandlers deletion_handlers_;
// True if this provider's results are being displayed in the app list. By
// default this is false, meaning that the results will be shown in the
// omnibox.
bool in_app_list_;
DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider);
};
......
......@@ -8,7 +8,6 @@
#include "chrome/browser/autocomplete/autocomplete_controller.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/autocomplete/search_provider.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h"
#include "chrome/browser/ui/browser_navigator.h"
......@@ -66,15 +65,23 @@ void ACMatchClassificationsToTags(
class OmniboxResult : public ChromeSearchResult {
public:
OmniboxResult(Profile* profile, const AutocompleteMatch& match)
OmniboxResult(Profile* profile,
AutocompleteController* autocomplete_controller,
const AutocompleteMatch& match)
: profile_(profile),
autocomplete_controller_(autocomplete_controller),
match_(match) {
set_id(match.destination_url.spec());
if (match_.search_terms_args) {
match_.search_terms_args->from_app_list = true;
autocomplete_controller_->UpdateMatchDestinationURL(
*match_.search_terms_args, &match_);
}
set_id(match_.destination_url.spec());
// Derive relevance from omnibox relevance and normalize it to [0, 1].
// The magic number 1500 is the highest score of an omnibox result.
// See comments in autocomplete_provider.h.
set_relevance(match.relevance / 1500.0);
set_relevance(match_.relevance / 1500.0);
UpdateIcon();
UpdateTitleAndDetails();
......@@ -94,7 +101,7 @@ class OmniboxResult : public ChromeSearchResult {
virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE {
return scoped_ptr<ChromeSearchResult>(
new OmniboxResult(profile_, match_)).Pass();
new OmniboxResult(profile_, autocomplete_controller_, match_)).Pass();
}
virtual ChromeSearchResultType GetType() OVERRIDE {
......@@ -126,6 +133,7 @@ class OmniboxResult : public ChromeSearchResult {
}
Profile* profile_;
AutocompleteController* autocomplete_controller_;
AutocompleteMatch match_;
DISALLOW_COPY_AND_ASSIGN(OmniboxResult);
......@@ -141,7 +149,6 @@ OmniboxProvider::OmniboxProvider(Profile* profile)
this,
AutocompleteClassifier::kDefaultOmniboxProviders &
~AutocompleteProvider::TYPE_ZERO_SUGGEST)) {
controller_->search_provider()->set_in_app_list();
}
OmniboxProvider::~OmniboxProvider() {}
......@@ -165,7 +172,8 @@ void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) {
if (!it->destination_url.is_valid())
continue;
Add(scoped_ptr<SearchResult>(new OmniboxResult(profile_, *it)));
Add(scoped_ptr<SearchResult>(
new OmniboxResult(profile_, controller_.get(), *it)));
}
}
......
......@@ -711,7 +711,7 @@ void OmniboxEditModel::OpenMatch(AutocompleteMatch match,
const base::TimeTicks& now(base::TimeTicks::Now());
base::TimeDelta elapsed_time_since_user_first_modified_omnibox(
now - time_user_first_modified_omnibox_);
autocomplete_controller()->UpdateMatchDestinationURL(
autocomplete_controller()->UpdateMatchDestinationURLWithQueryFormulationTime(
elapsed_time_since_user_first_modified_omnibox, &match);
base::string16 input_text(pasted_text);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment