Commit 90bd0b2b authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Migrate both normal and incognito sessions to multi-window.

The flag for the previous window was reset too early before the
incognito session was restored, and that caused the problem of
not migrating incognito sessions


Bug: 1139894
Change-Id: I40384b3f2051a79f18cdd0fc755cc01b402cdd2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2499177
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821397}
parent fe031994
......@@ -101,7 +101,9 @@ enum class DeviceBatteryState {
@property(nonatomic, assign, readonly) BOOL OSRestartedAfterPreviousSession;
// Whether the previous session was on Multi Window enabled version of the
// application.
// application. A previous session doesn't have to be from a previous run, in
// the case of single window to multiple windows migration, after the first
// session created/restored the flag value should be updated to |YES|.
// TODO(crbug.com/1109280): Remove after the migration to Multi-Window sessions
// is done.
@property(nonatomic, assign, readonly) BOOL isMultiWindowEnabledSession;
......@@ -175,6 +177,11 @@ enum class DeviceBatteryState {
// Empties the list of connected session.
- (void)resetConnectedSceneSessionIDs;
// Updates the local and the saved Multi Window support status.
// TODO(crbug.com/1109280): Remove after the migration to Multi-Window
// sessions is done.
- (void)updateMultiWindowSupportStatus;
// Must be called when Chrome starts session restoration. The returned closure
// runner will clear up the flag when destroyed. Can be used on different
// threads.
......
......@@ -259,12 +259,6 @@ static PreviousSessionInfo* gSharedInstance = nil;
NSString* currentLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
[defaults setObject:currentLanguage forKey:kLastRanLanguage];
// Set the current Multi-Window support state.
// TODO(crbug.com/1109280): Remove after the migration to Multi-Window
// sessions is done.
[defaults setBool:base::ios::IsMultiwindowSupported()
forKey:kPreviousSessionInfoMultiWindowEnabled];
// Clear the memory warning flag.
[defaults
removeObjectForKey:previous_session_info_constants::
......@@ -494,6 +488,15 @@ static PreviousSessionInfo* gSharedInstance = nil;
[self synchronizeSceneSessionIDs];
}
- (void)updateMultiWindowSupportStatus {
gSharedInstance.isMultiWindowEnabledSession =
base::ios::IsMultiwindowSupported();
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:gSharedInstance.isMultiWindowEnabledSession
forKey:kPreviousSessionInfoMultiWindowEnabled];
[defaults synchronize];
}
- (base::ScopedClosureRunner)startSessionRestoration {
if (self.numberOfSessionsBeingRestored == 0) {
[NSUserDefaults.standardUserDefaults
......@@ -509,12 +512,6 @@ static PreviousSessionInfo* gSharedInstance = nil;
--self.numberOfSessionsBeingRestored;
if (self.numberOfSessionsBeingRestored == 0) {
[self resetSessionRestorationFlag];
// Once the first patch of sessions is restored. Update the Multi-Window
// flag so it's not used again in the same run.
// TODO(crbug.com/1109280): Remove after the migration to Multi-Window
// sessions is done.
gSharedInstance.isMultiWindowEnabledSession =
base::ios::IsMultiwindowSupported();
}
}));
}
......
......@@ -645,6 +645,14 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
[self createInitialUI:(startInIncognito ? ApplicationMode::INCOGNITO
: ApplicationMode::NORMAL)];
// By reaching here, it's guaranteed that both Normal and incognito sessions
// were restored. and if it's the first time that multi-window sessions are
// created, the migration was done. Update the Multi-Window flag so it's not
// used again in the same run when creating new windows.
// TODO(crbug.com/1109280): Remove after the migration to Multi-Window
// sessions is done.
[[PreviousSessionInfo sharedInstance] updateMultiWindowSupportStatus];
if ([self shouldShowRestorePrompt]) {
[self.sceneState.appState.startupInformation
.restoreHelper showRestorePrompt];
......
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