Commit 26fff17c authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Fix crash restoration to restore all windows correctly.

Also make sure that the restore prompt doesn't show if the user already
restored.


Bug: 1136307
Change-Id: I733202c348923224c20d5e8728cbab9cd21466d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2459804
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815155}
parent ddf84e29
...@@ -15,6 +15,9 @@ class ChromeBrowserState; ...@@ -15,6 +15,9 @@ class ChromeBrowserState;
- (instancetype)initWithBrowser:(Browser*)browser; - (instancetype)initWithBrowser:(Browser*)browser;
// Returns YES if a backup file for sessionID can be found on disk.
+ (BOOL)isBackedUpSessionID:(NSString*)sessionID;
// Saves the session information stored on disk for sessions with |sessionIDs| // Saves the session information stored on disk for sessions with |sessionIDs|
// in temporary files and will then delete those from their default location. // in temporary files and will then delete those from their default location.
// This will ensure that the user will then start from scratch, while allowing // This will ensure that the user will then start from scratch, while allowing
......
...@@ -232,12 +232,12 @@ int SessionCrashedInfoBarDelegate::GetIconId() const { ...@@ -232,12 +232,12 @@ int SessionCrashedInfoBarDelegate::GetIconId() const {
@implementation CrashRestoreHelper { @implementation CrashRestoreHelper {
Browser* _browser; Browser* _browser;
std::unique_ptr<InfoBarManagerObserverBridge> _infoBarBridge; std::unique_ptr<InfoBarManagerObserverBridge> _infoBarBridge;
// Indicate that the session has been restored to tabs or to recently closed
// and should not be rerestored.
BOOL _sessionRestored;
} }
// Indicate that the session has been restored to tabs or to recently closed
// and should not be rerestored.
static BOOL _sessionRestored = NO;
- (instancetype)initWithBrowser:(Browser*)browser { - (instancetype)initWithBrowser:(Browser*)browser {
if (self = [super init]) { if (self = [super init]) {
_browser = browser; _browser = browser;
...@@ -408,6 +408,10 @@ int SessionCrashedInfoBarDelegate::GetIconId() const { ...@@ -408,6 +408,10 @@ int SessionCrashedInfoBarDelegate::GetIconId() const {
error:nil]; error:nil];
} }
+ (BOOL)isBackedUpSessionID:(NSString*)sessionID {
return [[[self class] backedupSessionIDs] containsObject:sessionID];
}
+ (BOOL)moveAsideSessionInformationForBrowserState: + (BOOL)moveAsideSessionInformationForBrowserState:
(ChromeBrowserState*)browserState { (ChromeBrowserState*)browserState {
DCHECK(!IsMultiwindowSupported()); DCHECK(!IsMultiwindowSupported());
...@@ -488,10 +492,15 @@ int SessionCrashedInfoBarDelegate::GetIconId() const { ...@@ -488,10 +492,15 @@ int SessionCrashedInfoBarDelegate::GetIconId() const {
NSString* originalSessionPath = NSString* originalSessionPath =
[SessionServiceIOS sessionPathForSessionID:sessionID [SessionServiceIOS sessionPathForSessionID:sessionID
directory:stashPath]; directory:stashPath];
[fileManager NSString* backupPath =
moveItemAtPath:[[strongSelf class] backupPathForSessionID:sessionID] [[strongSelf class] backupPathForSessionID:sessionID];
[fileManager moveItemAtPath:backupPath
toPath:originalSessionPath toPath:originalSessionPath
error:&error]; error:&error];
// Remove Parent directory for the backup path, so it doesn't show restore
// prompt again.
[fileManager removeItemAtPath:[backupPath stringByDeletingLastPathComponent]
error:&error];
} }
return success; return success;
......
...@@ -614,11 +614,16 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -614,11 +614,16 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
} }
} }
// Only create the restoration helper if the browser state was backed up // Only create the restoration helper if the session with the current session
// successfully. // id was backed up successfully.
if (self.sceneState.appState.sessionRestorationRequired) { if (self.sceneState.appState.sessionRestorationRequired) {
if (!IsMultiwindowSupported() ||
[CrashRestoreHelper
isBackedUpSessionID:self.sceneState.sceneSessionID]) {
self.sceneState.appState.startupInformation.restoreHelper = self.sceneState.appState.startupInformation.restoreHelper =
[[CrashRestoreHelper alloc] initWithBrowser:self.mainInterface.browser]; [[CrashRestoreHelper alloc]
initWithBrowser:self.mainInterface.browser];
}
} }
// Before bringing up the UI, make sure the launch mode is correct, and // Before bringing up the UI, make sure the launch mode is correct, and
......
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