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( ...@@ -850,15 +850,17 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
BOOL otrBVCIsCurrent = (self.currentBVC == self.otrBVC); BOOL otrBVCIsCurrent = (self.currentBVC == self.otrBVC);
TabSwitcherMode mode = GetTabSwitcherMode(); 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). // user should be in the tab switcher (the stack view).
DCHECK(mode != TabSwitcherMode::STACK || DCHECK(mode != TabSwitcherMode::STACK ||
(!otrBVCIsCurrent || _tabSwitcherIsActive)); (!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. // 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]; [_tabSwitcher setOtrTabModel:nil];
}
[_browserViewWrangler deleteIncognitoTabModelState]; [_browserViewWrangler deleteIncognitoTabModelState];
...@@ -866,10 +868,12 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -866,10 +868,12 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[self activateBVCAndMakeCurrentBVCPrimary]; [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. // 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]; [_tabSwitcher setOtrTabModel:self.otrTabModel];
}
} }
- (void)activateBVCAndMakeCurrentBVCPrimary { - (void)activateBVCAndMakeCurrentBVCPrimary {
...@@ -1265,6 +1269,15 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -1265,6 +1269,15 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// Lazy init of mainCoordinator. // Lazy init of mainCoordinator.
[self.mainCoordinator start]; [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. // Decide if the First Run UI needs to run.
BOOL firstRun = (FirstRun::IsChromeFirstRun() || BOOL firstRun = (FirstRun::IsChromeFirstRun() ||
...@@ -2536,18 +2549,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -2536,18 +2549,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// Creates and returns a tab switcher object according to the tab switcher stye. // Creates and returns a tab switcher object according to the tab switcher stye.
- (id<TabSwitcher>)newTabSwitcher { - (id<TabSwitcher>)newTabSwitcher {
switch (GetTabSwitcherMode()) { switch (GetTabSwitcherMode()) {
case TabSwitcherMode::GRID: { case TabSwitcherMode::GRID:
DCHECK(_mainCoordinator) NOTREACHED() << "When the tab grid is enabled, the tab switcher should"
<< " Main coordinator not created when tab switcher needed."; << " have been assigned during app startup.";
TabGridCoordinator* tabGridCoordinator = return nil;
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::TABLET_SWITCHER: case TabSwitcherMode::TABLET_SWITCHER:
return [[TabSwitcherController alloc] return [[TabSwitcherController alloc]
initWithBrowserState:_mainBrowserState initWithBrowserState:_mainBrowserState
......
...@@ -81,8 +81,11 @@ ...@@ -81,8 +81,11 @@
} }
- (void)setRegularTabModel:(TabModel*)regularTabModel { - (void)setRegularTabModel:(TabModel*)regularTabModel {
if (self.regularTabsMediator) {
self.regularTabsMediator.tabModel = regularTabModel; self.regularTabsMediator.tabModel = regularTabModel;
} else {
_regularTabModel = regularTabModel; _regularTabModel = regularTabModel;
}
} }
- (TabModel*)incognitoTabModel { - (TabModel*)incognitoTabModel {
...@@ -93,8 +96,11 @@ ...@@ -93,8 +96,11 @@
} }
- (void)setIncognitoTabModel:(TabModel*)incognitoTabModel { - (void)setIncognitoTabModel:(TabModel*)incognitoTabModel {
if (self.incognitoTabsMediator) {
self.incognitoTabsMediator.tabModel = incognitoTabModel; self.incognitoTabsMediator.tabModel = incognitoTabModel;
} else {
_incognitoTabModel = incognitoTabModel; _incognitoTabModel = incognitoTabModel;
}
} }
#pragma mark - MainCoordinator properties #pragma mark - MainCoordinator properties
...@@ -133,6 +139,10 @@ ...@@ -133,6 +139,10 @@
mainViewController.incognitoTabsDelegate = self.incognitoTabsMediator; mainViewController.incognitoTabsDelegate = self.incognitoTabsMediator;
mainViewController.regularTabsImageDataSource = self.regularTabsMediator; mainViewController.regularTabsImageDataSource = self.regularTabsMediator;
mainViewController.incognitoTabsImageDataSource = self.incognitoTabsMediator; 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 { - (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