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

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

Issue 1708763003: Fix strict mode violation in TabPersistentStore.cleanupPersistentData() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab-persist-1
Patch Set: comments & rebase Created 4 years, 9 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/tabmodel/TabPersistentStore.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java
index d2cb3f19ec5517ffc52df3d41af671eb2517f9e4..fa8a8119bc069eacbfa4cabed821fc13eac241ba 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java
@@ -511,7 +511,7 @@ public class TabPersistentStore extends TabPersister {
public void clearState() {
deleteFileAsync(SAVED_STATE_FILE);
- cleanupPersistentData();
+ cleanUpPersistentData();
onStateLoaded();
}
@@ -939,7 +939,7 @@ public class TabPersistentStore extends TabPersister {
if (mTabsToRestore.isEmpty()) {
mNormalTabsRestored = null;
mIncognitoTabsRestored = null;
- cleanupPersistentData();
+ cleanUpPersistentData();
onStateLoaded();
mLoadTabTask = null;
Log.d(TAG, "Loaded tab lists; counts: " + mTabModelSelector.getModel(false).getCount()
@@ -951,38 +951,11 @@ public class TabPersistentStore extends TabPersister {
}
}
- private void cleanupPersistentData() {
- String[] files = getStateDirectory().list();
- if (files != null) {
- for (String file : files) {
- Pair<Integer, Boolean> data = TabState.parseInfoFromFilename(file);
- if (data != null) {
- TabModel model = mTabModelSelector.getModel(data.second);
- if (TabModelUtils.getTabById(model, data.first) == null) {
- deleteFileAsync(file);
- }
- }
- }
- }
+ private void cleanUpPersistentData() {
+ new CleanUpTabStateDataTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (mTabContentManager != null) {
- mTabContentManager.cleanupPersistentData(mTabModelSelector);
- }
- }
-
- private void cleanupPersistentDataAtAndAboveId(int minForbiddenId) {
- String[] files = getStateDirectory().list();
- if (files != null) {
- for (String file : files) {
- Pair<Integer, Boolean> data = TabState.parseInfoFromFilename(file);
- if (data != null && data.first >= minForbiddenId) {
- deleteFileAsync(file);
- }
- }
- }
-
- if (mTabContentManager != null) {
- mTabContentManager.cleanupPersistentDataAtAndAboveId(minForbiddenId);
+ mTabContentManager.cleanUpPersistentData(mTabModelSelector);
}
}
@@ -1020,6 +993,34 @@ public class TabPersistentStore extends TabPersister {
// Explicitly serializing file mutations (save & delete) to ensure they occur in order.
}
+ private class CleanUpTabStateDataTask extends AsyncTask<Void, Void, String[]> {
+ @Override
+ protected String[] doInBackground(Void... voids) {
+ if (mDestroyed) {
+ return null;
+ }
+ return getStateDirectory().list();
+ }
+
+ @Override
+ protected void onPostExecute(String[] fileNames) {
+ if (mDestroyed || fileNames == null) {
+ return;
+ }
+ for (String fileName : fileNames) {
+ Pair<Integer, Boolean> data = TabState.parseInfoFromFilename(fileName);
+ if (data != null) {
+ TabModel model = mTabModelSelector.getModel(data.second);
+ if (TabModelUtils.getTabById(model, data.first) == null) {
+ // It might be more efficient to use a single task for all files, but
+ // the number of files is expected to be very small.
+ deleteFileAsync(fileName);
+ }
+ }
+ }
+ }
+ }
+
private class LoadTabTask extends AsyncTask<Void, Void, TabState> {
public final TabRestoreDetails mTabToRestore;

Powered by Google App Engine
This is Rietveld 408576698