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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridge.java

Issue 2639403003: Remove Last 1 pages when the tab holding them is destroyed. (Closed)
Patch Set: Adds a test. Created 3 years, 11 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
Index: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridge.java
index f2f42ff68774c0cc1a37078937f4566e626962bc..031e4dbe9d473f94313256ff470c5e3380fcb1af 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridge.java
@@ -11,6 +11,9 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.chrome.browser.tabmodel.TabModel;
+import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList;
@@ -26,6 +29,7 @@ import java.util.Set;
public class OfflinePageBridge {
public static final String ASYNC_NAMESPACE = "async_loading";
public static final String BOOKMARK_NAMESPACE = "bookmark";
+ public static final String LAST_N_NAMESPACE = "last_n";
public static final String SHARE_NAMESPACE = "share";
/**
@@ -435,6 +439,31 @@ public class OfflinePageBridge {
nativeCheckPagesExistOffline(mNativeOfflinePageBridge, urlArray, callbackInternal);
}
+ // Listens for tab closure events and removes any last N pages that still exist for a destroyed
+ // tab. This should only be called once it is no longer possible to "undo" closure of the tab.
+ public static void onTabDestroyed(Tab tab) {
+ // We don't use Tab#getProfile() since it relies on the attached WebContents to extract the
+ // profile, and at tab destruction time this may not exist anymore (returning null). So we
+ // use the tab model to get the profile instead.
+ TabModelSelector selector = tab.getTabModelSelector();
+ if (selector == null) return;
+ TabModel tabModel = selector.getModel(tab.isIncognito());
+ if (tabModel == null) return;
+ OfflinePageBridge bridge = OfflinePageBridge.getForProfile(tabModel.getProfile());
+ if (bridge == null) return;
+
+ ClientId clientId = new ClientId(LAST_N_NAMESPACE, Integer.toString(tab.getId()));
+ List<ClientId> clientIds = new ArrayList<>();
+ clientIds.add(clientId);
+
+ bridge.deletePagesByClientId(clientIds, new Callback<Integer>() {
+ @Override
+ public void onResult(Integer result) {
+ // Result is ignored.
+ }
+ });
+ }
+
@VisibleForTesting
static void setOfflineBookmarksEnabledForTesting(boolean enabled) {
sOfflineBookmarksEnabled = enabled;

Powered by Google App Engine
This is Rietveld 408576698