Commit 45f59631 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Show account selector when a scene becomes active.

Instead of using deferred initialization, show the account selector when
a scene becomes active. This means if there are multiple scenes, the
user will always have to go through this dialog even if they switch to
another window.
Also completely get rid of AppNavigation, as it's not used anymore.

Bug: 1045663
Change-Id: Idbbd19f1e188b033e39ce318def6b1338ad3ac6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2107581
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751982}
parent 900d2515
......@@ -86,7 +86,6 @@ source_set("unit_tests") {
source_set("application_delegate_internal") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"app_navigation.h",
"app_state.h",
"app_state.mm",
"browser_launcher.h",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_APP_APPLICATION_DELEGATE_APP_NAVIGATION_H_
#define IOS_CHROME_APP_APPLICATION_DELEGATE_APP_NAVIGATION_H_
#import <Foundation/Foundation.h>
#include "base/ios/block_types.h"
class ChromeBrowserState;
@class SettingsNavigationController;
// Handles the navigation through the application.
@protocol AppNavigation<NSObject>
// Presents a SignedInAccountsViewController for |browserState| on the top view
// controller.
- (void)presentSignedInAccountsViewControllerForBrowserState:
(ChromeBrowserState*)browserState;
@end
#endif // IOS_CHROME_APP_APPLICATION_DELEGATE_APP_NAVIGATION_H_
......@@ -7,7 +7,6 @@
#import <UIKit/UIKit.h>
@protocol AppNavigation;
@protocol BrowserLauncher;
@class MainApplicationDelegate;
@class MemoryWarningHelper;
......@@ -54,8 +53,7 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
// Called when the application is getting terminated. It stops all outgoing
// requests, config updates, clears the device sharing manager and stops the
// mainChrome instance.
- (void)applicationWillTerminate:(UIApplication*)application
applicationNavigation:(id<AppNavigation>)appNavigation;
- (void)applicationWillTerminate:(UIApplication*)application;
// Resumes the session: reinitializing metrics and opening new tab if necessary.
// User sessions are defined in terms of BecomeActive/ResignActive so that
......@@ -75,8 +73,7 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
- (void)applicationWillEnterForeground:(UIApplication*)application
metricsMediator:(MetricsMediator*)metricsMediator
memoryHelper:(MemoryWarningHelper*)memoryHelper
tabOpener:(id<TabOpening>)tabOpener
appNavigation:(id<AppNavigation>)appNavigation;
tabOpener:(id<TabOpening>)tabOpener;
// Sets the return value for -didFinishLaunchingWithOptions that determines if
// UIKit should make followup delegate calls such as
......
......@@ -16,7 +16,6 @@
#include "components/feature_engagement/public/event_constants.h"
#include "components/feature_engagement/public/tracker.h"
#include "components/metrics/metrics_service.h"
#import "ios/chrome/app/application_delegate/app_navigation.h"
#import "ios/chrome/app/application_delegate/browser_launcher.h"
#import "ios/chrome/app/application_delegate/memory_warning_helper.h"
#import "ios/chrome/app/application_delegate/metrics_mediator.h"
......@@ -271,8 +270,7 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
- (void)applicationWillEnterForeground:(UIApplication*)application
metricsMediator:(MetricsMediator*)metricsMediator
memoryHelper:(MemoryWarningHelper*)memoryHelper
tabOpener:(id<TabOpening>)tabOpener
appNavigation:(id<AppNavigation>)appNavigation {
tabOpener:(id<TabOpening>)tabOpener {
if ([_browserLauncher browserInitializationStage] <
INITIALIZATION_STAGE_FOREGROUND) {
// The application has been launched in background and the initialization
......@@ -311,20 +309,14 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
.interfaceProvider];
[memoryHelper resetForegroundMemoryWarningCount];
ChromeBrowserState* currentBrowserState =
_browserLauncher.interfaceProvider.currentInterface.browserState;
if ([SignedInAccountsViewController
shouldBePresentedForBrowserState:currentBrowserState]) {
[appNavigation presentSignedInAccountsViewControllerForBrowserState:
currentBrowserState];
}
// Use the mainBVC as the ContentSuggestions can only be started in non-OTR.
ChromeBrowserState* mainBrowserState =
_browserLauncher.interfaceProvider.mainInterface.browserState;
[ContentSuggestionsSchedulerNotifications notifyForeground:mainBrowserState];
// If the current browser state is not OTR, check for cookie loss.
ChromeBrowserState* currentBrowserState =
_browserLauncher.interfaceProvider.currentInterface.browserState;
if (currentBrowserState && !currentBrowserState->IsOffTheRecord() &&
currentBrowserState->GetOriginalChromeBrowserState()
->GetStatePath()
......@@ -389,8 +381,7 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
[MetricsMediator logStartupDuration:_startupInformation];
}
- (void)applicationWillTerminate:(UIApplication*)application
applicationNavigation:(id<AppNavigation>)appNavigation {
- (void)applicationWillTerminate:(UIApplication*)application {
if (_appIsTerminating) {
// Previous handling of this method spun the runloop, resulting in
// recursive calls; this does not appear to happen with the new shutdown
......
......@@ -9,7 +9,6 @@
#include "base/bind.h"
#include "base/ios/block_types.h"
#import "ios/chrome/app/app_startup_parameters.h"
#import "ios/chrome/app/application_delegate/app_navigation.h"
#import "ios/chrome/app/application_delegate/app_state_testing.h"
#import "ios/chrome/app/application_delegate/browser_launcher.h"
#import "ios/chrome/app/application_delegate/fake_startup_information.h"
......@@ -261,7 +260,6 @@ class AppStateTest : public BlockCleanupTest {
id metricsMediator = [OCMockObject mockForClass:[MetricsMediator class]];
id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]];
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
id appNavigation = [OCMockObject mockForProtocol:@protocol(AppNavigation)];
id tabModel = interface_provider_.currentInterface.tabModel;
[[metricsMediator stub] updateMetricsStateBasedOnPrefsUserTriggered:NO];
......@@ -281,8 +279,7 @@ class AppStateTest : public BlockCleanupTest {
[appState applicationWillEnterForeground:application
metricsMediator:metricsMediator
memoryHelper:memoryHelper
tabOpener:tabOpener
appNavigation:appNavigation];
tabOpener:tabOpener];
initializeIncognitoBlocker(window);
......@@ -536,8 +533,6 @@ TEST_F(AppStateWithThreadTest, willTerminate) {
browserInitializationStage];
[[[browserLauncher stub] andReturn:interfaceProvider] interfaceProvider];
id appNavigation = [OCMockObject mockForProtocol:@protocol(AppNavigation)];
id startupInformation =
[OCMockObject mockForProtocol:@protocol(StartupInformation)];
[[startupInformation expect] stopChromeMain];
......@@ -551,13 +546,11 @@ TEST_F(AppStateWithThreadTest, willTerminate) {
id application = [OCMockObject mockForClass:[UIApplication class]];
// Action.
[appState applicationWillTerminate:application
applicationNavigation:appNavigation];
[appState applicationWillTerminate:application];
// Test.
EXPECT_OCMOCK_VERIFY(browserViewController);
EXPECT_OCMOCK_VERIFY(startupInformation);
EXPECT_OCMOCK_VERIFY(appNavigation);
EXPECT_OCMOCK_VERIFY(application);
EXPECT_FALSE(interfaceProvider.mainInterface.userInteractionEnabled);
EXPECT_TRUE(interfaceProvider.deviceManagerCleaned);
......@@ -726,7 +719,6 @@ TEST_F(AppStateTest, applicationWillEnterForeground) {
id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]];
StubBrowserInterfaceProvider* interfaceProvider = getInterfaceProvider();
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
id appNavigation = [OCMockObject mockForProtocol:@protocol(AppNavigation)];
id tabModel = [OCMockObject mockForClass:[TabModel class]];
BrowserInitializationStageType stage = INITIALIZATION_STAGE_FOREGROUND;
......@@ -761,8 +753,7 @@ TEST_F(AppStateTest, applicationWillEnterForeground) {
[getAppStateWithMock() applicationWillEnterForeground:application
metricsMediator:metricsMediator
memoryHelper:memoryHelper
tabOpener:tabOpener
appNavigation:appNavigation];
tabOpener:tabOpener];
// Tests.
EXPECT_OCMOCK_VERIFY(metricsMediator);
......@@ -782,7 +773,6 @@ TEST_F(AppStateTest, applicationWillEnterForegroundFromBackground) {
id metricsMediator = [OCMockObject mockForClass:[MetricsMediator class]];
id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]];
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
id appNavigation = [OCMockObject mockForProtocol:@protocol(AppNavigation)];
BrowserInitializationStageType stage = INITIALIZATION_STAGE_BACKGROUND;
[[[getBrowserLauncherMock() stub] andReturnValue:@(stage)]
......@@ -799,8 +789,7 @@ TEST_F(AppStateTest, applicationWillEnterForegroundFromBackground) {
[getAppStateWithMock() applicationWillEnterForeground:application
metricsMediator:metricsMediator
memoryHelper:memoryHelper
tabOpener:tabOpener
appNavigation:appNavigation];
tabOpener:tabOpener];
// Tests.
EXPECT_OCMOCK_VERIFY(getBrowserLauncherMock());
......@@ -815,7 +804,6 @@ TEST_F(AppStateTest,
id metricsMediator = [OCMockObject mockForClass:[MetricsMediator class]];
id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]];
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
id appNavigation = [OCMockObject mockForProtocol:@protocol(AppNavigation)];
id window = getWindowMock();
......@@ -832,8 +820,7 @@ TEST_F(AppStateTest,
[getAppStateWithMock() applicationWillEnterForeground:application
metricsMediator:metricsMediator
memoryHelper:memoryHelper
tabOpener:tabOpener
appNavigation:appNavigation];
tabOpener:tabOpener];
// Tests.
EXPECT_OCMOCK_VERIFY(window);
......@@ -848,7 +835,6 @@ TEST_F(AppStateTest, applicationWillEnterForegroundFromForegroundSafeMode) {
id metricsMediator = [OCMockObject mockForClass:[MetricsMediator class]];
id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]];
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
id appNavigation = [OCMockObject mockForProtocol:@protocol(AppNavigation)];
BrowserInitializationStageType stage = INITIALIZATION_STAGE_FOREGROUND;
[[[getBrowserLauncherMock() stub] andReturnValue:@(stage)]
......@@ -866,8 +852,7 @@ TEST_F(AppStateTest, applicationWillEnterForegroundFromForegroundSafeMode) {
[appState applicationWillEnterForeground:application
metricsMediator:metricsMediator
memoryHelper:memoryHelper
tabOpener:tabOpener
appNavigation:appNavigation];
tabOpener:tabOpener];
}
// Tests that -applicationDidEnterBackground creates an incognito blocker.
......
......@@ -6,7 +6,6 @@
#include "base/ios/ios_util.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/app/application_delegate/app_navigation.h"
#import "ios/chrome/app/application_delegate/app_state.h"
#import "ios/chrome/app/application_delegate/browser_launcher.h"
#import "ios/chrome/app/application_delegate/memory_warning_helper.h"
......@@ -47,8 +46,6 @@
// Handles the application stage changes.
AppState* _appState;
// Handles tab switcher.
id<AppNavigation> _appNavigation;
// Handles tab switcher.
id<TabSwitching> _tabSwitcherProtocol;
}
......@@ -91,7 +88,6 @@
_mainController.sceneController = _sceneController;
_tabSwitcherProtocol = _sceneController;
_tabOpener = _sceneController;
_appNavigation = _sceneController;
}
}
return self;
......@@ -194,8 +190,7 @@
[_appState applicationWillEnterForeground:application
metricsMediator:_metricsMediator
memoryHelper:_memoryHelper
tabOpener:_tabOpener
appNavigation:_appNavigation];
tabOpener:_tabOpener];
}
- (void)applicationWillTerminate:(UIApplication*)application {
......@@ -204,8 +199,7 @@
// Instead of adding code here, consider if it could be handled by listening
// for UIApplicationWillterminate.
[_appState applicationWillTerminate:application
applicationNavigation:_appNavigation];
[_appState applicationWillTerminate:application];
}
- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application {
......@@ -241,7 +235,6 @@
_tabSwitcherProtocol = sceneController;
_tabOpener = sceneController;
_appNavigation = sceneController;
// TODO(crbug.com/1060645): This should be called later, or this flow should
// be changed completely.
......@@ -249,8 +242,7 @@
[_appState applicationWillEnterForeground:UIApplication.sharedApplication
metricsMediator:_metricsMediator
memoryHelper:_memoryHelper
tabOpener:_tabOpener
appNavigation:_appNavigation];
tabOpener:_tabOpener];
}
}
}
......
......@@ -112,7 +112,6 @@
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/appearance/appearance_customization.h"
#import "ios/chrome/browser/ui/authentication/signed_in_accounts_view_controller.h"
#import "ios/chrome/browser/ui/browser_view/browser_coordinator.h"
#import "ios/chrome/browser/ui/browser_view/browser_view_controller.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
......@@ -341,8 +340,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
- (void)scheduleMemoryDebuggingTools;
// Asynchronously kick off regular free memory checks.
- (void)startFreeMemoryMonitoring;
// Asynchronously schedules the notification of the AuthenticationService.
- (void)scheduleAuthenticationServiceNotification;
// Asynchronously schedules the reset of the failed startup attempt counter.
- (void)scheduleStartupAttemptReset;
// Asynchronously schedules the cleanup of crash reports.
......@@ -888,23 +885,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
}];
}
- (void)scheduleAuthenticationServiceNotification {
[[DeferredInitializationRunner sharedInstance]
enqueueBlockNamed:kAuthenticationServiceNotification
block:^{
// Active browser state should have been set before
// scheduling any authentication service notification.
DCHECK([self currentBrowserState]);
if ([SignedInAccountsViewController
shouldBePresentedForBrowserState:
[self currentBrowserState]]) {
[self.sceneController
presentSignedInAccountsViewControllerForBrowserState:
[self currentBrowserState]];
}
}];
}
- (void)scheduleStartupAttemptReset {
[[DeferredInitializationRunner sharedInstance]
enqueueBlockNamed:kStartupAttemptReset
......@@ -1047,7 +1027,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[self scheduleMemoryDebuggingTools];
[StartupTasks
scheduleDeferredBrowserStateInitialization:self.mainBrowserState];
[self scheduleAuthenticationServiceNotification];
[self sendQueuedFeedback];
[self scheduleSpotlightResync];
[self scheduleDeleteTempDownloadsDirectory];
......
......@@ -7,7 +7,6 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/app/application_delegate/app_navigation.h"
#import "ios/chrome/app/application_delegate/tab_opening.h"
#import "ios/chrome/app/application_delegate/tab_switching.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
......@@ -19,8 +18,7 @@
@protocol MainControllerGuts;
// The controller object for a scene. Reacts to scene state changes.
@interface SceneController : NSObject <AppNavigation,
AppURLLoadingServiceDelegate,
@interface SceneController : NSObject <AppURLLoadingServiceDelegate,
SceneStateObserver,
ApplicationCommands,
TabSwitcherDelegate,
......
......@@ -253,6 +253,19 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
if (level > SceneActivationLevelBackground && !self.hasInitializedUI) {
[self initializeUI];
}
if (level == SceneActivationLevelForegroundActive) {
[self presentSignInAccountsViewControllerIfNecessary];
}
}
- (void)presentSignInAccountsViewControllerIfNecessary {
ChromeBrowserState* browserState = self.currentInterface.browserState;
DCHECK(browserState);
if ([SignedInAccountsViewController
shouldBePresentedForBrowserState:browserState]) {
[self presentSignedInAccountsViewControllerForBrowserState:browserState];
}
}
#pragma mark - SceneControllerGuts
......@@ -1451,7 +1464,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
self.incognitoInterface)];
}
#pragma mark - AppNavigation
#pragma mark - Sign In UI presentation
- (void)presentSignedInAccountsViewControllerForBrowserState:
(ChromeBrowserState*)browserState {
......
......@@ -15,7 +15,6 @@
#import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
class ChromeBrowserState;
@class BrowserViewWrangler;
@protocol SceneControllerGuts <WebStateListObserving>
......@@ -45,13 +44,6 @@ class ChromeBrowserState;
- (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion
dismissOmnibox:(BOOL)dismissOmnibox;
#pragma mark - AppNavigation helpers
// Presents a SignedInAccountsViewController for |browserState| on the top view
// controller.
- (void)presentSignedInAccountsViewControllerForBrowserState:
(ChromeBrowserState*)browserState;
#pragma mark - iOS 12 compat
// Method called on SceneController when the scene disconnects. Exposed here for
......
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