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

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: fix test, address commetns Created 4 years, 10 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 fd870da029d87051ff1206444a8f04a97e6bb582..530dac947dcbe59e975a5bebaa09781304e62cc5 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
@@ -361,7 +361,7 @@ public class TabPersistentStore extends TabPersister {
// pointing to old files and not deleted fast enough. This makes sure to delete everything
// that we are sure not to use.
// This assumes that the app will only create tab with id at and above nextId.
- cleanupPersistentDataAtAndAboveId(nextId);
+ cleanUpPersistentDataAtAndAboveId(nextId);
if (mObserver != null) mObserver.onInitialized(mTabsToRestore.size());
return nextId;
@@ -509,7 +509,7 @@ public class TabPersistentStore extends TabPersister {
public void clearState() {
deleteFileAsync(SAVED_STATE_FILE);
- cleanupPersistentData();
+ cleanUpPersistentData();
onStateLoaded();
}
@@ -943,7 +943,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()
@@ -955,37 +955,17 @@ 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);
- }
- }
- }
- }
-
- if (mTabContentManager != null) {
- mTabContentManager.cleanupPersistentData(mTabModelSelector);
- }
+ private void cleanUpPersistentData() {
+ cleanUpPersistentDataAtAndAboveId(-1);
}
- 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);
- }
- }
- }
+ private void cleanUpPersistentDataAtAndAboveId(int minForbiddenId) {
+ new CleanUpPersistentDataTask(minForbiddenId)
+ .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- if (mTabContentManager != null) {
+ if (mTabContentManager != null && minForbiddenId < 0) {
+ mTabContentManager.cleanupPersistentData(mTabModelSelector);
+ } else if (mTabContentManager != null) {
mTabContentManager.cleanupPersistentDataAtAndAboveId(minForbiddenId);
gone 2016/02/18 17:45:35 Can't tell if it's cleaner to pull the common null
agrieve 2016/02/23 21:28:38 Done.
}
}
@@ -1024,6 +1004,39 @@ public class TabPersistentStore extends TabPersister {
// Explicitly serializing file mutations (save & delete) to ensure they occur in order.
}
+ private class CleanUpPersistentDataTask extends AsyncTask<Void, Void, String[]> {
gone 2016/02/18 17:45:35 Can you rename this CleanUpTabStateDataTask, inste
agrieve 2016/02/23 21:28:38 Done.
+ private final int mAtAndAboveId;
+
+ public CleanUpPersistentDataTask(int atAndAboveId) {
+ mAtAndAboveId = atAndAboveId;
+ }
+
+ @Override
+ protected String[] doInBackground(Void... voids) {
+ if (mDestroyed) {
+ return null;
+ }
+ return getStateDirectory().list();
+ }
+
+ @Override
+ protected void onPostExecute(String[] fileNames) {
+ if (!mDestroyed && fileNames != null) {
gone 2016/02/18 17:45:35 nit: early exit instead to avoid indentation?
agrieve 2016/02/23 21:28:38 Done.
+ for (String fileName : fileNames) {
+ Pair<Integer, Boolean> data = TabState.parseInfoFromFilename(fileName);
+ if (data != null && data.first >= mAtAndAboveId) {
+ TabModel model = mTabModelSelector.getModel(data.second);
+ if (TabModelUtils.getTabById(model, data.first) == null) {
gone 2016/02/18 17:45:35 There's a behavioral change here, right? Before,
agrieve 2016/02/19 01:43:26 Yikes! I stared and stared at this code and didn't
gone 2016/02/19 23:54:04 I think we'd be fine just with deleting TabState f
agrieve 2016/02/23 21:28:38 Done.
+ // 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