Commit f1919e1b authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Fix two crashes from the incognito notification.

1.) The repost form warning should use dismissAllowingStateLoss
    for the tab destroy call as it can happen in the background.
    For this dialog in particular, we do not want to restore
    it in the event of a restart, so loss of UI state is not
    only acceptable, but likely what we want always.

2.) Handle the case of tabbed activities in the process of startup
    when clicking the incognito notification.  This just kills
    any tabbed activities that aren't fully running because it
    has sync issues with incognito tabs that might have been read
    already.

BUG=856320

Change-Id: Ic3506d20d42cb915328394f18dcad5574d8dca7e
Reviewed-on: https://chromium-review.googlesource.com/1114279Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570257}
parent 18ddf6f7
...@@ -46,7 +46,7 @@ public class RepostFormWarningDialog extends DialogFragment { ...@@ -46,7 +46,7 @@ public class RepostFormWarningDialog extends DialogFragment {
mTabObserver = new EmptyTabObserver() { mTabObserver = new EmptyTabObserver() {
@Override @Override
public void onDestroyed(Tab tab) { public void onDestroyed(Tab tab) {
dismiss(); dismissAllowingStateLoss();
} }
}; };
mTab.addObserver(mTabObserver); mTab.addObserver(mTabObserver);
...@@ -113,6 +113,12 @@ public class RepostFormWarningDialog extends DialogFragment { ...@@ -113,6 +113,12 @@ public class RepostFormWarningDialog extends DialogFragment {
super.dismiss(); super.dismiss();
} }
@Override
public void dismissAllowingStateLoss() {
if (getFragmentManager() == null) return;
super.dismissAllowingStateLoss();
}
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog); super.onDismiss(dialog);
......
...@@ -71,35 +71,28 @@ public class IncognitoNotificationService extends IntentService { ...@@ -71,35 +71,28 @@ public class IncognitoNotificationService extends IntentService {
// If we failed clearing all of the incognito tabs, then do not dismiss the notification. // If we failed clearing all of the incognito tabs, then do not dismiss the notification.
if (!clearedIncognito) return; if (!clearedIncognito) return;
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(() -> {
@Override if (!TabWindowManager.getInstance().canDestroyIncognitoProfile()) {
public void run() { assert false : "Not all incognito tabs closed as expected";
if (!TabWindowManager.getInstance().canDestroyIncognitoProfile()) { return;
assert false : "Not all incognito tabs closed as expected"; }
return; IncognitoNotificationManager.dismissIncognitoNotification();
}
IncognitoNotificationManager.dismissIncognitoNotification(); if (BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
.isStartupSuccessfullyCompleted()) {
if (BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) if (Profile.getLastUsedProfile().hasOffTheRecordProfile()) {
.isStartupSuccessfullyCompleted()) { Profile.getLastUsedProfile().getOffTheRecordProfile().destroyWhenAppropriate();
if (Profile.getLastUsedProfile().hasOffTheRecordProfile()) {
Profile.getLastUsedProfile().getOffTheRecordProfile()
.destroyWhenAppropriate();
}
} }
} }
}); });
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(() -> {
@Override // Now ensure that the snapshots in recents are all cleared for Tabbed activities
public void run() { // to remove any trace of incognito mode.
// Now ensure that the snapshots in recents are all cleared for Tabbed activities if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// to remove any trace of incognito mode. focusChromeIfNecessary();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { } else {
focusChromeIfNecessary(); removeNonVisibleChromeTabbedRecentEntries();
} else {
removeNonVisibleChromeTabbedRecentEntries();
}
} }
}); });
} }
...@@ -180,22 +173,26 @@ public class IncognitoNotificationService extends IntentService { ...@@ -180,22 +173,26 @@ public class IncognitoNotificationService extends IntentService {
* @see TabWindowManager#getIndexForWindow(Activity) * @see TabWindowManager#getIndexForWindow(Activity)
*/ */
private void closeIncognitoTabsInRunningTabbedActivities() { private void closeIncognitoTabsInRunningTabbedActivities() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(() -> {
@Override List<WeakReference<Activity>> runningActivities =
public void run() { ApplicationStatus.getRunningActivities();
List<WeakReference<Activity>> runningActivities = for (int i = 0; i < runningActivities.size(); i++) {
ApplicationStatus.getRunningActivities(); Activity activity = runningActivities.get(i).get();
for (int i = 0; i < runningActivities.size(); i++) { if (activity == null) continue;
Activity activity = runningActivities.get(i).get(); if (!(activity instanceof ChromeTabbedActivity)) continue;
if (activity == null) continue;
if (!(activity instanceof ChromeTabbedActivity)) continue; ChromeTabbedActivity tabbedActivity = (ChromeTabbedActivity) activity;
if (tabbedActivity.isActivityDestroyed()) continue;
ChromeTabbedActivity tabbedActivity = (ChromeTabbedActivity) activity;
if (tabbedActivity.isActivityDestroyed()) continue; // If the tabbed activity has not yet initialized, then finish the activity to avoid
// timing issues with clearing the incognito tab state in the background.
tabbedActivity.getTabModelSelector().getModel(true).closeAllTabs( if (!tabbedActivity.areTabModelsInitialized()
false, false); || !tabbedActivity.didFinishNativeInitialization()) {
tabbedActivity.finish();
continue;
} }
tabbedActivity.getTabModelSelector().getModel(true).closeAllTabs(false, false);
} }
}); });
} }
......
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