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;
}
- (id<ApplicationCommands, BrowserCommands, BrowsingDataCommands>)
dispatcherForSettings {
handlerForSettings {
NOTREACHED();
return nil;
}
......
......@@ -35,9 +35,9 @@ class ChromeBrowserState;
@property(nonatomic, readonly) BrowserViewController* bvc;
// The tab model to which the current tab belongs.
@property(nonatomic, readonly) TabModel* tabModel;
// The active browser.
// The active browser. This can never be nullptr.
@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;
// YES if the tab view is available for user interaction.
@property(nonatomic) BOOL userInteractionEnabled;
......
......@@ -44,6 +44,7 @@
- (instancetype)initWithCoordinator:(BrowserCoordinator*)coordinator {
if (self = [super init]) {
DCHECK(coordinator.browser);
_coordinator = coordinator;
}
return self;
......@@ -58,7 +59,7 @@
}
- (TabModel*)tabModel {
return self.coordinator.browser->GetTabModel();
return self.browser->GetTabModel();
}
- (Browser*)browser {
......@@ -66,7 +67,7 @@
}
- (ChromeBrowserState*)browserState {
return self.coordinator.viewController.browserState;
return self.browser->GetBrowserState();
}
- (BOOL)userInteractionEnabled {
......
......@@ -43,15 +43,15 @@ TEST_F(BrowserViewWranglerTest, TestInitNilObserver) {
browsingDataCommandEndpoint:nil];
[wrangler createMainBrowser];
// Test that BVC is created on demand.
BrowserViewController* bvc = wrangler.mainInterface.bvc;
UIViewController* bvc = wrangler.mainInterface.viewController;
EXPECT_NE(bvc, nil);
// 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
// objects.
EXPECT_NE(bvc, wrangler.incognitoInterface.bvc);
EXPECT_NE(bvc, wrangler.incognitoInterface.viewController);
EXPECT_NE(wrangler.mainInterface.tabModel,
wrangler.incognitoInterface.tabModel);
EXPECT_TRUE(wrangler.incognitoInterface.browserState->IsOffTheRecord());
......
......@@ -30,10 +30,10 @@ extern NSString* const kSettingsDoneButtonId;
// need to perform some clean up tasks.
- (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.
- (id<ApplicationCommands, BrowserCommands, BrowsingDataCommands>)
dispatcherForSettings;
handlerForSettings;
@end
......
......@@ -74,7 +74,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
DCHECK(browser);
SettingsTableViewController* controller = [[SettingsTableViewController alloc]
initWithBrowser:browser
dispatcher:[delegate dispatcherForSettings]];
dispatcher:[delegate handlerForSettings]];
SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller
browser:browser
......@@ -91,7 +91,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AccountsTableViewController* controller =
[[AccountsTableViewController alloc] initWithBrowser:browser
closeSettingsOnAddAccount:YES];
controller.dispatcher = [delegate dispatcherForSettings];
controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller
browser:browser
......@@ -128,7 +128,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
SyncEncryptionPassphraseTableViewController* controller =
[[SyncEncryptionPassphraseTableViewController alloc]
initWithBrowserState:browser->GetBrowserState()];
controller.dispatcher = [delegate dispatcherForSettings];
controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller
browser:browser
......@@ -145,7 +145,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
PasswordsTableViewController* controller =
[[PasswordsTableViewController alloc]
initWithBrowserState:browser->GetBrowserState()];
controller.dispatcher = [delegate dispatcherForSettings];
controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller
......@@ -225,7 +225,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AutofillProfileTableViewController* controller =
[[AutofillProfileTableViewController alloc]
initWithBrowserState:browser->GetBrowserState()];
controller.dispatcher = [delegate dispatcherForSettings];
controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller
......@@ -246,7 +246,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
DCHECK(browser);
AutofillCreditCardTableViewController* controller =
[[AutofillCreditCardTableViewController alloc] initWithBrowser:browser];
controller.dispatcher = [delegate dispatcherForSettings];
controller.dispatcher = [delegate handlerForSettings];
SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller
......@@ -489,8 +489,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AccountsTableViewController* controller =
[[AccountsTableViewController alloc] initWithBrowser:self.browser
closeSettingsOnAddAccount:NO];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self pushViewController:controller animated:YES];
}
......@@ -506,8 +505,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
SyncEncryptionPassphraseTableViewController* controller =
[[SyncEncryptionPassphraseTableViewController alloc]
initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self pushViewController:controller animated:YES];
}
......@@ -517,8 +515,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
PasswordsTableViewController* controller =
[[PasswordsTableViewController alloc]
initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self pushViewController:controller animated:YES];
}
......@@ -528,8 +525,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AutofillProfileTableViewController* controller =
[[AutofillProfileTableViewController alloc]
initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self pushViewController:controller animated:YES];
}
......@@ -539,8 +535,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
AutofillCreditCardTableViewController* controller =
[[AutofillCreditCardTableViewController alloc]
initWithBrowser:self.browser];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
controller.dispatcher = [self.settingsNavigationDelegate handlerForSettings];
[self pushViewController:controller animated:YES];
}
......
......@@ -87,9 +87,9 @@ ChromeBrowserState* GetCurrentIncognitoBrowserState() {
}
id<BrowserCommands> BrowserCommandDispatcherForMainBVC() {
BrowserViewController* mainBVC =
GetMainController().interfaceProvider.mainInterface.bvc;
return mainBVC.dispatcher;
Browser* mainBrowser =
GetMainController().interfaceProvider.mainInterface.browser;
return static_cast<id<BrowserCommands>>(mainBrowser->GetCommandDispatcher());
}
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