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