Bug 1233602 - Don't depend on search suggestions to show search history. r=liuche, a=ritu
authorAndrzej Hunt <ahunt@mozilla.com>
Thu, 17 Dec 2015 17:14:27 -0800
changeset 305991 2285043ff5c6b01daff7f133b940d994eb3fc514
parent 305988 8706cd66a9b422beacfef8da453b647d66f4306b
child 305992 098464f40ee921e2a4be9d42e528351619a806ab
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, ritu
bugs1233602
milestone44.0
Bug 1233602 - Don't depend on search suggestions to show search history. r=liuche, a=ritu
mobile/android/base/home/BrowserSearch.java
--- a/mobile/android/base/home/BrowserSearch.java
+++ b/mobile/android/base/home/BrowserSearch.java
@@ -6,35 +6,38 @@
 package org.mozilla.gecko.home;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Locale;
 
+import android.content.SharedPreferences;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
+import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.SuggestClient;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserContract.History;
 import org.mozilla.gecko.db.BrowserContract.URLColumns;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.home.SearchLoader.SearchCursorLoader;
+import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.toolbar.AutocompleteHandler;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Activity;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -145,16 +148,19 @@ public class BrowserSearch extends HomeF
 
     // Track the locale that was last in use when we filled mSearchEngines.
     // Access to this member must only occur from the UI thread.
     private Locale mLastLocale;
 
     // Whether search suggestions are enabled or not
     private boolean mSuggestionsEnabled;
 
+    // Whether history suggestions are enabled or not
+    private boolean mSavedSearchesEnabled;
+
     // Callbacks used for the search loader
     private CursorLoaderCallbacks mCursorLoaderCallbacks;
 
     // Callbacks used for the search suggestion loader
     private SearchEngineSuggestionLoaderCallbacks mSearchEngineSuggestionLoaderCallbacks;
     private SearchHistorySuggestionLoaderCallbacks mSearchHistorySuggestionLoaderCallback;
 
     // Autocomplete handler used when filtering results
@@ -253,16 +259,19 @@ public class BrowserSearch extends HomeF
         }
         super.onHiddenChanged(hidden);
     }
 
     @Override
     public void onResume() {
         super.onResume();
 
+        final SharedPreferences prefs = GeckoSharedPrefs.forApp(getContext());
+        mSavedSearchesEnabled = prefs.getBoolean(GeckoPreferences.PREFS_HISTORY_SAVED_SEARCH, true);
+
         // Fetch engines if we need to.
         if (mSearchEngines.isEmpty() || !Locale.getDefault().equals(mLastLocale)) {
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
         } else {
             updateSearchEngineBar();
         }
 
         Telemetry.startUISession(TelemetryContract.Session.FRECENCY);
@@ -533,17 +542,17 @@ public class BrowserSearch extends HomeF
         return null;
     }
 
     public void resetScrollState() {
         mSearchEngineBar.scrollToPosition(0);
     }
 
     private void filterSuggestions() {
-        if (mSuggestClient == null || !mSuggestionsEnabled) {
+        if (mSuggestClient == null || (!mSuggestionsEnabled && !mSavedSearchesEnabled)) {
             return;
         }
 
         // Suggestions from search engine
         if (mSearchEngineSuggestionLoaderCallbacks == null) {
             mSearchEngineSuggestionLoaderCallbacks = new SearchEngineSuggestionLoaderCallbacks();
         }
         getLoaderManager().restartLoader(LOADER_ID_SUGGESTION, null, mSearchEngineSuggestionLoaderCallbacks);