Add a method to retrieve the top synchronous suggestion.

Generally speaking top synchronous suggestion remains as a top
asynchronous suggestion as well. Get a quick preview of the top
suggestion by requesting just the synchronous one.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275399 0039d316-1c4b-4281-b951-d872f2087c98
parent 99039107
...@@ -240,6 +240,14 @@ public class AutocompleteController { ...@@ -240,6 +240,14 @@ public class AutocompleteController {
elapsedTimeSinceInputChange); elapsedTimeSinceInputChange);
} }
/**
* @param query User input text.
* @return The top synchronous suggestion from the autocomplete controller.
*/
public OmniboxSuggestion getTopSynchronousMatch(String query) {
return nativeGetTopSynchronousMatch(mNativeAutocompleteControllerAndroid, query);
}
@VisibleForTesting @VisibleForTesting
protected native long nativeInit(Profile profile); protected native long nativeInit(Profile profile);
private native void nativeStart(long nativeAutocompleteControllerAndroid, String text, private native void nativeStart(long nativeAutocompleteControllerAndroid, String text,
...@@ -259,6 +267,8 @@ public class AutocompleteController { ...@@ -259,6 +267,8 @@ public class AutocompleteController {
int selectedIndex); int selectedIndex);
private native String nativeUpdateMatchDestinationURL(long nativeAutocompleteControllerAndroid, private native String nativeUpdateMatchDestinationURL(long nativeAutocompleteControllerAndroid,
int selectedIndex, long elapsedTimeSinceInputChange); int selectedIndex, long elapsedTimeSinceInputChange);
private native OmniboxSuggestion nativeGetTopSynchronousMatch(
long nativeAutocompleteControllerAndroid, String query);
/** /**
* Given a search query, this will attempt to see if the query appears to be portion of a * Given a search query, this will attempt to see if the query appears to be portion of a
......
...@@ -115,7 +115,7 @@ void ZeroSuggestPrefetcher::OnResultChanged(bool default_match_changed) { ...@@ -115,7 +115,7 @@ void ZeroSuggestPrefetcher::OnResultChanged(bool default_match_changed) {
AutocompleteControllerAndroid::AutocompleteControllerAndroid(Profile* profile) AutocompleteControllerAndroid::AutocompleteControllerAndroid(Profile* profile)
: autocomplete_controller_(new AutocompleteController( : autocomplete_controller_(new AutocompleteController(
profile, this, kAndroidAutocompleteProviders)), profile, this, kAndroidAutocompleteProviders)),
inside_classify_(false), inside_synchronous_start_(false),
profile_(profile) { profile_(profile) {
} }
...@@ -156,18 +156,7 @@ ScopedJavaLocalRef<jobject> AutocompleteControllerAndroid::Classify( ...@@ -156,18 +156,7 @@ ScopedJavaLocalRef<jobject> AutocompleteControllerAndroid::Classify(
JNIEnv* env, JNIEnv* env,
jobject obj, jobject obj,
jstring j_text) { jstring j_text) {
if (!autocomplete_controller_) return GetTopSynchronousResult(env, obj, j_text, true);
return ScopedJavaLocalRef<jobject>();
inside_classify_ = true;
Start(env, obj, j_text, NULL, NULL, true, false, false, false);
inside_classify_ = false;
DCHECK(autocomplete_controller_->done());
const AutocompleteResult& result = autocomplete_controller_->result();
if (result.empty())
return ScopedJavaLocalRef<jobject>();
return BuildOmniboxSuggestion(env, *result.begin());
} }
void AutocompleteControllerAndroid::StartZeroSuggest( void AutocompleteControllerAndroid::StartZeroSuggest(
...@@ -274,6 +263,13 @@ AutocompleteControllerAndroid::UpdateMatchDestinationURL( ...@@ -274,6 +263,13 @@ AutocompleteControllerAndroid::UpdateMatchDestinationURL(
return ConvertUTF8ToJavaString(env, match.destination_url.spec()); return ConvertUTF8ToJavaString(env, match.destination_url.spec());
} }
ScopedJavaLocalRef<jobject>
AutocompleteControllerAndroid::GetTopSynchronousMatch(JNIEnv* env,
jobject obj,
jstring query) {
return GetTopSynchronousResult(env, obj, query, false);
}
void AutocompleteControllerAndroid::Shutdown() { void AutocompleteControllerAndroid::Shutdown() {
autocomplete_controller_.reset(); autocomplete_controller_.reset();
...@@ -333,7 +329,7 @@ void AutocompleteControllerAndroid::InitJNI(JNIEnv* env, jobject obj) { ...@@ -333,7 +329,7 @@ void AutocompleteControllerAndroid::InitJNI(JNIEnv* env, jobject obj) {
void AutocompleteControllerAndroid::OnResultChanged( void AutocompleteControllerAndroid::OnResultChanged(
bool default_match_changed) { bool default_match_changed) {
if (autocomplete_controller_.get() != NULL && !inside_classify_) if (autocomplete_controller_.get() != NULL && !inside_synchronous_start_)
NotifySuggestionsReceived(autocomplete_controller_->result()); NotifySuggestionsReceived(autocomplete_controller_->result());
} }
...@@ -373,6 +369,43 @@ void AutocompleteControllerAndroid::NotifySuggestionsReceived( ...@@ -373,6 +369,43 @@ void AutocompleteControllerAndroid::NotifySuggestionsReceived(
j_autocomplete_result); j_autocomplete_result);
} }
AutocompleteInput::PageClassification
AutocompleteControllerAndroid::ClassifyPage(const GURL& gurl,
bool is_query_in_omnibox,
bool focused_from_fakebox) const {
if (!gurl.is_valid())
return AutocompleteInput::INVALID_SPEC;
const std::string& url = gurl.spec();
if (gurl.SchemeIs(content::kChromeUIScheme) &&
gurl.host() == chrome::kChromeUINewTabHost) {
return AutocompleteInput::NTP;
}
if (url == chrome::kChromeUINativeNewTabURL) {
return focused_from_fakebox ?
AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS :
AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS;
}
if (url == content::kAboutBlankURL)
return AutocompleteInput::BLANK;
if (url == profile_->GetPrefs()->GetString(prefs::kHomePage))
return AutocompleteInput::HOME_PAGE;
if (is_query_in_omnibox)
return AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT;
bool is_search_url = TemplateURLServiceFactory::GetForProfile(profile_)->
IsSearchResultsPageFromDefaultSearchProvider(gurl);
if (is_search_url)
return AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
return AutocompleteInput::OTHER;
}
ScopedJavaLocalRef<jobject> ScopedJavaLocalRef<jobject>
AutocompleteControllerAndroid::BuildOmniboxSuggestion( AutocompleteControllerAndroid::BuildOmniboxSuggestion(
JNIEnv* env, JNIEnv* env,
...@@ -420,37 +453,32 @@ base::string16 AutocompleteControllerAndroid::FormatURLUsingAcceptLanguages( ...@@ -420,37 +453,32 @@ base::string16 AutocompleteControllerAndroid::FormatURLUsingAcceptLanguages(
net::UnescapeRule::SPACES, NULL, NULL, NULL); net::UnescapeRule::SPACES, NULL, NULL, NULL);
} }
AutocompleteInput::PageClassification ScopedJavaLocalRef<jobject>
AutocompleteControllerAndroid::ClassifyPage(const GURL& gurl, AutocompleteControllerAndroid::GetTopSynchronousResult(
bool is_query_in_omnibox, JNIEnv* env,
bool focused_from_fakebox) const { jobject obj,
if (!gurl.is_valid()) jstring j_text,
return AutocompleteInput::INVALID_SPEC; bool prevent_inline_autocomplete) {
if (!autocomplete_controller_)
const std::string& url = gurl.spec(); return ScopedJavaLocalRef<jobject>();
if (gurl.SchemeIs(content::kChromeUIScheme) &&
gurl.host() == chrome::kChromeUINewTabHost) {
return AutocompleteInput::NTP;
}
if (url == chrome::kChromeUINativeNewTabURL) {
return focused_from_fakebox ?
AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS :
AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS;
}
if (url == content::kAboutBlankURL)
return AutocompleteInput::BLANK;
if (url == profile_->GetPrefs()->GetString(prefs::kHomePage)) inside_synchronous_start_ = true;
return AutocompleteInput::HOME_PAGE; Start(env,
if (is_query_in_omnibox) obj,
return AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; j_text,
NULL,
NULL,
prevent_inline_autocomplete,
false,
false,
false);
inside_synchronous_start_ = false;
DCHECK(autocomplete_controller_->done());
const AutocompleteResult& result = autocomplete_controller_->result();
if (result.empty())
return ScopedJavaLocalRef<jobject>();
bool is_search_url = TemplateURLServiceFactory::GetForProfile(profile_)-> return BuildOmniboxSuggestion(env, *result.begin());
IsSearchResultsPageFromDefaultSearchProvider(gurl);
if (is_search_url)
return AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
return AutocompleteInput::OTHER;
} }
static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) {
......
...@@ -67,6 +67,11 @@ class AutocompleteControllerAndroid : public AutocompleteControllerDelegate, ...@@ -67,6 +67,11 @@ class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
jint selected_index, jint selected_index,
jlong elapsed_time_since_input_change); jlong elapsed_time_since_input_change);
base::android::ScopedJavaLocalRef<jobject> GetTopSynchronousMatch(
JNIEnv* env,
jobject obj,
jstring query);
// KeyedService: // KeyedService:
virtual void Shutdown() OVERRIDE; virtual void Shutdown() OVERRIDE;
...@@ -119,13 +124,23 @@ class AutocompleteControllerAndroid : public AutocompleteControllerDelegate, ...@@ -119,13 +124,23 @@ class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
// e.g. http://xn--6q8b.kr/ --> 한.kr // e.g. http://xn--6q8b.kr/ --> 한.kr
base::string16 FormatURLUsingAcceptLanguages(GURL url); base::string16 FormatURLUsingAcceptLanguages(GURL url);
// A helper method for fetching the top synchronous autocomplete result.
// The |prevent_inline_autocomplete| flag is passed to the AutocompleteInput
// object, see documentation there for its description.
base::android::ScopedJavaLocalRef<jobject> GetTopSynchronousResult(
JNIEnv* env,
jobject obj,
jstring j_text,
bool prevent_inline_autocomplete);
scoped_ptr<AutocompleteController> autocomplete_controller_; scoped_ptr<AutocompleteController> autocomplete_controller_;
// Last input we sent to the autocomplete controller. // Last input we sent to the autocomplete controller.
AutocompleteInput input_; AutocompleteInput input_;
// Whether we're currently inside a call to Classify(). // Whether we're currently inside a call to Start() that's called
bool inside_classify_; // from GetTopSynchronousResult().
bool inside_synchronous_start_;
JavaObjectWeakGlobalRef weak_java_autocomplete_controller_android_; JavaObjectWeakGlobalRef weak_java_autocomplete_controller_android_;
Profile* profile_; Profile* profile_;
......
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