Commit 43f6a1d5 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Clean up WebAppActivity tab save/reload

This is cleanup in preparation for
https://chromium-review.googlesource.com/c/chromium/src/+/1313556, but
is probably worth it on its own as it puts all of the logic for save/
restore into WebAppActivity instead of having dependent logic split
across SingleTab and WebApp Activity.

Change-Id: Ibdf372e6c3a6be3f7d546a071162ed7a11a5f613
Reviewed-on: https://chromium-review.googlesource.com/c/1329544
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608402}
parent d89b2243
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle;
import android.provider.Browser; import android.provider.Browser;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.View; import android.view.View;
...@@ -219,4 +220,9 @@ public class FullscreenActivity extends SingleTabActivity { ...@@ -219,4 +220,9 @@ public class FullscreenActivity extends SingleTabActivity {
sTabsToSteal.remove(id); sTabsToSteal.remove(id);
return tab; return tab;
} }
@Override
protected Tab restoreTab(Bundle savedInstanceState) {
return null;
}
} }
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
package org.chromium.chrome.browser; package org.chromium.chrome.browser;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle;
import android.util.Pair; import android.util.Pair;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabDelegateFactory; import org.chromium.chrome.browser.tab.TabDelegateFactory;
import org.chromium.chrome.browser.tab.TabUma.TabCreationState;
import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector; import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
...@@ -18,8 +18,6 @@ import org.chromium.chrome.browser.tabmodel.document.TabDelegate; ...@@ -18,8 +18,6 @@ import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
import org.chromium.content_public.browser.ChildProcessImportance; import org.chromium.content_public.browser.ChildProcessImportance;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import java.io.File;
/** /**
* Base class for task-focused activities that need to display a single tab. * Base class for task-focused activities that need to display a single tab.
* *
...@@ -27,9 +25,6 @@ import java.io.File; ...@@ -27,9 +25,6 @@ import java.io.File;
* activities - anything where maintaining multiple tabs is unnecessary. * activities - anything where maintaining multiple tabs is unnecessary.
*/ */
public abstract class SingleTabActivity extends ChromeActivity { public abstract class SingleTabActivity extends ChromeActivity {
protected static final String BUNDLE_TAB_ID = "tabId";
protected static final String BUNDLE_TAB_URL = "tabUrl";
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
...@@ -83,19 +78,9 @@ public abstract class SingleTabActivity extends ChromeActivity { ...@@ -83,19 +78,9 @@ public abstract class SingleTabActivity extends ChromeActivity {
Tab tab = null; Tab tab = null;
boolean unfreeze = false; boolean unfreeze = false;
int tabId = Tab.INVALID_TAB_ID;
String tabUrl = null;
if (getSavedInstanceState() != null) { if (getSavedInstanceState() != null) {
tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TAB_ID); tab = restoreTab(getSavedInstanceState());
tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL); if (tab != null) unfreeze = true;
}
if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirectory() != null) {
// Restore the tab.
TabState tabState = TabState.restoreTabState(getActivityDirectory(), tabId);
tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, getWindowAndroid(),
TabLaunchType.FROM_RESTORE, TabCreationState.FROZEN_ON_RESTORE, tabState);
unfreeze = true;
} }
if (tab == null) { if (tab == null) {
...@@ -114,12 +99,7 @@ public abstract class SingleTabActivity extends ChromeActivity { ...@@ -114,12 +99,7 @@ public abstract class SingleTabActivity extends ChromeActivity {
return new TabDelegateFactory(); return new TabDelegateFactory();
} }
/** protected abstract Tab restoreTab(Bundle savedInstanceState);
* @return {@link File} pointing at a directory specific for this class.
*/
protected File getActivityDirectory() {
return null;
}
@Override @Override
protected boolean handleBackPressed() { protected boolean handleBackPressed() {
......
...@@ -48,6 +48,8 @@ import org.chromium.chrome.browser.tab.EmptyTabObserver; ...@@ -48,6 +48,8 @@ import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabDelegateFactory; import org.chromium.chrome.browser.tab.TabDelegateFactory;
import org.chromium.chrome.browser.tab.TabObserver; import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.chrome.browser.tab.TabUma.TabCreationState;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.document.TabDelegate; import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
import org.chromium.chrome.browser.toolbar.top.ToolbarControlContainer; import org.chromium.chrome.browser.toolbar.top.ToolbarControlContainer;
import org.chromium.chrome.browser.util.ColorUtils; import org.chromium.chrome.browser.util.ColorUtils;
...@@ -84,6 +86,8 @@ public class WebappActivity extends SingleTabActivity { ...@@ -84,6 +86,8 @@ public class WebappActivity extends SingleTabActivity {
private static final String HISTOGRAM_NAVIGATION_STATUS = "Webapp.NavigationStatus"; private static final String HISTOGRAM_NAVIGATION_STATUS = "Webapp.NavigationStatus";
private static final long MS_BEFORE_NAVIGATING_BACK_FROM_INTERSTITIAL = 1000; private static final long MS_BEFORE_NAVIGATING_BACK_FROM_INTERSTITIAL = 1000;
private static final String BUNDLE_TAB_ID = "tabId";
private static final int ENTER_IMMERSIVE_MODE_DELAY_MILLIS = 300; private static final int ENTER_IMMERSIVE_MODE_DELAY_MILLIS = 300;
private static final int RESTORE_IMMERSIVE_MODE_DELAY_MILLIS = 3000; private static final int RESTORE_IMMERSIVE_MODE_DELAY_MILLIS = 3000;
static final int IMMERSIVE_MODE_UI_FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_STABLE static final int IMMERSIVE_MODE_UI_FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
...@@ -303,10 +307,8 @@ public class WebappActivity extends SingleTabActivity { ...@@ -303,10 +307,8 @@ public class WebappActivity extends SingleTabActivity {
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
if (getActivityTab() != null) { mDirectoryManager.cancelCleanup();
outState.putInt(BUNDLE_TAB_ID, getActivityTab().getId()); saveState(outState);
outState.putString(BUNDLE_TAB_URL, getActivityTab().getUrl());
}
} }
@Override @Override
...@@ -318,8 +320,6 @@ public class WebappActivity extends SingleTabActivity { ...@@ -318,8 +320,6 @@ public class WebappActivity extends SingleTabActivity {
@Override @Override
public void onStopWithNative() { public void onStopWithNative() {
super.onStopWithNative(); super.onStopWithNative();
mDirectoryManager.cancelCleanup();
if (getActivityTab() != null) saveState(getActivityDirectory());
if (getFullscreenManager() != null) { if (getFullscreenManager() != null) {
getFullscreenManager().exitPersistentFullscreenMode(); getFullscreenManager().exitPersistentFullscreenMode();
} }
...@@ -328,9 +328,16 @@ public class WebappActivity extends SingleTabActivity { ...@@ -328,9 +328,16 @@ public class WebappActivity extends SingleTabActivity {
/** /**
* Saves the tab data out to a file. * Saves the tab data out to a file.
*/ */
void saveState(File activityDirectory) { private void saveState(Bundle outState) {
if (getActivityTab() == null || getActivityTab().getUrl() == null
|| getActivityTab().getUrl().isEmpty()) {
return;
}
outState.putInt(BUNDLE_TAB_ID, getActivityTab().getId());
String tabFileName = TabState.getTabStateFilename(getActivityTab().getId(), false); String tabFileName = TabState.getTabStateFilename(getActivityTab().getId(), false);
File tabFile = new File(activityDirectory, tabFileName); File tabFile = new File(getActivityDirectory(), tabFileName);
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781 // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
...@@ -344,6 +351,19 @@ public class WebappActivity extends SingleTabActivity { ...@@ -344,6 +351,19 @@ public class WebappActivity extends SingleTabActivity {
} }
} }
@Override
protected Tab restoreTab(Bundle savedInstanceState) {
int tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TAB_ID);
if (tabId == Tab.INVALID_TAB_ID || getActivityDirectory() == null) return null;
TabState tabState = TabState.restoreTabState(getActivityDirectory(), tabId);
if (tabState == null) return null;
return new Tab(tabId, Tab.INVALID_TAB_ID, false, getWindowAndroid(),
TabLaunchType.FROM_RESTORE, TabCreationState.FROZEN_ON_RESTORE, tabState);
}
@Override @Override
public void onWindowFocusChanged(boolean hasFocus) { public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus); super.onWindowFocusChanged(hasFocus);
...@@ -822,8 +842,7 @@ public class WebappActivity extends SingleTabActivity { ...@@ -822,8 +842,7 @@ public class WebappActivity extends SingleTabActivity {
* *
* @return The directory used for the current web app. * @return The directory used for the current web app.
*/ */
@Override private File getActivityDirectory() {
protected final File getActivityDirectory() {
return mDirectoryManager.getWebappDirectory(this, getActivityId()); return mDirectoryManager.getWebappDirectory(this, getActivityId());
} }
......
...@@ -61,7 +61,6 @@ public class WebappDirectoryManager { ...@@ -61,7 +61,6 @@ public class WebappDirectoryManager {
* *
* @param context Context to pull info and Files from. * @param context Context to pull info and Files from.
* @param currentWebappId ID for the currently running web app. * @param currentWebappId ID for the currently running web app.
* @return AsyncTask doing the cleaning.
*/ */
public void cleanUpDirectories(final Context context, final String currentWebappId) { public void cleanUpDirectories(final Context context, final String currentWebappId) {
if (mCleanupTask != null) return; if (mCleanupTask != null) return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment