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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelBase.java

Issue 672463002: Add a TabModelBase#closeAllTabs() that supports undo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Require canUndo to be true to send pending closure notification Created 6 years, 2 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 | no next file » | 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/tabmodel/TabModelBase.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelBase.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelBase.java
index b94acadfa1ca48cea12f554db03c56fd9a70b473..7d58d4a3da01366dbd237a3b7398fb4c26cb9cf2 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelBase.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelBase.java
@@ -291,6 +291,19 @@ public abstract class TabModelBase extends TabModelJniBridge {
@Override
public boolean closeTab(Tab tabToClose, boolean animate, boolean uponExit, boolean canUndo) {
+ return closeTab(tabToClose, animate, uponExit, canUndo, canUndo);
+ }
+
+ /**
+ * See TabModel.java documentation for description of other parameters.
+ * @param notify Whether or not to notify observers about the pending closure. If this is
+ * {@code true}, {@link #supportsPendingClosures()} is {@code true},
+ * and canUndo is {@code true}, observers will be notified of the pending
+ * closure. Observers will still be notified of a committed/cancelled closure
+ * even if they are not notified of a pending closure to start with.
+ */
+ private boolean closeTab(Tab tabToClose, boolean animate, boolean uponExit,
+ boolean canUndo, boolean notify) {
if (tabToClose == null) {
assert false : "Tab is null!";
return false;
@@ -303,7 +316,7 @@ public abstract class TabModelBase extends TabModelJniBridge {
canUndo &= supportsPendingClosures();
- if (canUndo) {
+ if (notify && canUndo) {
for (TabModelObserver obs : mObservers) obs.tabPendingClosure(tabToClose);
}
startTabClosure(tabToClose, animate, uponExit, canUndo);
@@ -321,6 +334,29 @@ public abstract class TabModelBase extends TabModelJniBridge {
}
}
+ /**
+ * Close all tabs on this model without notifying observers about pending tab closures.
+ *
+ * @param animate true iff the closing animation should be displayed
+ * @param uponExit true iff the tabs are being closed upon application exit (after user presses
+ * the system back button)
+ * @param canUndo Whether or not this action can be undone. If this is {@code true} and
+ * {@link #supportsPendingClosures()} is {@code true}, these {@link Tab}s
+ * will not actually be closed until {@link #commitTabClosure(int)} or
+ * {@link #commitAllTabClosures()} is called, but they will be effectively
+ * removed from this list.
+ * @return a list containing the ids of tabs that have been closed
+ */
+ public ArrayList<Integer> closeAllTabs(boolean animate, boolean uponExit, boolean canUndo) {
+ ArrayList<Integer> closedTabs = new ArrayList<Integer>();
+ while (getCount() > 0) {
+ Tab tab = getTabAt(0);
+ closedTabs.add(tab.getId());
+ closeTab(tab, animate, uponExit, canUndo, false);
+ }
+ return closedTabs;
+ }
+
@Override
public Tab getTabAt(int index) {
// This will catch INVALID_TAB_INDEX and return null
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698