summaryrefslogtreecommitdiffstats
path: root/chrome/browser/android
diff options
context:
space:
mode:
authormariakhomenko@chromium.org <mariakhomenko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-06 11:14:25 +0000
committermariakhomenko@chromium.org <mariakhomenko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-06 11:14:25 +0000
commit972c88fd15f69c8eb00b5424d2cf11afce832843 (patch)
tree71fc14c7e1749b7b688c8c52a3b524157fedd884 /chrome/browser/android
parent99039107ec9e659c12df0cb6d8f0f0562710e4de (diff)
downloadchromium_src-972c88fd15f69c8eb00b5424d2cf11afce832843.zip
chromium_src-972c88fd15f69c8eb00b5424d2cf11afce832843.tar.gz
chromium_src-972c88fd15f69c8eb00b5424d2cf11afce832843.tar.bz2
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
Diffstat (limited to 'chrome/browser/android')
-rw-r--r--chrome/browser/android/omnibox/autocomplete_controller_android.cc114
-rw-r--r--chrome/browser/android/omnibox/autocomplete_controller_android.h19
2 files changed, 88 insertions, 45 deletions
diff --git a/chrome/browser/android/omnibox/autocomplete_controller_android.cc b/chrome/browser/android/omnibox/autocomplete_controller_android.cc
index c976ebe..ea6cfc7 100644
--- a/chrome/browser/android/omnibox/autocomplete_controller_android.cc
+++ b/chrome/browser/android/omnibox/autocomplete_controller_android.cc
@@ -115,7 +115,7 @@ void ZeroSuggestPrefetcher::OnResultChanged(bool default_match_changed) {
AutocompleteControllerAndroid::AutocompleteControllerAndroid(Profile* profile)
: autocomplete_controller_(new AutocompleteController(
profile, this, kAndroidAutocompleteProviders)),
- inside_classify_(false),
+ inside_synchronous_start_(false),
profile_(profile) {
}
@@ -156,18 +156,7 @@ ScopedJavaLocalRef<jobject> AutocompleteControllerAndroid::Classify(
JNIEnv* env,
jobject obj,
jstring j_text) {
- if (!autocomplete_controller_)
- 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());
+ return GetTopSynchronousResult(env, obj, j_text, true);
}
void AutocompleteControllerAndroid::StartZeroSuggest(
@@ -274,6 +263,13 @@ AutocompleteControllerAndroid::UpdateMatchDestinationURL(
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() {
autocomplete_controller_.reset();
@@ -333,7 +329,7 @@ void AutocompleteControllerAndroid::InitJNI(JNIEnv* env, jobject obj) {
void AutocompleteControllerAndroid::OnResultChanged(
bool default_match_changed) {
- if (autocomplete_controller_.get() != NULL && !inside_classify_)
+ if (autocomplete_controller_.get() != NULL && !inside_synchronous_start_)
NotifySuggestionsReceived(autocomplete_controller_->result());
}
@@ -373,6 +369,43 @@ void AutocompleteControllerAndroid::NotifySuggestionsReceived(
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>
AutocompleteControllerAndroid::BuildOmniboxSuggestion(
JNIEnv* env,
@@ -420,37 +453,32 @@ base::string16 AutocompleteControllerAndroid::FormatURLUsingAcceptLanguages(
net::UnescapeRule::SPACES, NULL, NULL, NULL);
}
-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;
+ScopedJavaLocalRef<jobject>
+AutocompleteControllerAndroid::GetTopSynchronousResult(
+ JNIEnv* env,
+ jobject obj,
+ jstring j_text,
+ bool prevent_inline_autocomplete) {
+ if (!autocomplete_controller_)
+ return ScopedJavaLocalRef<jobject>();
- 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;
+ inside_synchronous_start_ = true;
+ Start(env,
+ obj,
+ 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_)->
- IsSearchResultsPageFromDefaultSearchProvider(gurl);
- if (is_search_url)
- return AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
- return AutocompleteInput::OTHER;
+ return BuildOmniboxSuggestion(env, *result.begin());
}
static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) {
diff --git a/chrome/browser/android/omnibox/autocomplete_controller_android.h b/chrome/browser/android/omnibox/autocomplete_controller_android.h
index d961068..582a350 100644
--- a/chrome/browser/android/omnibox/autocomplete_controller_android.h
+++ b/chrome/browser/android/omnibox/autocomplete_controller_android.h
@@ -67,6 +67,11 @@ class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
jint selected_index,
jlong elapsed_time_since_input_change);
+ base::android::ScopedJavaLocalRef<jobject> GetTopSynchronousMatch(
+ JNIEnv* env,
+ jobject obj,
+ jstring query);
+
// KeyedService:
virtual void Shutdown() OVERRIDE;
@@ -119,13 +124,23 @@ class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
// e.g. http://xn--6q8b.kr/ --> 한.kr
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_;
// Last input we sent to the autocomplete controller.
AutocompleteInput input_;
- // Whether we're currently inside a call to Classify().
- bool inside_classify_;
+ // Whether we're currently inside a call to Start() that's called
+ // from GetTopSynchronousResult().
+ bool inside_synchronous_start_;
JavaObjectWeakGlobalRef weak_java_autocomplete_controller_android_;
Profile* profile_;