| 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 ceebac54bd3b1568a71acb26f1aa60276922cb88..c8e9287a2810e7fbeee7a4b31a95ab7dba9c15c4 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
|
| @@ -27,6 +27,7 @@ import org.chromium.base.metrics.RecordHistogram;
|
| import org.chromium.base.metrics.RecordUserAction;
|
| import org.chromium.chrome.browser.TabState;
|
| import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
|
| +import org.chromium.chrome.browser.ntp.NewTabPage;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| import org.chromium.chrome.browser.tab.TabIdManager;
|
| import org.chromium.content_public.browser.LoadUrlParams;
|
| @@ -276,19 +277,11 @@ public class TabPersistentStore extends TabPersister {
|
|
|
| // Add current tabs to save because they did not get a save signal yet.
|
| Tab currentStandardTab = TabModelUtils.getCurrentTab(mTabModelSelector.getModel(false));
|
| - if (currentStandardTab != null && !mTabsToSave.contains(currentStandardTab)
|
| - && currentStandardTab.isTabStateDirty()
|
| - // For content URI, the read permission granted to an activity is not
|
| - // persistent.
|
| - && !isTabUrlContentScheme(currentStandardTab)) {
|
| - mTabsToSave.addLast(currentStandardTab);
|
| - }
|
| + addTabToSaveQueueIfApplicable(currentStandardTab);
|
| +
|
| Tab currentIncognitoTab = TabModelUtils.getCurrentTab(mTabModelSelector.getModel(true));
|
| - if (currentIncognitoTab != null && !mTabsToSave.contains(currentIncognitoTab)
|
| - && currentIncognitoTab.isTabStateDirty()
|
| - && !isTabUrlContentScheme(currentIncognitoTab)) {
|
| - mTabsToSave.addLast(currentIncognitoTab);
|
| - }
|
| + addTabToSaveQueueIfApplicable(currentIncognitoTab);
|
| +
|
| // Wait for the current tab to save.
|
| if (mSaveTabTask != null) {
|
| // Cancel calls get() to wait for this to finish internally if it has to.
|
| @@ -297,11 +290,7 @@ public class TabPersistentStore extends TabPersister {
|
| if (mSaveTabTask.cancel(false) && !mSaveTabTask.mStateSaved) {
|
| // The task was successfully cancelled. We should try to save this state again.
|
| Tab cancelledTab = mSaveTabTask.mTab;
|
| - if (!mTabsToSave.contains(cancelledTab)
|
| - && cancelledTab.isTabStateDirty()
|
| - && !isTabUrlContentScheme(cancelledTab)) {
|
| - mTabsToSave.addLast(cancelledTab);
|
| - }
|
| + addTabToSaveQueueIfApplicable(cancelledTab);
|
| }
|
|
|
| mSaveTabTask = null;
|
| @@ -330,6 +319,14 @@ public class TabPersistentStore extends TabPersister {
|
| }
|
| }
|
|
|
| + @VisibleForTesting
|
| + void initializeRestoreVars(boolean ignoreIncognitoFiles) {
|
| + mCancelNormalTabLoads = false;
|
| + mCancelIncognitoTabLoads = ignoreIncognitoFiles;
|
| + mNormalTabsRestored = new SparseIntArray();
|
| + mIncognitoTabsRestored = new SparseIntArray();
|
| + }
|
| +
|
| /**
|
| * Restore saved state. Must be called before any tabs are added to the list.
|
| *
|
| @@ -348,10 +345,8 @@ public class TabPersistentStore extends TabPersister {
|
| waitForMigrationToFinish();
|
| logExecutionTime("LoadStateTime", time);
|
|
|
| - mCancelNormalTabLoads = false;
|
| - mCancelIncognitoTabLoads = ignoreIncognitoFiles;
|
| - mNormalTabsRestored = new SparseIntArray();
|
| - mIncognitoTabsRestored = new SparseIntArray();
|
| + initializeRestoreVars(ignoreIncognitoFiles);
|
| +
|
| try {
|
| long timeLoadingState = SystemClock.uptimeMillis();
|
| assert mTabModelSelector.getModel(true).getCount() == 0;
|
| @@ -421,10 +416,7 @@ public class TabPersistentStore extends TabPersister {
|
| }
|
|
|
| // Initialize variables.
|
| - mCancelNormalTabLoads = false;
|
| - mCancelIncognitoTabLoads = false;
|
| - mNormalTabsRestored = new SparseIntArray();
|
| - mIncognitoTabsRestored = new SparseIntArray();
|
| + initializeRestoreVars(false);
|
|
|
| try {
|
| long time = SystemClock.uptimeMillis();
|
| @@ -554,7 +546,16 @@ public class TabPersistentStore extends TabPersister {
|
| }
|
| }
|
|
|
| - private void restoreTab(
|
| + /**
|
| + * Handles restoring an individual tab.
|
| + *
|
| + * @param tabToRestore Meta data about the tab to be restored.
|
| + * @param tabState The previously serialized state of the tab to be restored.
|
| + * @param setAsActive Whether the tab should be set as the active tab as part of the
|
| + * restoration process.
|
| + */
|
| + @VisibleForTesting
|
| + protected void restoreTab(
|
| TabRestoreDetails tabToRestore, TabState tabState, boolean setAsActive) {
|
| // If we don't have enough information about the Tab, bail out.
|
| boolean isIncognito = isIncognitoTabBeingRestored(tabToRestore, tabState);
|
| @@ -594,6 +595,11 @@ public class TabPersistentStore extends TabPersister {
|
| mTabCreatorManager.getTabCreator(isIncognito).createFrozenTab(
|
| tabState, tabToRestore.id, restoredIndex);
|
| } else {
|
| + if (NewTabPage.isNTPUrl(tabToRestore.url) && !setAsActive) {
|
| + Log.i(TAG, "Skipping restore of non-selected NTP.");
|
| + return;
|
| + }
|
| +
|
| Log.w(TAG, "Failed to restore TabState; creating Tab with last known URL.");
|
| Tab fallbackTab = mTabCreatorManager.getTabCreator(isIncognito).createNewTab(
|
| new LoadUrlParams(tabToRestore.url), TabModel.TabLaunchType.FROM_RESTORE, null);
|
| @@ -684,12 +690,30 @@ public class TabPersistentStore extends TabPersister {
|
| }
|
|
|
| public void addTabToSaveQueue(Tab tab) {
|
| - if (!mTabsToSave.contains(tab) && tab.isTabStateDirty() && !isTabUrlContentScheme(tab)) {
|
| - mTabsToSave.addLast(tab);
|
| - }
|
| + addTabToSaveQueueIfApplicable(tab);
|
| saveNextTab();
|
| }
|
|
|
| + /**
|
| + * @return Whether the specified tab is in any pending save operations.
|
| + */
|
| + @VisibleForTesting
|
| + boolean isTabPendingSave(Tab tab) {
|
| + return (mSaveTabTask != null && mSaveTabTask.mTab.equals(tab)) || mTabsToSave.contains(tab);
|
| + }
|
| +
|
| + private void addTabToSaveQueueIfApplicable(Tab tab) {
|
| + if (tab == null) return;
|
| + if (mTabsToSave.contains(tab) || !tab.isTabStateDirty() || isTabUrlContentScheme(tab)) {
|
| + return;
|
| + }
|
| +
|
| + if (NewTabPage.isNTPUrl(tab.getUrl()) && !tab.canGoBack() && !tab.canGoForward()) {
|
| + return;
|
| + }
|
| + mTabsToSave.addLast(tab);
|
| + }
|
| +
|
| public void removeTabFromQueues(Tab tab) {
|
| mTabsToSave.remove(tab);
|
| mTabsToRestore.remove(getTabToRestoreById(tab.getId()));
|
| @@ -1044,7 +1068,12 @@ public class TabPersistentStore extends TabPersister {
|
| return nextId;
|
| }
|
|
|
| - private void saveNextTab() {
|
| + /**
|
| + * Triggers the next save tab task. Clients do not need to call this as it will be triggered
|
| + * automatically by calling {@link #addTabToSaveQueue(Tab)}.
|
| + */
|
| + @VisibleForTesting
|
| + void saveNextTab() {
|
| if (mSaveTabTask != null) return;
|
| if (!mTabsToSave.isEmpty()) {
|
| Tab tab = mTabsToSave.removeFirst();
|
| @@ -1253,7 +1282,11 @@ public class TabPersistentStore extends TabPersister {
|
| }
|
| }
|
|
|
| - private static final class TabRestoreDetails {
|
| + /**
|
| + * Provides additional meta data to restore an individual tab.
|
| + */
|
| + @VisibleForTesting
|
| + protected static final class TabRestoreDetails {
|
| public final int id;
|
| public final int originalIndex;
|
| public final String url;
|
|
|