Commit 95761677 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Remove some spurious dependencies on BVC through browserInterface

In order to remove explicit dependencies on the BVC, this CL takes the
initial step of using the |viewController| property in BrowserInterface
instead of |bvc| wherever possible. It also uses the Browser's command
dispatcher (through HandlerForProtocol or a static cast) instead of the
BVC's |dispatcher| property.

Remaining uses of the BVC property of browserInterface after this CL
are limited to (a) SceneController, and (b) BVC-specific public API,
which will be factored away in future CLs.

As related cleanup, the settings nav controller delegate property is
renamed from "dispatcherForSettings" to "handlerForSettings".

Change-Id: I1a10e7b1655f22f6559249597a6f4f467ed9ed87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124668Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754952}
parent 8a6a658d
...@@ -490,7 +490,7 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10; ...@@ -490,7 +490,7 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10;
} }
- (id<ApplicationCommands, BrowserCommands, BrowsingDataCommands>) - (id<ApplicationCommands, BrowserCommands, BrowsingDataCommands>)
dispatcherForSettings { handlerForSettings {
NOTREACHED(); NOTREACHED();
return nil; return nil;
} }
......
...@@ -35,9 +35,9 @@ class ChromeBrowserState; ...@@ -35,9 +35,9 @@ class ChromeBrowserState;
@property(nonatomic, readonly) BrowserViewController* bvc; @property(nonatomic, readonly) BrowserViewController* bvc;
// The tab model to which the current tab belongs. // The tab model to which the current tab belongs.
@property(nonatomic, readonly) TabModel* tabModel; @property(nonatomic, readonly) TabModel* tabModel;
// The active browser. // The active browser. This can never be nullptr.
@property(nonatomic, readonly) Browser* browser; @property(nonatomic, readonly) Browser* browser;
// The browser state for this interface. // The browser state for this interface. This can never be nullptr.
@property(nonatomic, readonly) ChromeBrowserState* browserState; @property(nonatomic, readonly) ChromeBrowserState* browserState;
// YES if the tab view is available for user interaction. // YES if the tab view is available for user interaction.
@property(nonatomic) BOOL userInteractionEnabled; @property(nonatomic) BOOL userInteractionEnabled;
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
- (instancetype)initWithCoordinator:(BrowserCoordinator*)coordinator { - (instancetype)initWithCoordinator:(BrowserCoordinator*)coordinator {
if (self = [super init]) { if (self = [super init]) {
DCHECK(coordinator.browser);
_coordinator = coordinator; _coordinator = coordinator;
} }
return self; return self;
...@@ -58,7 +59,7 @@ ...@@ -58,7 +59,7 @@
} }
- (TabModel*)tabModel { - (TabModel*)tabModel {
return self.coordinator.browser->GetTabModel(); return self.browser->GetTabModel();
} }
- (Browser*)browser { - (Browser*)browser {
...@@ -66,7 +67,7 @@ ...@@ -66,7 +67,7 @@
} }
- (ChromeBrowserState*)browserState { - (ChromeBrowserState*)browserState {
return self.coordinator.viewController.browserState; return self.browser->GetBrowserState();
} }
- (BOOL)userInteractionEnabled { - (BOOL)userInteractionEnabled {
......
...@@ -43,15 +43,15 @@ TEST_F(BrowserViewWranglerTest, TestInitNilObserver) { ...@@ -43,15 +43,15 @@ TEST_F(BrowserViewWranglerTest, TestInitNilObserver) {
browsingDataCommandEndpoint:nil]; browsingDataCommandEndpoint:nil];
[wrangler createMainBrowser]; [wrangler createMainBrowser];
// Test that BVC is created on demand. // Test that BVC is created on demand.
BrowserViewController* bvc = wrangler.mainInterface.bvc; UIViewController* bvc = wrangler.mainInterface.viewController;
EXPECT_NE(bvc, nil); EXPECT_NE(bvc, nil);
// Test that once created the BVC isn't re-created. // Test that once created the BVC isn't re-created.
EXPECT_EQ(bvc, wrangler.mainInterface.bvc); EXPECT_EQ(bvc, wrangler.mainInterface.viewController);
// Test that the OTR objects are (a) OTR and (b) not the same as the non-OTR // Test that the OTR objects are (a) OTR and (b) not the same as the non-OTR
// objects. // objects.
EXPECT_NE(bvc, wrangler.incognitoInterface.bvc); EXPECT_NE(bvc, wrangler.incognitoInterface.viewController);
EXPECT_NE(wrangler.mainInterface.tabModel, EXPECT_NE(wrangler.mainInterface.tabModel,
wrangler.incognitoInterface.tabModel); wrangler.incognitoInterface.tabModel);
EXPECT_TRUE(wrangler.incognitoInterface.browserState->IsOffTheRecord()); EXPECT_TRUE(wrangler.incognitoInterface.browserState->IsOffTheRecord());
......
...@@ -30,10 +30,10 @@ extern NSString* const kSettingsDoneButtonId; ...@@ -30,10 +30,10 @@ extern NSString* const kSettingsDoneButtonId;
// need to perform some clean up tasks. // need to perform some clean up tasks.
- (void)settingsWasDismissed; - (void)settingsWasDismissed;
// Asks the delegate for a dispatcher that can be passed into child view // Asks the delegate for a handler that can be passed into child view
// controllers when they are created. // controllers when they are created.
- (id<ApplicationCommands, BrowserCommands, BrowsingDataCommands>) - (id<ApplicationCommands, BrowserCommands, BrowsingDataCommands>)
dispatcherForSettings; handlerForSettings;
@end @end
......
...@@ -74,7 +74,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -74,7 +74,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
DCHECK(browser); DCHECK(browser);
SettingsTableViewController* controller = [[SettingsTableViewController alloc] SettingsTableViewController* controller = [[SettingsTableViewController alloc]
initWithBrowser:browser initWithBrowser:browser
dispatcher:[delegate dispatcherForSettings]]; dispatcher:[delegate handlerForSettings]];
SettingsNavigationController* nc = [[SettingsNavigationController alloc] SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller initWithRootViewController:controller
browser:browser browser:browser
...@@ -91,7 +91,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -91,7 +91,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AccountsTableViewController* controller = AccountsTableViewController* controller =
[[AccountsTableViewController alloc] initWithBrowser:browser [[AccountsTableViewController alloc] initWithBrowser:browser
closeSettingsOnAddAccount:YES]; closeSettingsOnAddAccount:YES];
controller.dispatcher = [delegate dispatcherForSettings]; controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc] SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller initWithRootViewController:controller
browser:browser browser:browser
...@@ -128,7 +128,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -128,7 +128,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
SyncEncryptionPassphraseTableViewController* controller = SyncEncryptionPassphraseTableViewController* controller =
[[SyncEncryptionPassphraseTableViewController alloc] [[SyncEncryptionPassphraseTableViewController alloc]
initWithBrowserState:browser->GetBrowserState()]; initWithBrowserState:browser->GetBrowserState()];
controller.dispatcher = [delegate dispatcherForSettings]; controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc] SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller initWithRootViewController:controller
browser:browser browser:browser
...@@ -145,7 +145,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -145,7 +145,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
PasswordsTableViewController* controller = PasswordsTableViewController* controller =
[[PasswordsTableViewController alloc] [[PasswordsTableViewController alloc]
initWithBrowserState:browser->GetBrowserState()]; initWithBrowserState:browser->GetBrowserState()];
controller.dispatcher = [delegate dispatcherForSettings]; controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc] SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller initWithRootViewController:controller
...@@ -225,7 +225,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -225,7 +225,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AutofillProfileTableViewController* controller = AutofillProfileTableViewController* controller =
[[AutofillProfileTableViewController alloc] [[AutofillProfileTableViewController alloc]
initWithBrowserState:browser->GetBrowserState()]; initWithBrowserState:browser->GetBrowserState()];
controller.dispatcher = [delegate dispatcherForSettings]; controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc] SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller initWithRootViewController:controller
...@@ -246,7 +246,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -246,7 +246,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
DCHECK(browser); DCHECK(browser);
AutofillCreditCardTableViewController* controller = AutofillCreditCardTableViewController* controller =
[[AutofillCreditCardTableViewController alloc] initWithBrowser:browser]; [[AutofillCreditCardTableViewController alloc] initWithBrowser:browser];
controller.dispatcher = [delegate dispatcherForSettings]; controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc] SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller initWithRootViewController:controller
...@@ -489,8 +489,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -489,8 +489,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AccountsTableViewController* controller = AccountsTableViewController* controller =
[[AccountsTableViewController alloc] initWithBrowser:self.browser [[AccountsTableViewController alloc] initWithBrowser:self.browser
closeSettingsOnAddAccount:NO]; closeSettingsOnAddAccount:NO];
controller.dispatcher = controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES]; [self pushViewController:controller animated:YES];
} }
...@@ -506,8 +505,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -506,8 +505,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
SyncEncryptionPassphraseTableViewController* controller = SyncEncryptionPassphraseTableViewController* controller =
[[SyncEncryptionPassphraseTableViewController alloc] [[SyncEncryptionPassphraseTableViewController alloc]
initWithBrowserState:self.browser->GetBrowserState()]; initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher = controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES]; [self pushViewController:controller animated:YES];
} }
...@@ -517,8 +515,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -517,8 +515,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
PasswordsTableViewController* controller = PasswordsTableViewController* controller =
[[PasswordsTableViewController alloc] [[PasswordsTableViewController alloc]
initWithBrowserState:self.browser->GetBrowserState()]; initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher = controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES]; [self pushViewController:controller animated:YES];
} }
...@@ -528,8 +525,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -528,8 +525,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AutofillProfileTableViewController* controller = AutofillProfileTableViewController* controller =
[[AutofillProfileTableViewController alloc] [[AutofillProfileTableViewController alloc]
initWithBrowserState:self.browser->GetBrowserState()]; initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher = controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES]; [self pushViewController:controller animated:YES];
} }
...@@ -539,8 +535,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -539,8 +535,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AutofillCreditCardTableViewController* controller = AutofillCreditCardTableViewController* controller =
[[AutofillCreditCardTableViewController alloc] [[AutofillCreditCardTableViewController alloc]
initWithBrowser:self.browser]; initWithBrowser:self.browser];
controller.dispatcher = controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES]; [self pushViewController:controller animated:YES];
} }
......
...@@ -87,9 +87,9 @@ ChromeBrowserState* GetCurrentIncognitoBrowserState() { ...@@ -87,9 +87,9 @@ ChromeBrowserState* GetCurrentIncognitoBrowserState() {
} }
id<BrowserCommands> BrowserCommandDispatcherForMainBVC() { id<BrowserCommands> BrowserCommandDispatcherForMainBVC() {
BrowserViewController* mainBVC = Browser* mainBrowser =
GetMainController().interfaceProvider.mainInterface.bvc; GetMainController().interfaceProvider.mainInterface.browser;
return mainBVC.dispatcher; return static_cast<id<BrowserCommands>>(mainBrowser->GetCommandDispatcher());
} }
UIViewController* GetActiveViewController() { UIViewController* GetActiveViewController() {
......
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