Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4610)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java

Issue 2738583002: Add a way to cache and show zero suggest results before native (Closed)
Patch Set: reset on start call as well Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java
index a212b0889d2dbf1750da8c26ffe46ddbb69eee3d..c23bdaac5bdcdb3bd924ac409b2abc37539ef948 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java
@@ -33,6 +33,9 @@ public class AutocompleteController {
private final VoiceSuggestionProvider mVoiceSuggestionProvider = new VoiceSuggestionProvider();
+ private boolean mUseCachedZeroSuggestResults;
+ private boolean mWaitingForSuggestionsToCache;
+
/**
* Listener for receiving OmniboxSuggestions.
*/
@@ -73,6 +76,17 @@ public class AutocompleteController {
}
/**
+ * Use cached zero suggest results if there are any available and start caching them
+ * for all zero suggest updates.
+ */
+ public void startCachedZeroSuggest() {
+ mUseCachedZeroSuggestResults = true;
+ List<OmniboxSuggestion> suggestions =
+ OmniboxSuggestion.getCachedOmniboxSuggestionsForZeroSuggest();
+ if (suggestions != null) mListener.onSuggestionsReceived(suggestions, "");
+ }
+
+ /**
* Starts querying for omnibox suggestions for a given text.
*
* @param profile The profile to use for starting the AutocompleteController
@@ -103,6 +117,7 @@ public class AutocompleteController {
if (mNativeAutocompleteControllerAndroid != 0) {
nativeStart(mNativeAutocompleteControllerAndroid, text, cursorPosition, null, url,
preventInlineAutocomplete, false, false, true);
+ mWaitingForSuggestionsToCache = false;
}
}
@@ -140,6 +155,7 @@ public class AutocompleteController {
if (profile == null || TextUtils.isEmpty(url)) return;
mNativeAutocompleteControllerAndroid = nativeInit(profile);
if (mNativeAutocompleteControllerAndroid != 0) {
+ if (mUseCachedZeroSuggestResults) mWaitingForSuggestionsToCache = true;
nativeOnOmniboxFocused(mNativeAutocompleteControllerAndroid, omniboxText, url,
focusedFromFakebox);
}
@@ -159,6 +175,7 @@ public class AutocompleteController {
public void stop(boolean clear) {
if (clear) mVoiceSuggestionProvider.clearVoiceSearchResults();
mCurrentNativeAutocompleteResult = 0;
+ mWaitingForSuggestionsToCache = false;
if (mNativeAutocompleteControllerAndroid != 0) {
nativeStop(mNativeAutocompleteControllerAndroid, clear);
}
@@ -210,6 +227,9 @@ public class AutocompleteController {
// Notify callbacks of suggestions.
mListener.onSuggestionsReceived(suggestions, inlineAutocompleteText);
+ if (mWaitingForSuggestionsToCache) {
+ OmniboxSuggestion.cacheOmniboxSuggestionListForZeroSuggest(suggestions);
+ }
}
@CalledByNative
@@ -234,6 +254,7 @@ public class AutocompleteController {
public void onSuggestionSelected(int selectedIndex, int type,
String currentPageUrl, boolean focusedFromFakebox, long elapsedTimeSinceModified,
int completedLength, WebContents webContents) {
+ assert mNativeAutocompleteControllerAndroid != 0;
// Don't natively log voice suggestion results as we add them in Java.
if (type == OmniboxSuggestionType.VOICE_SUGGEST) return;
nativeOnSuggestionSelected(mNativeAutocompleteControllerAndroid, selectedIndex,
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698