Commit 60dc7fa7 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Move ApplicationCommands to SceneController.

Introduces a temporary interface connecting the Scene and the Main
controllers, and exposes a bunch of internals of MainController through
a MainControllerGuts protocol (obviously temporary).

Uses this interface to implement ApplicationCommands in SceneController
and updates the use of the commands endpoint to be SceneController.

Note also:
- Updates a bunch of ivar use in MainController to properties.
- Moves a Deferred Initialization constant to a shared file as it's
used in both SceneCtrl and MainCtrl. It seems like this is semantically
correct for it to be used in both places, so it probably is a permanent
change.
- Removes a DCHECK(_localStatePrefObserverBridge) in
showSettingsFromViewController, as keeping it would mean exposing MainController->_localStatePrefObserverBridge to SceneController.

Bug: None
Change-Id: Idd45bc0850eaabca068e59e3843d901c9a0c780b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845976
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709497}
parent f81687c7
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "base/ios/block_types.h" #include "base/ios/block_types.h"
// Constants for deferred initialization of preferences observer.
extern NSString* const kPrefObserverInit;
// A singleton object to run initialization code asynchronously. Blocks are // A singleton object to run initialization code asynchronously. Blocks are
// scheduled to be run after a delay. The block is named when added to the // scheduled to be run after a delay. The block is named when added to the
// singleton so that other code can force a deferred block to be run // singleton so that other code can force a deferred block to be run
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kPrefObserverInit = @"PrefObserverInit";
// An object encapsulating the deferred execution of a block of initialization // An object encapsulating the deferred execution of a block of initialization
// code. // code.
@interface DeferredInitializationBlock : NSObject @interface DeferredInitializationBlock : NSObject
......
...@@ -86,6 +86,10 @@ ...@@ -86,6 +86,10 @@
_sceneState = [[SceneState alloc] init]; _sceneState = [[SceneState alloc] init];
_sceneController = _sceneController =
[[SceneController alloc] initWithSceneState:_sceneState]; [[SceneController alloc] initWithSceneState:_sceneState];
// This is temporary plumbing that's not supposed to be here.
_sceneController.mainController = (id<MainControllerGuts>)_mainController;
_mainController.sceneController = _sceneController;
} }
} }
return self; return self;
...@@ -117,8 +121,14 @@ ...@@ -117,8 +121,14 @@
BOOL inBackground = BOOL inBackground =
[application applicationState] == UIApplicationStateBackground; [application applicationState] == UIApplicationStateBackground;
return [_appState requiresHandlingAfterLaunchWithOptions:launchOptions BOOL requiresHandling =
stateBackground:inBackground]; [_appState requiresHandlingAfterLaunchWithOptions:launchOptions
stateBackground:inBackground];
if (!IsMultiwindowSupported()) {
self.sceneState.activationLevel = SceneActivationLevelForegroundInactive;
}
return requiresHandling;
} }
- (void)applicationDidBecomeActive:(UIApplication*)application { - (void)applicationDidBecomeActive:(UIApplication*)application {
...@@ -152,10 +162,10 @@ ...@@ -152,10 +162,10 @@
self.sceneState.activationLevel = SceneActivationLevelBackground; self.sceneState.activationLevel = SceneActivationLevelBackground;
} }
[_appState [_appState applicationDidEnterBackground:application
applicationDidEnterBackground:application memoryHelper:_memoryHelper
memoryHelper:_memoryHelper incognitoContentVisible:self.sceneController
incognitoContentVisible:_mainController.incognitoContentVisible]; .incognitoContentVisible];
} }
// Called when returning to the foreground. // Called when returning to the foreground.
......
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
// //
// By design, it has no public API of its own. Anything interacting with // By design, it has no public API of its own. Anything interacting with
// MainController should be doing so through a specific protocol. // MainController should be doing so through a specific protocol.
@interface MainController : NSObject <ApplicationCommands, @interface MainController : NSObject <AppNavigation,
AppNavigation,
BrowserLauncher, BrowserLauncher,
MainControllerGuts, MainControllerGuts,
StartupInformation, StartupInformation,
...@@ -43,9 +42,8 @@ ...@@ -43,9 +42,8 @@
// to the user preferences. // to the user preferences.
@property(nonatomic, weak) MetricsMediator* metricsMediator; @property(nonatomic, weak) MetricsMediator* metricsMediator;
// Returns whether the app is showing or partially showing the // For temporary plumbing only.
// incognito panel. @property(nonatomic, weak) id<ApplicationCommands> sceneController;
@property(nonatomic, assign, readonly) BOOL incognitoContentVisible;
@end @end
......
This diff is collapsed.
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h" #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h"
@class BrowserViewController;
@class HistoryCoordinator; @class HistoryCoordinator;
@class SigninInteractionCoordinator; @class SigninInteractionCoordinator;
@class TabGridCoordinator; @class TabGridCoordinator;
......
...@@ -80,7 +80,7 @@ bool OpenNewIncognitoTabUsingUIAndEvictMainTabs() { ...@@ -80,7 +80,7 @@ bool OpenNewIncognitoTabUsingUIAndEvictMainTabs() {
bool RemoveBrowsingCacheForMainTabs() { bool RemoveBrowsingCacheForMainTabs() {
__block BOOL caches_cleared = NO; __block BOOL caches_cleared = NO;
[chrome_test_util::GetMainController() [chrome_test_util::GetMainController().sceneController
removeBrowsingDataForBrowserState:chrome_test_util:: removeBrowsingDataForBrowserState:chrome_test_util::
GetOriginalBrowserState() GetOriginalBrowserState()
timePeriod:browsing_data::TimePeriod::ALL_TIME timePeriod:browsing_data::TimePeriod::ALL_TIME
......
...@@ -18,10 +18,22 @@ source_set("scene") { ...@@ -18,10 +18,22 @@ source_set("scene") {
deps = [ deps = [
":main", ":main",
"//base", "//base",
"//ios/chrome/app:app",
"//ios/chrome/app/application_delegate:application_delegate_internal",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/browsing_data",
"//ios/chrome/browser/browsing_data",
"//ios/chrome/browser/snapshots",
"//ios/chrome/browser/tabs:tabs", "//ios/chrome/browser/tabs:tabs",
"//ios/chrome/browser/ui/browser_view",
"//ios/chrome/browser/ui/commands:commands", "//ios/chrome/browser/ui/commands:commands",
"//ios/chrome/browser/ui/history",
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/signin_interaction",
"//ios/chrome/browser/ui/tab_grid", "//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/ui/util:multiwindow_util", "//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/web_state_list",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
......
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/main/scene_state.h" #import "ios/chrome/browser/ui/main/scene_state.h"
@protocol MainControllerGuts;
// The controller object for a scene. Reacts to scene state changes. // The controller object for a scene. Reacts to scene state changes.
@interface SceneController : NSObject <SceneStateObserver> @interface SceneController : NSObject <SceneStateObserver, ApplicationCommands>
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithSceneState:(SceneState*)sceneState - (instancetype)initWithSceneState:(SceneState*)sceneState
...@@ -19,6 +22,13 @@ ...@@ -19,6 +22,13 @@
// The state of the scene controlled by this object. // The state of the scene controlled by this object.
@property(nonatomic, weak, readonly) SceneState* sceneState; @property(nonatomic, weak, readonly) SceneState* sceneState;
// Returns whether the scene is showing or partially showing the
// incognito panel.
@property(nonatomic, assign, readonly) BOOL incognitoContentVisible;
// A temporary pointer to MainController.
@property(nonatomic, weak) id<MainControllerGuts> mainController;
@end @end
#endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_H_
...@@ -79,7 +79,7 @@ void TapOnPrimarySignInButtonInRecentTabs() { ...@@ -79,7 +79,7 @@ void TapOnPrimarySignInButtonInRecentTabs() {
// Removes all browsing data. // Removes all browsing data.
void RemoveBrowsingData() { void RemoveBrowsingData() {
__block BOOL browsing_data_removed = NO; __block BOOL browsing_data_removed = NO;
[chrome_test_util::GetMainController() [chrome_test_util::GetMainController().sceneController
removeBrowsingDataForBrowserState:chrome_test_util:: removeBrowsingDataForBrowserState:chrome_test_util::
GetOriginalBrowserState() GetOriginalBrowserState()
timePeriod:browsing_data::TimePeriod::ALL_TIME timePeriod:browsing_data::TimePeriod::ALL_TIME
......
...@@ -32,7 +32,7 @@ bool ClearBrowsingData(bool off_the_record, BrowsingDataRemoveMask mask) { ...@@ -32,7 +32,7 @@ bool ClearBrowsingData(bool off_the_record, BrowsingDataRemoveMask mask) {
: chrome_test_util::GetOriginalBrowserState(); : chrome_test_util::GetOriginalBrowserState();
__block bool did_complete = false; __block bool did_complete = false;
[chrome_test_util::GetMainController() [chrome_test_util::GetMainController().sceneController
removeBrowsingDataForBrowserState:browser_state removeBrowsingDataForBrowserState:browser_state
timePeriod:browsing_data::TimePeriod::ALL_TIME timePeriod:browsing_data::TimePeriod::ALL_TIME
removeMask:mask removeMask:mask
......
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