Commit 48c7dbdf authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Fix how the tab grid is notified of OTR tab model changes.

This Cl fixes two problems that can occur when the OTR tab model is
replaced.

First, when the last incognito tab is closed, the tab grid should
have its OTR tab model set to nil so it can stop observing the OTR
web state list.

Second, MainController should set _tabSwitcher to be the TabGridAdaptor
as soon as its created, not when the tab switcher is displayed.

This CL also has the TabGridCoordinator stop keeping pointers to tab
models after it has created mediators.

Bug: 831594
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I61f674bde5d2a64645b8ccb7ed1129b6801eddcc
Reviewed-on: https://chromium-review.googlesource.com/1010288Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550543}
parent d4c1d1d6
......@@ -850,15 +850,17 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
BOOL otrBVCIsCurrent = (self.currentBVC == self.otrBVC);
TabSwitcherMode mode = GetTabSwitcherMode();
// If the stack view is in use,and the current BVC is the otr BVC, then the
// If the stack view is in use, and the current BVC is the otr BVC, then the
// user should be in the tab switcher (the stack view).
DCHECK(mode != TabSwitcherMode::STACK ||
(!otrBVCIsCurrent || _tabSwitcherIsActive));
// Always clear the OTR tab model for the tablet switcher.
// Always clear the OTR tab model for the tablet and grid switchers.
// Notify the _tabSwitcher that its otrBVC will be destroyed.
if (mode == TabSwitcherMode::TABLET_SWITCHER || _tabSwitcherIsActive)
if (mode == TabSwitcherMode::TABLET_SWITCHER ||
mode == TabSwitcherMode::GRID || _tabSwitcherIsActive) {
[_tabSwitcher setOtrTabModel:nil];
}
[_browserViewWrangler deleteIncognitoTabModelState];
......@@ -866,10 +868,12 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[self activateBVCAndMakeCurrentBVCPrimary];
}
// Always set the new otr tab model for the tablet switcher.
// Always set the new otr tab model for the tablet or grid switcher.
// Notify the _tabSwitcher with the new otrBVC.
if (mode == TabSwitcherMode::TABLET_SWITCHER || _tabSwitcherIsActive)
if (mode == TabSwitcherMode::TABLET_SWITCHER ||
mode == TabSwitcherMode::GRID || _tabSwitcherIsActive) {
[_tabSwitcher setOtrTabModel:self.otrTabModel];
}
}
- (void)activateBVCAndMakeCurrentBVCPrimary {
......@@ -1265,6 +1269,15 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// Lazy init of mainCoordinator.
[self.mainCoordinator start];
if (GetTabSwitcherMode() == TabSwitcherMode::GRID) {
TabGridCoordinator* tabGridCoordinator =
base::mac::ObjCCastStrict<TabGridCoordinator>(self.mainCoordinator);
_tabSwitcher = tabGridCoordinator.tabSwitcher;
// Call -restoreInternalState so that the grid shows the correct panel.
[_tabSwitcher restoreInternalStateWithMainTabModel:self.mainTabModel
otrTabModel:self.otrTabModel
activeTabModel:self.currentTabModel];
}
// Decide if the First Run UI needs to run.
BOOL firstRun = (FirstRun::IsChromeFirstRun() ||
......@@ -2536,18 +2549,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// Creates and returns a tab switcher object according to the tab switcher stye.
- (id<TabSwitcher>)newTabSwitcher {
switch (GetTabSwitcherMode()) {
case TabSwitcherMode::GRID: {
DCHECK(_mainCoordinator)
<< " Main coordinator not created when tab switcher needed.";
TabGridCoordinator* tabGridCoordinator =
base::mac::ObjCCastStrict<TabGridCoordinator>(self.mainCoordinator);
// Call -restoreInternalState so that the grid shows the correct panel.
[tabGridCoordinator.tabSwitcher
restoreInternalStateWithMainTabModel:self.mainTabModel
otrTabModel:self.otrTabModel
activeTabModel:self.currentTabModel];
return tabGridCoordinator.tabSwitcher;
}
case TabSwitcherMode::GRID:
NOTREACHED() << "When the tab grid is enabled, the tab switcher should"
<< " have been assigned during app startup.";
return nil;
case TabSwitcherMode::TABLET_SWITCHER:
return [[TabSwitcherController alloc]
initWithBrowserState:_mainBrowserState
......
......@@ -81,8 +81,11 @@
}
- (void)setRegularTabModel:(TabModel*)regularTabModel {
if (self.regularTabsMediator) {
self.regularTabsMediator.tabModel = regularTabModel;
} else {
_regularTabModel = regularTabModel;
}
}
- (TabModel*)incognitoTabModel {
......@@ -93,8 +96,11 @@
}
- (void)setIncognitoTabModel:(TabModel*)incognitoTabModel {
if (self.incognitoTabsMediator) {
self.incognitoTabsMediator.tabModel = incognitoTabModel;
} else {
_incognitoTabModel = incognitoTabModel;
}
}
#pragma mark - MainCoordinator properties
......@@ -133,6 +139,10 @@
mainViewController.incognitoTabsDelegate = self.incognitoTabsMediator;
mainViewController.regularTabsImageDataSource = self.regularTabsMediator;
mainViewController.incognitoTabsImageDataSource = self.incognitoTabsMediator;
// Once the mediators are set up, stop keeping pointers to the tab models used
// to initialize them.
_regularTabModel = nil;
_incognitoTabModel = nil;
}
- (void)stop {
......
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