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

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

Issue 868323003: Begin uniting the TabPersistentStore and StorageDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java » ('j') | 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/TabState.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/TabState.java b/chrome/android/java/src/org/chromium/chrome/browser/TabState.java
index 8e5226360bffe5a7b24ab3514b7de5f142be49d8..8aa972939ced43652ad8ad9524282fd3fe12da93 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/TabState.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/TabState.java
@@ -135,6 +135,31 @@ public class TabState {
}
/**
+ * Restore a TabState file for a particular Tab. Checks if the Tab exists as a regular tab
+ * before searching for an encrypted version.
+ * @param stateFolder Folder containing the TabState files.
+ * @param id ID of the Tab to restore.
+ * @return TabState that has been restored, or null if it failed.
+ */
+ public static TabState restoreTabState(File stateFolder, int id) {
+ // First try finding an unencrypted file.
+ boolean encrypted = false;
+ File file = getTabStateFile(stateFolder, id, encrypted);
+
+ // If that fails, try finding the encrypted version.
+ if (!file.exists()) {
+ encrypted = true;
+ file = getTabStateFile(stateFolder, id, encrypted);
+ }
+
+ // If they both failed, there's nothing to read.
+ if (!file.exists()) return null;
+
+ // If one of them passed, open the file input stream and read the state contents.
+ return restoreTabState(file, encrypted);
+ }
+
+ /**
* Restores a particular TabState file from storage.
* @param tabFile Location of the TabState file.
* @param isIncognito Whether the Tab is incognito or not.
@@ -293,6 +318,28 @@ public class TabState {
}
}
+ /**
+ * Returns a File corresponding to the given TabState.
+ * @param directory Directory containing the TabState files.
+ * @param tabId ID of the TabState to delete.
+ * @param encrypted Whether the TabState is encrypted.
+ * @return File corresponding to the given TabState.
+ */
+ public static File getTabStateFile(File directory, int tabId, boolean encrypted) {
+ return new File(directory, getTabStateFilename(tabId, encrypted));
+ }
+
+ /**
+ * Deletes the TabState corresponding to the given Tab.
+ * @param directory Directory containing the TabState files.
+ * @param tabId ID of the TabState to delete.
+ * @param encrypted Whether the TabState is encrypted.
+ */
+ public static void deleteTabState(File directory, int tabId, boolean encrypted) {
+ File file = getTabStateFile(directory, tabId, encrypted);
+ if (file.exists() && !file.delete()) Log.e(TAG, "Failed to delete TabState: " + file);
+ }
+
/** @return Title currently being displayed in the saved state's current entry. */
public String getDisplayTitleFromState() {
return nativeGetDisplayTitleFromByteBuffer(contentsState.buffer(), contentsState.version());
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698