Bug 1234319 - Post: Don't track or care about the reading list in Tabs r?mcomella draft
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 08 Mar 2016 09:31:15 -0800
changeset 345254 d3bba5ed13b60b14e8554d601424ed360fa7334a
parent 345253 cff67d12f2f165fd8f9116b29075a8223ba3fe49
child 345255 7f65ffb0fe71580968c830fd87e329d2e4dd5ba8
push id14029
push userahunt@mozilla.com
push dateMon, 28 Mar 2016 16:56:10 +0000
reviewersmcomella
bugs1234319
milestone48.0a1
Bug 1234319 - Post: Don't track or care about the reading list in Tabs r?mcomella MozReview-Commit-ID: Ex89J6QLmrI
mobile/android/base/java/org/mozilla/gecko/Tab.java
mobile/android/base/java/org/mozilla/gecko/Tabs.java
--- a/mobile/android/base/java/org/mozilla/gecko/Tab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tab.java
@@ -60,17 +60,16 @@ public class Tab {
     private boolean mHasFeeds;
     private boolean mHasOpenSearch;
     private final SiteIdentity mSiteIdentity;
     private SiteLogins mSiteLogins;
     private BitmapDrawable mThumbnail;
     private final int mParentId;
     private final boolean mExternal;
     private boolean mBookmark;
-    private boolean mIsInReadingList;
     private int mFaviconLoadId;
     private String mContentType;
     private boolean mHasTouchListeners;
     private ZoomConstraints mZoomConstraints;
     private boolean mIsRTL;
     private final ArrayList<View> mPluginViews;
     private final HashMap<Object, Layer> mPluginLayers;
     private int mBackgroundColor;
@@ -133,17 +132,16 @@ public class Tab {
         mLoadProgress = LOAD_PROGRESS_INIT;
 
         // At startup, the background is set to a color specified by LayerView
         // when the LayerView is created. Shortly after, this background color
         // will be used before the tab's content is shown.
         mBackgroundColor = DEFAULT_BACKGROUND_COLOR;
 
         updateBookmark();
-        updateReadingList();
     }
 
     private ContentResolver getContentResolver() {
         return mAppContext.getContentResolver();
     }
 
     public void onDestroy() {
         Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.CLOSED);
@@ -289,20 +287,16 @@ public class Tab {
     public SiteLogins getSiteLogins() {
         return mSiteLogins;
     }
 
     public boolean isBookmark() {
         return mBookmark;
     }
 
-    public boolean isInReadingList() {
-        return mIsInReadingList;
-    }
-
     public boolean isExternal() {
         return mExternal;
     }
 
     public synchronized void updateURL(String url) {
         if (url != null && url.length() > 0) {
             mUrl = url;
         }
@@ -532,35 +526,16 @@ public class Tab {
                 final String pageUrl = ReaderModeUtils.stripAboutReaderUrl(url);
 
                 mBookmark = mDB.isBookmark(getContentResolver(), pageUrl);
                 Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.MENU_UPDATED);
             }
         });
     }
 
-    void updateReadingList() {
-        if (getURL() == null) {
-            return;
-        }
-
-        ThreadUtils.postToBackgroundThread(new Runnable() {
-            @Override
-            public void run() {
-                final String url = getURL();
-                if (url == null) {
-                    return;
-                }
-
-                mIsInReadingList = mDB.getReadingListAccessor().isReadingListItem(getContentResolver(), url);
-                Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.MENU_UPDATED);
-            }
-        });
-    }
-
     public void addBookmark() {
         final String url = getURL();
         if (url == null) {
             return;
         }
 
         final String pageUrl = ReaderModeUtils.stripAboutReaderUrl(getURL());
 
@@ -593,48 +568,16 @@ public class Tab {
             }
         });
 
         // We need to ensure we remove readercached items here - we could have switched out of readermode
         // before unbookmarking, so we don't necessarily have an about:reader URL here.
         ReadingListHelper.removeCachedReaderItem(pageUrl, mAppContext);
     }
 
-    public void addToReadingList() {
-        ThreadUtils.postToBackgroundThread(new Runnable() {
-            @Override
-            public void run() {
-                String url = getURL();
-                if (url == null) {
-                    return;
-                }
-
-                mDB.getReadingListAccessor().addBasicReadingListItem(getContentResolver(), url, mTitle);
-                Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.READING_LIST_ADDED);
-            }
-        });
-    }
-
-    public void removeFromReadingList() {
-        ThreadUtils.postToBackgroundThread(new Runnable() {
-            @Override
-            public void run() {
-                String url = getURL();
-                if (url == null) {
-                    return;
-                }
-                if (AboutPages.isAboutReader(url)) {
-                    url = ReaderModeUtils.getUrlFromAboutReader(url);
-                }
-                mDB.getReadingListAccessor().removeReadingListItemWithURL(getContentResolver(), url);
-                Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.READING_LIST_REMOVED);
-            }
-        });
-    }
-
     public boolean isEnteringReaderMode() {
         return mEnteringReaderMode;
     }
 
     public void doReload(boolean bypassCache) {
         GeckoAppShell.notifyObservers("Session:Reload", "{\"bypassCache\":" + String.valueOf(bypassCache) + "}");
     }
 
@@ -676,17 +619,16 @@ public class Tab {
         mHistoryIndex = message.getInt("historyIndex");
         mHistorySize = message.getInt("historySize");
         mCanDoBack = message.getBoolean("canGoBack");
         mCanDoForward = message.getBoolean("canGoForward");
 
         if (!TextUtils.equals(oldUrl, uri)) {
             updateURL(uri);
             updateBookmark();
-            updateReadingList();
             if (!sameDocument) {
                 // We can unconditionally clear the favicon and title here: we
                 // already filtered both cases in which this was a (pseudo-)
                 // spurious location change, so we're definitely loading a new
                 // page.
                 clearFavicon();
 
                 // Load local static Favicons immediately
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -69,17 +69,16 @@ public class Tabs implements GeckoEventL
 
     public static final int INVALID_TAB_ID = -1;
 
     private static final AtomicInteger sTabId = new AtomicInteger(0);
     private volatile boolean mInitialTabsAdded;
 
     private Context mAppContext;
     private ContentObserver mBookmarksContentObserver;
-    private ContentObserver mReadingListContentObserver;
     private PersistTabsRunnable mPersistTabsRunnable;
 
     private static class PersistTabsRunnable implements Runnable {
         private final BrowserDB db;
         private final Context context;
         private final Iterable<Tab> tabs;
 
         public PersistTabsRunnable(final Context context, Iterable<Tab> tabsInOrder) {
@@ -146,24 +145,16 @@ public class Tabs implements GeckoEventL
         // The listener will run on the background thread (see 2nd argument).
         mAccountManager.addOnAccountsUpdatedListener(mAccountListener, ThreadUtils.getBackgroundHandler(), false);
 
         if (mBookmarksContentObserver != null) {
             // It's safe to use the db here since we aren't doing any I/O.
             final GeckoProfile profile = GeckoProfile.get(context);
             profile.getDB().registerBookmarkObserver(getContentResolver(), mBookmarksContentObserver);
         }
-
-        if (mReadingListContentObserver != null) {
-            // It's safe to use the db here since we aren't doing any I/O.
-            final GeckoProfile profile = GeckoProfile.get(context);
-            profile.getDB().getReadingListAccessor().registerContentObserver(
-                    mAppContext, mReadingListContentObserver);
-        }
-
     }
 
     /**
      * Gets the tab count corresponding to the private state of the selected
      * tab.
      *
      * If the selected tab is a non-private tab, this will return the number of
      * non-private tabs; likewise, if this is a private tab, this will return
@@ -206,41 +197,21 @@ public class Tabs implements GeckoEventL
             };
 
             // It's safe to use the db here since we aren't doing any I/O.
             final GeckoProfile profile = GeckoProfile.get(mAppContext);
             profile.getDB().registerBookmarkObserver(getContentResolver(), mBookmarksContentObserver);
         }
     }
 
-    // Must be synchronized to avoid racing on mReadingListContentObserver.
-    private void lazyRegisterReadingListObserver() {
-        if (mReadingListContentObserver == null) {
-            mReadingListContentObserver = new ContentObserver(null) {
-                @Override
-                public void onChange(final boolean selfChange) {
-                    for (final Tab tab : mOrder) {
-                        tab.updateReadingList();
-                    }
-                }
-            };
-
-            // It's safe to use the db here since we aren't doing any I/O.
-            final GeckoProfile profile = GeckoProfile.get(mAppContext);
-            profile.getDB().getReadingListAccessor().registerContentObserver(
-                    mAppContext, mReadingListContentObserver);
-        }
-    }
-
     private Tab addTab(int id, String url, boolean external, int parentId, String title, boolean isPrivate, int tabIndex) {
         final Tab tab = isPrivate ? new PrivateTab(mAppContext, id, url, external, parentId, title) :
                                     new Tab(mAppContext, id, url, external, parentId, title);
         synchronized (this) {
             lazyRegisterBookmarkObserver();
-            lazyRegisterReadingListObserver();
             mTabs.put(id, tab);
 
             if (tabIndex > -1) {
                 mOrder.add(tabIndex, tab);
             } else {
                 mOrder.add(tab);
             }
         }
@@ -641,18 +612,16 @@ public class Tabs implements GeckoEventL
         PAGE_SHOW,
         LINK_FEED,
         SECURITY_CHANGE,
         DESKTOP_MODE_CHANGE,
         VIEWPORT_CHANGE,
         RECORDING_CHANGE,
         BOOKMARK_ADDED,
         BOOKMARK_REMOVED,
-        READING_LIST_ADDED,
-        READING_LIST_REMOVED,
         AUDIO_PLAYING_CHANGE,
     }
 
     public void notifyListeners(Tab tab, TabEvents msg) {
         notifyListeners(tab, msg, "");
     }
 
     public void notifyListeners(final Tab tab, final TabEvents msg, final Object data) {