Commit 977b6be2 authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

Add logging while loading tab state

Add additional debug logging while loading / merging tab state, to be
(mostly) removed after bug resolution.

Also adds two new IllegalStateException's for completely unexpected
states.

BUG=1111594

Change-Id: I2c900eb47889659e593de5f8186e3e82c2bbd0b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340296
Commit-Queue: Theresa  <twellington@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795498}
parent cf3a7e72
......@@ -1085,7 +1085,7 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent
TraceEvent.begin("ChromeTabbedActivity.initializeState");
super.initializeState();
Log.i(TAG, "#initializeState");
Intent intent = getIntent();
boolean hadCipherData =
......
......@@ -54,6 +54,8 @@ public class ChromeTabCreator extends TabCreator {
boolean handleCreateNTPIfNeeded(boolean isNTP, boolean isIncognito);
}
private static final String TAG = "ChromeTabCreator";
private final ChromeActivity mActivity;
private final StartupTabPreloader mStartupTabPreloader;
private final boolean mIncognito;
......@@ -385,7 +387,8 @@ public class ChromeTabCreator extends TabCreator {
TabReparentingParams params = (TabReparentingParams) asyncParams;
tab = params.getTabToReparent();
if (tab.isIncognito() != state.isIncognito()) {
throw new IllegalStateException("Incognito state mismatch");
throw new IllegalStateException("Incognito state mismatch. TabState: "
+ state.isIncognito() + ". Tab: " + tab.isIncognito());
}
ReparentingTask.from(tab).finish(
ReparentingDelegateFactory.createReparentingTaskDelegate(
......@@ -409,7 +412,12 @@ public class ChromeTabCreator extends TabCreator {
.setTabState(state)
.build();
}
assert state.isIncognito() == mIncognito;
if (state.isIncognito() != mIncognito) {
throw new IllegalStateException("Incognito state mismatch. TabState: "
+ state.isIncognito() + ". Creator: " + mIncognito);
}
mTabModel.addTab(tab, index, launchType, creationState);
return tab;
}
......
......@@ -350,6 +350,7 @@ public class TabPersistentStore extends TabPersister {
waitForMigrationToFinish();
logExecutionTime("LoadStateTime", time);
Log.i(TAG, "#loadState, ignoreIncognitoFiles? " + ignoreIncognitoFiles);
initializeRestoreVars(ignoreIncognitoFiles);
try {
......@@ -428,6 +429,7 @@ public class TabPersistentStore extends TabPersister {
return;
}
Log.i(TAG, "Merging state");
// Initialize variables.
initializeRestoreVars(false);
......@@ -585,6 +587,12 @@ public class TabPersistentStore extends TabPersister {
}
TabModel model = mTabModelSelector.getModel(isIncognito);
if (model.isIncognito() != isIncognito) {
throw new IllegalStateException("Incognito state mismatch. Restored tab state: "
+ isIncognito + ". Model: " + model.isIncognito());
}
SparseIntArray restoredTabs = isIncognito ? mIncognitoTabsRestored : mNormalTabsRestored;
int restoredIndex = 0;
if (tabToRestore.fromMerge) {
......@@ -1064,6 +1072,9 @@ public class TabPersistentStore extends TabPersister {
final int count = stream.readInt();
final int incognitoCount = skipIncognitoCount ? -1 : stream.readInt();
Log.i(TAG,
"Tab metadata, skipIncognitoCount? " + skipIncognitoCount
+ " incognitoCount: " + incognitoCount + " totalCount: " + count);
final int incognitoActiveIndex = stream.readInt();
final int standardActiveIndex = stream.readInt();
if (count < 0 || incognitoActiveIndex >= count || standardActiveIndex >= count) {
......@@ -1077,6 +1088,7 @@ public class TabPersistentStore extends TabPersister {
if (tabIds != null) tabIds.append(id, true);
Boolean isIncognito = (incognitoCount < 0) ? null : i < incognitoCount;
if (callback != null) {
callback.onDetailsRead(i, id, tabUrl, isIncognito,
i == standardActiveIndex, i == incognitoActiveIndex);
......@@ -1320,6 +1332,11 @@ public class TabPersistentStore extends TabPersister {
if (mDestroyed || isCancelled()) return;
boolean isIncognito = isIncognitoTabBeingRestored(mTabToRestore, tabState);
if (isIncognito) {
Log.i(TAG,
"Finishing tab restore, isIncognito: " + isIncognito
+ " cancelIncognito: " + mCancelIncognitoTabLoads);
}
boolean isLoadCancelled = (isIncognito && mCancelIncognitoTabLoads)
|| (!isIncognito && mCancelNormalTabLoads);
if (!isLoadCancelled) restoreTab(mTabToRestore, tabState, false);
......@@ -1364,13 +1381,16 @@ public class TabPersistentStore extends TabPersister {
*/
private boolean isIncognitoTabBeingRestored(TabRestoreDetails tabDetails, TabState tabState) {
if (tabState != null) {
Log.i(TAG, "#isIncognitoTabBeingRestored from tabState: " + tabState.isIncognito());
// The Tab's previous state was completely restored.
return tabState.isIncognito();
} else if (tabDetails.isIncognito != null) {
Log.i(TAG, "#isIncognitoTabBeingRestored from tabDetails: " + tabDetails.isIncognito);
// The TabState couldn't be restored, but we have some information about the tab.
return tabDetails.isIncognito;
} else {
// The tab's type is undecideable.
Log.i(TAG, "#isIncognitoTabBeingRestored defaulting to false");
// The tab's type is undecidable.
return false;
}
}
......
......@@ -70,6 +70,7 @@ public class TabPersistentStoreUnitTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mIncognitoTabModel.isIncognito()).thenReturn(true);
when(mTabModelSelector.getModel(false)).thenReturn(mNormalTabModel);
when(mTabModelSelector.getModel(true)).thenReturn(mIncognitoTabModel);
......
......@@ -270,19 +270,27 @@ public class CipherFactory {
*
*/
public boolean restoreFromBundle(Bundle savedInstanceState) {
if (savedInstanceState == null) return false;
if (savedInstanceState == null) {
Log.i(TAG, "#restoreFromBundle, no savedInstanceState.");
return false;
}
byte[] wrappedKey = savedInstanceState.getByteArray(BUNDLE_KEY);
byte[] iv = savedInstanceState.getByteArray(BUNDLE_IV);
if (wrappedKey == null || iv == null) return false;
if (wrappedKey == null || iv == null) {
Log.i(TAG, "#restoreFromBundle, no wrapped key or no iv.");
return false;
}
try {
Key bundledKey = new SecretKeySpec(wrappedKey, "AES");
synchronized (mDataLock) {
if (mData == null) {
Log.i(TAG, "#restoreFromBundle, creating new CipherData.");
mData = new CipherData(bundledKey, iv);
return true;
} else if (mData.key.equals(bundledKey) && Arrays.equals(mData.iv, iv)) {
Log.i(TAG, "#restoreFromBundle, using existing CipherData.");
return true;
} else {
Log.e(TAG, "Attempted to restore different cipher data.");
......
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