Bug 697747 - Only query frecency results on AwesomeBar startup (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 28 Oct 2011 15:57:09 +0100
changeset 83310 ddc7b89fa4d6b3f777ff69b7c669cf10e4bc2ebf
parent 83309 403d217a6c098cf7c794ce61fddb509fcc66aa51
child 83311 0b65a47a160c5329b279b33f162cec8001bad7a0
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs697747
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 697747 - Only query frecency results on AwesomeBar startup (r=mfinkle) Only load the bookmark and history lists if they are actually requested.
embedding/android/AwesomeBarTabs.java
--- a/embedding/android/AwesomeBarTabs.java
+++ b/embedding/android/AwesomeBarTabs.java
@@ -398,16 +398,29 @@ public class AwesomeBarTabs extends TabH
         // This should be called before adding any tabs
         // to the TabHost.
         setup();
 
         addAllPagesTab();
         addBookmarksTab();
         addHistoryTab();
 
+        setOnTabChangedListener(new TabHost.OnTabChangeListener() {
+            @Override
+            public void onTabChanged(String tabId) {
+                // Lazy load bookmarks and history lists. Only query the database
+                // if those lists requested by user.
+                if (tabId.equals(BOOKMARKS_TAB) && mBookmarksAdapter == null) {
+                    new BookmarksQueryTask().execute();
+                } else if (tabId.equals(HISTORY_TAB) && mHistoryAdapter == null) {
+                    new HistoryQueryTask().execute();
+                }
+            }
+        });
+
         // Initialize "App Pages" list with no filter
         filter("");
     }
 
     private TabSpec addAwesomeTab(String id, int titleId, int contentId) {
         TabSpec tab = newTabSpec(id);
 
         Resources resources = mContext.getResources();
@@ -472,27 +485,29 @@ public class AwesomeBarTabs extends TabH
 
     private void addBookmarksTab() {
         Log.d(LOG_NAME, "Creating Bookmarks tab");
 
         addAwesomeTab(BOOKMARKS_TAB,
                       R.string.awesomebar_bookmarks_title,
                       R.id.bookmarks_list);
 
-        new BookmarksQueryTask().execute();
+        // Only load bookmark list when tab is actually used.
+        // See OnTabChangeListener above.
     }
 
     private void addHistoryTab() {
         Log.d(LOG_NAME, "Creating History tab");
 
         addAwesomeTab(HISTORY_TAB,
                       R.string.awesomebar_history_title,
                       R.id.history_list);
 
-        new HistoryQueryTask().execute();
+        // Only load history list when tab is actually used.
+        // See OnTabChangeListener above.
     }
 
     private void handleHistoryItemClick(int groupPosition, int childPosition) {
         @SuppressWarnings("unchecked")
         Map<String,Object> historyItem =
                 (Map<String,Object>) mHistoryAdapter.getChild(groupPosition, childPosition);
 
         String url = (String) historyItem.get(AwesomeBar.URL_KEY);
@@ -513,19 +528,21 @@ public class AwesomeBarTabs extends TabH
         mUrlOpenListener = listener;
     }
 
     public void destroy() {
         Cursor allPagesCursor = mAllPagesAdapter.getCursor();
         if (allPagesCursor != null)
             allPagesCursor.close();
 
-        Cursor bookmarksCursor = mBookmarksAdapter.getCursor();
-        if (bookmarksCursor != null)
-            bookmarksCursor.close();
+        if (mBookmarksAdapter != null) {
+            Cursor bookmarksCursor = mBookmarksAdapter.getCursor();
+            if (bookmarksCursor != null)
+                bookmarksCursor.close();
+        }
     }
 
     public void filter(String searchTerm) {
         // Ensure the 'All Pages' tab is selected
         setCurrentTabByTag(ALL_PAGES_TAB);
 
         // The tabs should only be visible if there's no on-going search
         int tabsVisibility = (searchTerm.length() == 0 ? View.VISIBLE : View.GONE);