Commit ae45f114 authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Fix sessions loss on cold start on iPhones when multiwindow is enabled

Update previousSessionInfo to retain the session id in the case of single
window app, then use it on later runs for the first restore of the run.

Bug: 1131031
Change-Id: I3b245826e9a9c40cb6df1d2e9c4123276c8d73f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2442231
Commit-Queue: Mark Cogan <marq@chromium.org>
Auto-Submit: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812730}
parent e902bd38
...@@ -90,6 +90,10 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -90,6 +90,10 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
// The last window which received a tap. // The last window which received a tap.
@property(nonatomic, weak) UIWindow* lastTappedWindow; @property(nonatomic, weak) UIWindow* lastTappedWindow;
// The SceneSession ID for the last session, where the Device doesn't support
// multiple windows.
@property(nonatomic, strong) NSString* previousSingleWindowSessionID;
// Saves the launchOptions to be used from -newTabFromLaunchOptions. If the // Saves the launchOptions to be used from -newTabFromLaunchOptions. If the
// application is in background, initialize the browser to basic. If not, launch // application is in background, initialize the browser to basic. If not, launch
// the browser. // the browser.
......
...@@ -480,6 +480,12 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -480,6 +480,12 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
moveAsideSessionInformationForBrowserState:chromeBrowserState]; moveAsideSessionInformationForBrowserState:chromeBrowserState];
} }
} }
if (!IsMultipleScenesSupported() && IsMultiwindowSupported()) {
NSSet<NSString*>* previousSessions =
[PreviousSessionInfo sharedInstance].connectedSceneSessionsIDs;
DCHECK(previousSessions.count <= 1);
self.appState.previousSingleWindowSessionID = [previousSessions anyObject];
}
[[PreviousSessionInfo sharedInstance] resetConnectedSceneSessionIDs]; [[PreviousSessionInfo sharedInstance] resetConnectedSceneSessionIDs];
// Initialize and set the main browser state. // Initialize and set the main browser state.
......
...@@ -71,9 +71,6 @@ SessionRestorationBrowserAgent::~SessionRestorationBrowserAgent() { ...@@ -71,9 +71,6 @@ SessionRestorationBrowserAgent::~SessionRestorationBrowserAgent() {
void SessionRestorationBrowserAgent::SetSessionID( void SessionRestorationBrowserAgent::SetSessionID(
const std::string& session_identifier) { const std::string& session_identifier) {
// It's probably incorrect to set this more than once.
DCHECK(session_identifier_.empty() ||
session_identifier_ == session_identifier);
session_identifier_ = session_identifier; session_identifier_ = session_identifier;
} }
......
...@@ -145,6 +145,7 @@ source_set("main") { ...@@ -145,6 +145,7 @@ source_set("main") {
"//base", "//base",
"//components/translate/core/browser", "//components/translate/core/browser",
"//ios/chrome/app:mode", "//ios/chrome/app:mode",
"//ios/chrome/app/application_delegate:app_state_header",
"//ios/chrome/app/resources:launchscreen_xib", "//ios/chrome/app/resources:launchscreen_xib",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/app_launcher", "//ios/chrome/browser/app_launcher",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "ios/chrome/app/application_delegate/app_state.h"
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/crash_report/crash_report_helper.h" #include "ios/chrome/browser/crash_report/crash_report_helper.h"
...@@ -167,10 +168,19 @@ ...@@ -167,10 +168,19 @@
std::string sessionID = base::SysNSStringToUTF8(self.sessionID); std::string sessionID = base::SysNSStringToUTF8(self.sessionID);
SnapshotBrowserAgent::FromBrowser(_mainBrowser.get()) SnapshotBrowserAgent::FromBrowser(_mainBrowser.get())
->SetSessionID(sessionID); ->SetSessionID(sessionID);
SessionRestorationBrowserAgent::FromBrowser(_mainBrowser.get())
->SetSessionID(sessionID); // If the OS doesn't support multiple scenes, use the previous run scene ID
SessionRestorationBrowserAgent::FromBrowser(_mainBrowser.get()) // for the session restoration.
->RestoreSession(); NSString* restoreSessionID = self.sessionID;
if (_sceneState.appState.previousSingleWindowSessionID) {
restoreSessionID = _sceneState.appState.previousSingleWindowSessionID;
}
SessionRestorationBrowserAgent* restorationAgent =
SessionRestorationBrowserAgent::FromBrowser(_mainBrowser.get());
restorationAgent->SetSessionID(base::SysNSStringToUTF8(restoreSessionID));
restorationAgent->RestoreSession();
restorationAgent->SetSessionID(sessionID);
breakpad::MonitorTabStateForWebStateList(_mainBrowser->GetWebStateList()); breakpad::MonitorTabStateForWebStateList(_mainBrowser->GetWebStateList());
// Follow loaded URLs in the main tab model to send those in case of // Follow loaded URLs in the main tab model to send those in case of
// crashes. // crashes.
......
...@@ -363,8 +363,13 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -363,8 +363,13 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
if (self.hasInitializedUI && level == SceneActivationLevelUnattached) { if (self.hasInitializedUI && level == SceneActivationLevelUnattached) {
if (IsMultiwindowSupported()) { if (IsMultiwindowSupported()) {
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
[[PreviousSessionInfo sharedInstance] if (IsMultipleScenesSupported()) {
removeSceneSessionID:sceneState.scene.session.persistentIdentifier]; // If Multiple scenes are not supported, the session shouldn't be
// removed as it can be used for normal restoration.
[[PreviousSessionInfo sharedInstance]
removeSceneSessionID:sceneState.scene.session
.persistentIdentifier];
}
} }
} }
[self teardownUI]; [self teardownUI];
......
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