Commit 6eb3a9dd authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Make main browser interface initialization explicit.

This CL changes the init of the main BrowserInterface in BrowserViewWrangler to be
explicit, and to be done as part of creating the main Browser instance.

BrowserViewWrangler's -mainInterface implementation is now a simple (synthesized)
getter, and thus will return nil before -createMainBrowser is called.

BrowserViewWrangler's -incognitoInterface implementation now returns nil if there's
no mainInterface.

This mitigates the risks around calling -mainInterface prior to the main browser
being created. It does slightly change the timing of BVC creation (it's slightly
earlier), but at least now it's explicit.

TEST: The crash for this bug is triggered by auth service init forcing a sign-out
of a managed account, which causes MainController's removeBrowsingDataForBrowserState:
method to be called. The completion block in that method uses mainInterface to
disable user interactions. To test this fix, I added an explicit call to SignOut()
in AuthService::Initialize() and launched Chrome with a signed-in managed account.
It crashes as expected before this fix, and works fine afterwards.

Bug: 919932
Change-Id: Iaffb29cd7d0dfb5b54f3347755fc9e15f0aa4539
Reviewed-on: https://chromium-review.googlesource.com/c/1430239
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625209}
parent 09f30ab9
......@@ -738,7 +738,10 @@ enum class EnterTabSwitcherSnapshotResult {
feature_engagement::TrackerFactory::GetForBrowserState(chromeBrowserState)
->NotifyEvent(feature_engagement::events::kChromeOpened);
// Ensure the main tab model is created.
// Make sure Roboto is available before any UI is created.
[MDCTypography setFontLoader:[MDFRobotoFontLoader sharedInstance]];
// Ensure the main tab model is created. This also creates the BVC.
[_browserViewWrangler createMainBrowser];
_spotlightManager =
......@@ -761,8 +764,6 @@ enum class EnterTabSwitcherSnapshotResult {
if (switchFromIncognito)
startInIncognito = NO;
[MDCTypography setFontLoader:[MDFRobotoFontLoader sharedInstance]];
if ([PreviousSessionInfo sharedInstance].isFirstSessionAfterLanguageChange) {
IOSChromeContentSuggestionsServiceFactory::GetForBrowserState(
chromeBrowserState)
......
......@@ -48,8 +48,10 @@ class ChromeBrowserState;
- (instancetype)init NS_UNAVAILABLE;
// Creates the main Browser used by the receiver, using the browser state
// and tab model observer it was configured with. This should be done before
// the main interface is accessed, usually immediately after initialization.
// and tab model observer it was configured with. The main interface is then
// created; until this method is called, the main and incognito interfaces will
// be nil. This should be done before the main interface is accessed, usually
// immediately after initialization.
- (void)createMainBrowser;
// Update the device sharing manager. This should be done after updates to the
......
......@@ -161,6 +161,13 @@
breakpad::MonitorURLsForTabModel(self.mainBrowser->GetTabModel());
ios::GetChromeBrowserProvider()->InitializeCastService(
self.mainBrowser->GetTabModel());
// Create the main coordinator, and thus the main interface.
_mainBrowserCoordinator = [self coordinatorForBrowser:self.mainBrowser];
[_mainBrowserCoordinator start];
DCHECK(_mainBrowserCoordinator.viewController);
_mainInterface =
[[WrangledBrowser alloc] initWithCoordinator:_mainBrowserCoordinator];
}
#pragma mark - BrowserViewInformation property implementations
......@@ -191,20 +198,9 @@
[self updateDeviceSharingManager];
}
- (id<BrowserInterface>)mainInterface {
if (!_mainInterface) {
// The backing coordinator should not have been created yet.
DCHECK(!_mainBrowserCoordinator);
_mainBrowserCoordinator = [self coordinatorForBrowser:self.mainBrowser];
[_mainBrowserCoordinator start];
DCHECK(_mainBrowserCoordinator.viewController);
_mainInterface =
[[WrangledBrowser alloc] initWithCoordinator:_mainBrowserCoordinator];
}
return _mainInterface;
}
- (id<BrowserInterface>)incognitoInterface {
if (!_mainInterface)
return nil;
if (!_incognitoInterface) {
// The backing coordinator should not have been created yet.
DCHECK(!_incognitoBrowserCoordinator);
......
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