use of org.chromium.chrome.browser.TabState in project AndroidChromium by JackyAndroid.
the class TabPersistentStore method saveState.
public void saveState() {
// Temporarily allowing disk access. TODO: Fix. See http://b/5518024
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
long saveStateStartTime = SystemClock.uptimeMillis();
// it looked when the SaveListTask was first created.
if (mSaveListTask != null)
mSaveListTask.cancel(true);
try {
saveListToFile(serializeTabMetadata());
} catch (IOException e) {
Log.w(TAG, "Error while saving tabs state; will attempt to continue...", e);
}
logExecutionTime("SaveListTime", saveStateStartTime);
// 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() && // persistent.
!isTabUrlContentScheme(currentStandardTab)) {
mTabsToSave.addLast(currentStandardTab);
}
Tab currentIncognitoTab = TabModelUtils.getCurrentTab(mTabModelSelector.getModel(true));
if (currentIncognitoTab != null && !mTabsToSave.contains(currentIncognitoTab) && currentIncognitoTab.isTabStateDirty() && !isTabUrlContentScheme(currentIncognitoTab)) {
mTabsToSave.addLast(currentIncognitoTab);
}
// Wait for the current tab to save.
if (mSaveTabTask != null) {
// wrote the state to disk. That's why we have to check mStateSaved here.
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);
}
}
mSaveTabTask = null;
}
long saveTabsStartTime = SystemClock.uptimeMillis();
// Synchronously save any remaining unsaved tabs (hopefully very few).
for (Tab tab : mTabsToSave) {
int id = tab.getId();
boolean incognito = tab.isIncognito();
try {
TabState state = tab.getState();
if (state != null) {
TabState.saveState(getTabStateFile(id, incognito), state, incognito);
}
} catch (OutOfMemoryError e) {
Log.w(TAG, "Out of memory error while attempting to save tab state. Erasing.");
deleteTabState(id, incognito);
}
}
mTabsToSave.clear();
logExecutionTime("SaveTabsTime", saveTabsStartTime);
logExecutionTime("SaveStateTime", saveStateStartTime);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
use of org.chromium.chrome.browser.TabState in project AndroidChromium by JackyAndroid.
the class Tab method getState.
/** @return An opaque "state" object that can be persisted to storage. */
public TabState getState() {
if (!isInitialized())
return null;
TabState tabState = new TabState();
tabState.contentsState = getWebContentsState();
tabState.openerAppId = mAppAssociatedWith;
tabState.parentId = mParentId;
tabState.shouldPreserve = mShouldPreserve;
tabState.syncId = mSyncId;
tabState.timestampMillis = mTimestampMillis;
tabState.themeColor = getThemeColor();
return tabState;
}
use of org.chromium.chrome.browser.TabState in project AndroidChromium by JackyAndroid.
the class FullScreenActivity method createTab.
/**
* Creates the {@link Tab} used by the FullScreenActivity.
* If the {@code savedInstanceState} exists, then the user did not intentionally close the app
* by swiping it away in the recent tasks list. In that case, we try to restore the tab from
* disk.
*/
private Tab createTab() {
Tab tab = null;
boolean unfreeze = false;
int tabId = Tab.INVALID_TAB_ID;
String tabUrl = null;
if (getSavedInstanceState() != null) {
tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TAB_ID);
tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL);
}
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, this, getWindowAndroid(), TabLaunchType.FROM_RESTORE, TabCreationState.FROZEN_ON_RESTORE, tabState);
unfreeze = true;
}
if (tab == null) {
tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_CHROME_UI, null, null);
}
tab.initialize(null, getTabContentManager(), createTabDelegateFactory(), false, unfreeze);
mWebContentsObserver = new WebContentsObserver(tab.getWebContents()) {
@Override
public void didCommitProvisionalLoadForFrame(long frameId, boolean isMainFrame, String url, int transitionType) {
if (isMainFrame) {
// Notify the renderer to permanently hide the top controls since they do
// not apply to fullscreen content views.
getActivityTab().updateTopControlsState(getActivityTab().getTopControlsStateConstraints(), true);
}
}
};
return tab;
}
use of org.chromium.chrome.browser.TabState in project AndroidChromium by JackyAndroid.
the class TabPersistentStore method restoreTab.
private void restoreTab(TabRestoreDetails tabToRestore, boolean setAsActive) {
// As we do this in startup, and restoring the active tab's state is critical, we permit
// this read in the event that the prefetch task is not available. Either:
// 1. The user just upgraded, has not yet set the new active tab id pref yet. Or
// 2. restoreTab is used to preempt async queue and restore immediately on the UI thread.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
long time = SystemClock.uptimeMillis();
TabState state;
int restoredTabId = mPreferences.getInt(PREF_ACTIVE_TAB_ID, Tab.INVALID_TAB_ID);
if (restoredTabId == tabToRestore.id && mPrefetchActiveTabTask != null) {
long timeWaitingForPrefetch = SystemClock.uptimeMillis();
state = mPrefetchActiveTabTask.get();
logExecutionTime("RestoreTabPrefetchTime", timeWaitingForPrefetch);
} else {
// Necessary to do on the UI thread as a last resort.
state = TabState.restoreTabState(getStateDirectory(), tabToRestore.id);
}
logExecutionTime("RestoreTabTime", time);
restoreTab(tabToRestore, state, setAsActive);
} catch (Exception e) {
// Catch generic exception to prevent a corrupted state from crashing the app
// at startup.
Log.d(TAG, "loadTabs exception: " + e.toString(), e);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
Aggregations