Commit 538764b6 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS][MW] Fixing AppState will enter foreground

UIApplicationWillEnterForeground doesn't exist with MultiWindow enabled.

To keep the same behavior in Chrome, MainApplicationDelegate needs to
listen to UISceneWillEnterForegroundNotification notifications.
When the first window goes back to foreground, the method needs be
called:
-[AppState applicationWillEnterForeground:metricsMediator:memoryHelper:
tabOpener:]

Related to crbug.com/1097080:
"AuthenticationService should not rely on foreground/background
notifications"

Fixed: 1092485, 1090748
Change-Id: Ic248fa9c88a10bb3340b1a4f32efa75b9b751491
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252103
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarNohemi Fernandez <fernandex@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781224}
parent 8afd0b71
......@@ -319,7 +319,7 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
[self initializeUI];
return;
}
if ([self isInSafeMode])
if ([self isInSafeMode] || !_applicationInBackground)
return;
_applicationInBackground = NO;
......
......@@ -708,6 +708,13 @@ TEST_F(AppStateTest, applicationWillEnterForeground) {
[[[tabOpener stub] andReturnValue:@YES]
shouldOpenNTPTabOnActivationOfBrowser:browser.get()];
// Simulate background before going to foreground.
[[getStartupInformationMock() expect] expireFirstUserActionRecorder];
swizzleMetricsMediatorDisableReporting();
[getAppStateWithMock() applicationDidEnterBackground:application
memoryHelper:memoryHelper
incognitoContentVisible:YES];
void (^swizzleBlock)() = ^{
};
......@@ -725,6 +732,7 @@ TEST_F(AppStateTest, applicationWillEnterForeground) {
// Tests.
EXPECT_OCMOCK_VERIFY(metricsMediator);
EXPECT_OCMOCK_VERIFY(memoryHelper);
EXPECT_OCMOCK_VERIFY(getStartupInformationMock());
FakeUserFeedbackProvider* user_feedback_provider =
static_cast<FakeUserFeedbackProvider*>(
ios::GetChromeBrowserProvider()->GetUserFeedbackProvider());
......
......@@ -138,6 +138,11 @@
selector:@selector(sceneDidEnterBackground:)
name:UISceneDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(sceneWillEnterForeground:)
name:UISceneWillEnterForegroundNotification
object:nil];
}
}
......@@ -250,7 +255,7 @@
- (void)sceneDidEnterBackground:(NSNotification*)notification {
DCHECK(IsSceneStartupSupported());
if (@available(iOS 13, *)) {
// When the first scene enters foreground, update the app state.
// When the last scene enters background, update the app state.
if (self.foregroundSceneCount == 0) {
[_appState applicationDidEnterBackground:UIApplication.sharedApplication
memoryHelper:_memoryHelper
......@@ -260,6 +265,19 @@
}
}
- (void)sceneWillEnterForeground:(NSNotification*)notification {
DCHECK(IsSceneStartupSupported());
if (@available(iOS 13, *)) {
// When the first scene will enter foreground, update the app state.
if (self.foregroundSceneCount == 0) {
[_appState applicationWillEnterForeground:UIApplication.sharedApplication
metricsMediator:_metricsMediator
memoryHelper:_memoryHelper
tabOpener:_tabOpener];
}
}
}
#pragma mark Downloading Data in the Background
- (void)application:(UIApplication*)application
......
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