Chromium Code Reviews| 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..44f9e93c76d20839ac335f18e1e209af86a56fb9 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 { |
| } |
| /** |
| + * Sets to use any cached zero suggest results if there are any available and start caching them |
| + * for all zero suggest updates. |
| + */ |
| + public void setUseCachedZeroSuggestResults() { |
|
Maria
2017/03/08 06:48:08
nit: I don't know why but I have a lot of trouble
Yusuf
2017/03/08 20:10:46
Done.
|
| + mUseCachedZeroSuggestResults = true; |
| + List<OmniboxSuggestion> suggestions = |
| + OmniboxSuggestion.getCachedOmniboxSuggestionsForZeroSuggest(); |
| + if (suggestions != null) mListener.onSuggestionsReceived(suggestions, ""); |
|
Maria
2017/03/08 06:48:08
I wonder if we can hit some subtle assumptions her
Yusuf
2017/03/08 20:10:46
Acknowledged.
|
| + } |
| + |
| + /** |
| * Starts querying for omnibox suggestions for a given text. |
| * |
| * @param profile The profile to use for starting the AutocompleteController |
| @@ -140,6 +154,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 +174,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 +226,10 @@ public class AutocompleteController { |
| // Notify callbacks of suggestions. |
| mListener.onSuggestionsReceived(suggestions, inlineAutocompleteText); |
| + if (mWaitingForSuggestionsToCache) { |
|
Maria
2017/03/08 06:48:08
This is a little fragile because it relies on zero
Yusuf
2017/03/08 20:10:46
On the omnibox side, we never combine these calls
Maria
2017/03/09 17:55:09
Correct. Each onSuggestionReceived set is newly ra
Yusuf
2017/03/09 19:29:38
Done.
|
| + OmniboxSuggestion.cacheOmniboxSuggestionListForZeroSuggest(suggestions); |
| + mWaitingForSuggestionsToCache = false; |
| + } |
| } |
| @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, |
| @@ -307,6 +328,7 @@ public class AutocompleteController { |
| */ |
| public String updateMatchDestinationUrlWithQueryFormulationTime(int selectedIndex, |
| long elapsedTimeSinceInputChange) { |
| + if (mNativeAutocompleteControllerAndroid == 0) return null; |
|
Maria
2017/03/08 06:48:08
I thought this couldn't get called until native is
Yusuf
2017/03/08 20:10:46
Done. Yeah this seems to be a leftover from initia
|
| return nativeUpdateMatchDestinationURLWithQueryFormulationTime( |
| mNativeAutocompleteControllerAndroid, selectedIndex, elapsedTimeSinceInputChange); |
| } |