Commit d2a03d7a authored by edchin's avatar edchin Committed by Commit Bot

[ios] Refactor BrowserViewInformation

This CL inverts the relationship between |currentBVC| and |currentBrowserCoordinator|.
This CL makes |currentBrowserCoordinator| the source of truth, and |currentBVC| simply
returns the corresponding BVC.

Change-Id: Ibdcb79ca3f6fb2f3c2d8cecae1be036c58962dae
Reviewed-on: https://chromium-review.googlesource.com/c/1355995Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613140}
parent 1b4dd201
...@@ -399,6 +399,10 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -399,6 +399,10 @@ enum class ShowTabSwitcherSnapshotResult {
StartupTasks* _startupTasks; StartupTasks* _startupTasks;
} }
// Redefined from BrowserViewInformation.
@property(nonatomic, weak, readwrite)
BrowserCoordinator* currentBrowserCoordinator;
// The main coordinator, lazily created the first time it is accessed. Manages // The main coordinator, lazily created the first time it is accessed. Manages
// the main view controller. This property should not be accessed before the // the main view controller. This property should not be accessed before the
// browser has started up to the FOREGROUND stage. // browser has started up to the FOREGROUND stage.
...@@ -1293,10 +1297,10 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -1293,10 +1297,10 @@ enum class ShowTabSwitcherSnapshotResult {
TabModel* tabModel; TabModel* tabModel;
if (launchMode == ApplicationMode::INCOGNITO) { if (launchMode == ApplicationMode::INCOGNITO) {
tabModel = otrTabModel; tabModel = otrTabModel;
self.currentBVC = self.otrBVC; self.currentBrowserCoordinator = self.incognitoBrowserCoordinator;
} else { } else {
tabModel = mainTabModel; tabModel = mainTabModel;
self.currentBVC = self.mainBVC; self.currentBrowserCoordinator = self.mainBrowserCoordinator;
} }
if (_tabSwitcherIsActive) { if (_tabSwitcherIsActive) {
DCHECK(!_dismissingTabSwitcher); DCHECK(!_dismissingTabSwitcher);
...@@ -1498,13 +1502,16 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -1498,13 +1502,16 @@ enum class ShowTabSwitcherSnapshotResult {
transition:ui::PAGE_TRANSITION_TYPED transition:ui::PAGE_TRANSITION_TYPED
completion:nil]; completion:nil];
} else { } else {
[self dismissModalDialogsWithCompletion:^{ [self
self.currentBVC = [command inIncognito] ? self.otrBVC : self.mainBVC; dismissModalDialogsWithCompletion:^{
DCHECK(self.currentBVC.browserState->IsOffTheRecord() == self.currentBrowserCoordinator =
command.inIncognito); [command inIncognito] ? self.incognitoBrowserCoordinator
[self.currentBVC webPageOrderedOpen:command]; : self.mainBrowserCoordinator;
} DCHECK(self.currentBVC.browserState->IsOffTheRecord() ==
dismissOmnibox:YES]; command.inIncognito);
[self.currentBVC webPageOrderedOpen:command];
}
dismissOmnibox:YES];
} }
} else { } else {
...@@ -1799,17 +1806,28 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -1799,17 +1806,28 @@ enum class ShowTabSwitcherSnapshotResult {
return [_browserViewWrangler currentBVC]; return [_browserViewWrangler currentBVC];
} }
// Note that the current tab of |bvc| will normally be reloaded by this method. - (BrowserCoordinator*)mainBrowserCoordinator {
// If a new tab is about to be added, call expectNewForegroundTab on the BVC DCHECK(_browserViewWrangler);
// first to avoid extra work and possible page load side-effects for the tab return _browserViewWrangler.mainBrowserCoordinator;
// being replaced. }
- (void)setCurrentBVC:(BrowserViewController*)bvc {
DCHECK(bvc != nil); - (BrowserCoordinator*)incognitoBrowserCoordinator {
if (self.currentBVC == bvc) DCHECK(_browserViewWrangler);
return _browserViewWrangler.incognitoBrowserCoordinator;
}
// Note that the current tab of |browserCoordinator|'s BVC will normally be
// reloaded by this method. If a new tab is about to be added, call
// expectNewForegroundTab on the BVC first to avoid extra work and possible page
// load side-effects for the tab being replaced.
- (void)setCurrentBrowserCoordinator:(BrowserCoordinator*)browserCoordinator {
DCHECK(browserCoordinator);
if (self.currentBrowserCoordinator == browserCoordinator)
return; return;
DCHECK(_browserViewWrangler); DCHECK(_browserViewWrangler);
[_browserViewWrangler setCurrentBVC:bvc storageSwitcher:self]; [_browserViewWrangler setCurrentBrowserCoordinator:browserCoordinator
storageSwitcher:self];
if (!_dismissingTabSwitcher) if (!_dismissingTabSwitcher)
[self displayCurrentBVCAndFocusOmnibox:NO]; [self displayCurrentBVCAndFocusOmnibox:NO];
...@@ -1856,7 +1874,7 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -1856,7 +1874,7 @@ enum class ShowTabSwitcherSnapshotResult {
if ([self.currentTabModel count] == 0U) { if ([self.currentTabModel count] == 0U) {
[self showTabSwitcher]; [self showTabSwitcher];
} else { } else {
self.currentBVC = self.mainBVC; self.currentBrowserCoordinator = self.mainBrowserCoordinator;
} }
} }
...@@ -1877,10 +1895,12 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -1877,10 +1895,12 @@ enum class ShowTabSwitcherSnapshotResult {
#pragma mark - Mode Switching #pragma mark - Mode Switching
- (void)switchModesAndOpenNewTab:(OpenNewTabCommand*)command { - (void)switchModesAndOpenNewTab:(OpenNewTabCommand*)command {
BrowserViewController* bvc = command.inIncognito ? self.otrBVC : self.mainBVC; BrowserCoordinator* browserCoordinator =
DCHECK(bvc); command.inIncognito ? self.incognitoBrowserCoordinator
[bvc expectNewForegroundTab]; : self.mainBrowserCoordinator;
self.currentBVC = bvc; DCHECK(browserCoordinator);
[browserCoordinator.viewController expectNewForegroundTab];
self.currentBrowserCoordinator = browserCoordinator;
[self openURLInNewTab:command]; [self openURLInNewTab:command];
} }
...@@ -2103,9 +2123,10 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -2103,9 +2123,10 @@ enum class ShowTabSwitcherSnapshotResult {
DCHECK(tabModel == self.mainTabModel || tabModel == self.otrTabModel); DCHECK(tabModel == self.mainTabModel || tabModel == self.otrTabModel);
_dismissingTabSwitcher = YES; _dismissingTabSwitcher = YES;
BrowserViewController* targetBVC = BrowserCoordinator* targetBrowserCoordinator =
(tabModel == self.mainTabModel) ? self.mainBVC : self.otrBVC; (tabModel == self.mainTabModel) ? self.mainBrowserCoordinator
self.currentBVC = targetBVC; : self.incognitoBrowserCoordinator;
self.currentBrowserCoordinator = targetBrowserCoordinator;
// The call to set currentBVC above does not actually display the BVC, because // The call to set currentBVC above does not actually display the BVC, because
// _dismissingTabSwitcher is YES. So: Force the BVC transition to start. // _dismissingTabSwitcher is YES. So: Force the BVC transition to start.
...@@ -2120,10 +2141,10 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -2120,10 +2141,10 @@ enum class ShowTabSwitcherSnapshotResult {
if (_modeToDisplayOnTabSwitcherDismissal == if (_modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::NORMAL) { TabSwitcherDismissalMode::NORMAL) {
self.currentBVC = self.mainBVC; self.currentBrowserCoordinator = self.mainBrowserCoordinator;
} else if (_modeToDisplayOnTabSwitcherDismissal == } else if (_modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::INCOGNITO) { TabSwitcherDismissalMode::INCOGNITO) {
self.currentBVC = self.otrBVC; self.currentBrowserCoordinator = self.incognitoBrowserCoordinator;
} }
_modeToDisplayOnTabSwitcherDismissal = TabSwitcherDismissalMode::NONE; _modeToDisplayOnTabSwitcherDismissal = TabSwitcherDismissalMode::NONE;
...@@ -2315,8 +2336,9 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -2315,8 +2336,9 @@ enum class ShowTabSwitcherSnapshotResult {
withURL:(const GURL&)url withURL:(const GURL&)url
transition:(ui::PageTransition)transition transition:(ui::PageTransition)transition
completion:(ProceduralBlock)completion { completion:(ProceduralBlock)completion {
BrowserViewController* targetBVC = BrowserCoordinator* targetBrowserCoordinator =
targetMode == ApplicationMode::NORMAL ? self.mainBVC : self.otrBVC; targetMode == ApplicationMode::NORMAL ? self.mainBrowserCoordinator
: self.incognitoBrowserCoordinator;
NSUInteger tabIndex = NSNotFound; NSUInteger tabIndex = NSNotFound;
ProceduralBlock startupCompletion = ProceduralBlock startupCompletion =
...@@ -2349,26 +2371,29 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -2349,26 +2371,29 @@ enum class ShowTabSwitcherSnapshotResult {
targetMode == ApplicationMode::NORMAL targetMode == ApplicationMode::NORMAL
? TabSwitcherDismissalMode::NORMAL ? TabSwitcherDismissalMode::NORMAL
: TabSwitcherDismissalMode::INCOGNITO; : TabSwitcherDismissalMode::INCOGNITO;
[targetBVC appendTabAddedCompletion:tabOpenedCompletion]; [targetBrowserCoordinator.viewController
tab = [targetBVC addSelectedTabWithURL:url appendTabAddedCompletion:tabOpenedCompletion];
atIndex:tabIndex tab = [targetBrowserCoordinator.viewController
transition:transition]; addSelectedTabWithURL:url
atIndex:tabIndex
transition:transition];
} else { } else {
// Voice search, QRScanner and the omnibox are presented by the BVC. // Voice search, QRScanner and the omnibox are presented by the BVC.
// They must be started after the BVC view is added in the hierarchy. // They must be started after the BVC view is added in the hierarchy.
self.NTPActionAfterTabSwitcherDismissal = self.NTPActionAfterTabSwitcherDismissal =
[_startupParameters postOpeningAction]; [_startupParameters postOpeningAction];
[self setStartupParameters:nil]; [self setStartupParameters:nil];
tab = [_tabSwitcher dismissWithNewTabAnimationToModel:targetBVC.tabModel tab = [_tabSwitcher
withURL:url dismissWithNewTabAnimationToModel:targetBrowserCoordinator.tabModel
atIndex:tabIndex withURL:url
transition:transition]; atIndex:tabIndex
transition:transition];
} }
} else { } else {
if (!self.currentBVC.presentedViewController) { if (!self.currentBVC.presentedViewController) {
[targetBVC expectNewForegroundTab]; [targetBrowserCoordinator.viewController expectNewForegroundTab];
} }
self.currentBVC = targetBVC; self.currentBrowserCoordinator = targetBrowserCoordinator;
tab = [self openOrReuseTabInMode:targetMode tab = [self openOrReuseTabInMode:targetMode
withURL:url withURL:url
transition:transition transition:transition
......
...@@ -18,19 +18,27 @@ class ChromeBrowserState; ...@@ -18,19 +18,27 @@ class ChromeBrowserState;
// Information about the Browser View, controllers and tab model. // Information about the Browser View, controllers and tab model.
@protocol BrowserViewInformation<NSObject> @protocol BrowserViewInformation<NSObject>
// The normal (non-OTR) BrowserViewController // The normal (non-incognito, non-OTR) BrowserCoordinator.
@property(nonatomic, strong, readonly)
BrowserCoordinator* mainBrowserCoordinator;
// The incognito (a.k.a OTR) BrowserCoordinator.
@property(nonatomic, strong, readonly)
BrowserCoordinator* incognitoBrowserCoordinator;
// The BrowserCoordinator that is currently being used (one of mainBVC or
// otrBVC). The other, if present, is in suspended mode..
@property(nonatomic, weak, readonly)
BrowserCoordinator* currentBrowserCoordinator;
// The BrowserViewController corresponding to |mainBrowserCoordinator|.
@property(nonatomic, readonly) BrowserViewController* mainBVC; @property(nonatomic, readonly) BrowserViewController* mainBVC;
// The normal (non-OTR) TabModel corresponding to mainBVC. // The normal (non-OTR) TabModel corresponding to |mainBrowserCoordinator|.
@property(nonatomic, retain) TabModel* mainTabModel; @property(nonatomic, retain) TabModel* mainTabModel;
// The OTR BrowserViewController. // The BrowserViewController corresponding to |incognitoBrowserCoordinator|.
@property(nonatomic, readonly) BrowserViewController* otrBVC; @property(nonatomic, readonly) BrowserViewController* otrBVC;
// The OTR TabModel corresponding to otrBVC. // The OTR TabModel corresponding to |incognitoBrowserCoordinator|.
@property(nonatomic, retain) TabModel* otrTabModel; @property(nonatomic, retain) TabModel* otrTabModel;
// The BrowserViewController that is currently being used (one of mainBVC or // The BrowserViewController corresponding to |currentBrowserCoordinator|.
// otrBVC). The other, if present, is in suspended mode. @property(nonatomic, readonly) BrowserViewController* currentBVC;
@property(nonatomic, weak) BrowserViewController* currentBVC;
// The BrowserCoordinator corresponding to |currentBVC|.
@property(nonatomic, readonly) BrowserCoordinator* currentBrowserCoordinator;
// Halts all tabs from all TabModels. // Halts all tabs from all TabModels.
- (void)haltAllTabs; - (void)haltAllTabs;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "ios/chrome/browser/ui/main/browser_view_information.h" #import "ios/chrome/browser/ui/main/browser_view_information.h"
@protocol ApplicationCommands; @protocol ApplicationCommands;
@class BrowserCoordinator;
@class DeviceSharingManager; @class DeviceSharingManager;
@protocol TabModelObserver; @protocol TabModelObserver;
...@@ -42,16 +43,14 @@ class ChromeBrowserState; ...@@ -42,16 +43,14 @@ class ChromeBrowserState;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
// Set the current BVC to be |bvc|, and use |storageSwitcher| to handle the // Set the current BrowserCoordinator to be |browserCoordinator|, and use
// storage switch. |bvc| should be one of the view controller instances already // |storageSwitcher| to handle the storage switch. |browserCoordinator| should
// owned by the receiver (either |mainBVC| or |otrBVBC|), and this method does // be one of the BrowserCoordinator instances already owned by the receiver
// not retain or take ownership of |bvc|. // (either |mainBrowserCoordinator| or |incognitoBrowserCoordinator|), and this
// Note that the BrowserViewInformation protocol defines // method does not retain or take ownership of |browserCoordinator|.
// |currentBVC| as a readwrite property, so users of this class can directly - (void)setCurrentBrowserCoordinator:(BrowserCoordinator*)browserCoordinator
// call -setCurrentBVC: and bypass the logic in this method; that should only be storageSwitcher:
// done on BVC instances who do not yet have a browser state. (id<BrowserStateStorageSwitching>)storageSwitcher;
- (void)setCurrentBVC:(BrowserViewController*)bvc
storageSwitcher:(id<BrowserStateStorageSwitching>)storageSwitcher;
// Update the device sharing manager. This should be done after updates to the // Update the device sharing manager. This should be done after updates to the
// tab model. This class creates and manages the state of the sharing manager. // tab model. This class creates and manages the state of the sharing manager.
......
...@@ -33,12 +33,6 @@ ...@@ -33,12 +33,6 @@
BOOL _isShutdown; BOOL _isShutdown;
} }
// Coordinator for non-incognito BVC.
@property(nonatomic, strong) BrowserCoordinator* mainCoordinator;
// Coordinator for incognito BVC.
@property(nonatomic, strong) BrowserCoordinator* incognitoCoordinator;
// Responsible for maintaining all state related to sharing to other devices. // Responsible for maintaining all state related to sharing to other devices.
// Redeclared readwrite from the readonly declaration in the Testing interface. // Redeclared readwrite from the readonly declaration in the Testing interface.
@property(nonatomic, strong, readwrite) @property(nonatomic, strong, readwrite)
...@@ -65,12 +59,12 @@ ...@@ -65,12 +59,12 @@
@implementation BrowserViewWrangler @implementation BrowserViewWrangler
// Properties defined in the BrowserViewInformation protocol. // Properties defined in the BrowserViewInformation protocol.
@synthesize mainBrowserCoordinator = _mainBrowserCoordinator;
@synthesize incognitoBrowserCoordinator = _incognitoBrowserCoordinator;
@synthesize currentBrowserCoordinator = _currentBrowserCoordinator;
@synthesize mainTabModel = _mainTabModel; @synthesize mainTabModel = _mainTabModel;
@synthesize otrTabModel = _otrTabModel; @synthesize otrTabModel = _otrTabModel;
@synthesize currentBVC = _currentBVC;
// Private properies. // Private properies.
@synthesize mainCoordinator = _mainCoordinator;
@synthesize incognitoCoordinator = _incognitoCoordinator;
@synthesize deviceSharingManager = _deviceSharingManager; @synthesize deviceSharingManager = _deviceSharingManager;
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
...@@ -91,17 +85,20 @@ ...@@ -91,17 +85,20 @@
#pragma mark - BrowserViewInformation property implementations #pragma mark - BrowserViewInformation property implementations
- (BrowserViewController*)mainBVC { - (BrowserCoordinator*)mainBrowserCoordinator {
if (!self.mainCoordinator.viewController) { if (!_mainBrowserCoordinator) {
// |_browserState| should always be set before trying to create _mainBrowserCoordinator =
// |mainBVC|. [self coordinatorForBrowserState:_browserState
DCHECK(_browserState); tabModel:self.mainTabModel];
self.mainCoordinator = [self coordinatorForBrowserState:_browserState [_mainBrowserCoordinator start];
tabModel:self.mainTabModel]; DCHECK(_mainBrowserCoordinator.viewController);
[self.mainCoordinator start];
DCHECK(self.mainCoordinator.viewController);
} }
return self.mainCoordinator.viewController; return _mainBrowserCoordinator;
}
- (BrowserViewController*)mainBVC {
DCHECK(self.mainBrowserCoordinator.viewController);
return self.mainBrowserCoordinator.viewController;
} }
- (TabModel*)mainTabModel { - (TabModel*)mainTabModel {
...@@ -132,21 +129,23 @@ ...@@ -132,21 +129,23 @@
_mainTabModel = mainTabModel; _mainTabModel = mainTabModel;
} }
- (BrowserViewController*)otrBVC { - (BrowserCoordinator*)incognitoBrowserCoordinator {
if (!self.incognitoCoordinator.viewController) { if (!_incognitoBrowserCoordinator) {
// |_browserState| should always be set before trying to create
// |otrBVC|.
DCHECK(_browserState);
ios::ChromeBrowserState* otrBrowserState = ios::ChromeBrowserState* otrBrowserState =
_browserState->GetOffTheRecordChromeBrowserState(); _browserState->GetOffTheRecordChromeBrowserState();
DCHECK(otrBrowserState); DCHECK(otrBrowserState);
self.incognitoCoordinator = _incognitoBrowserCoordinator =
[self coordinatorForBrowserState:otrBrowserState [self coordinatorForBrowserState:otrBrowserState
tabModel:self.otrTabModel]; tabModel:self.otrTabModel];
[self.incognitoCoordinator start]; [_incognitoBrowserCoordinator start];
DCHECK(self.incognitoCoordinator.viewController); DCHECK(_incognitoBrowserCoordinator.viewController);
} }
return self.incognitoCoordinator.viewController; return _incognitoBrowserCoordinator;
}
- (BrowserViewController*)otrBVC {
DCHECK(self.incognitoBrowserCoordinator.viewController);
return self.incognitoBrowserCoordinator.viewController;
} }
- (TabModel*)otrTabModel { - (TabModel*)otrTabModel {
...@@ -172,46 +171,48 @@ ...@@ -172,46 +171,48 @@
_otrTabModel = otrTabModel; _otrTabModel = otrTabModel;
} }
- (void)setCurrentBVC:(BrowserViewController*)bvc - (void)setCurrentBrowserCoordinator:(BrowserCoordinator*)browserCoordinator
storageSwitcher:(id<BrowserStateStorageSwitching>)storageSwitcher { storageSwitcher:
DCHECK(bvc != nil); (id<BrowserStateStorageSwitching>)storageSwitcher {
// |bvc| should be one of the BrowserViewControllers this class already owns. DCHECK(browserCoordinator);
DCHECK(self.mainBVC == bvc || self.otrBVC == bvc); // |browserCoordinator| should be one of the BrowserCoordinators this class
if (self.currentBVC == bvc) { // already owns.
DCHECK(self.mainBrowserCoordinator == browserCoordinator ||
self.incognitoBrowserCoordinator == browserCoordinator);
if (self.currentBrowserCoordinator == browserCoordinator) {
return; return;
} }
if (self.currentBVC) { if (self.currentBrowserCoordinator) {
// Tell the current BVC it moved to the background. // Tell the current BVC it moved to the background.
[self.currentBVC setPrimary:NO]; [self.currentBrowserCoordinator.viewController setPrimary:NO];
// Data storage for the browser is always owned by the current BVC, so it // Data storage for the browser is always owned by the current BVC, so it
// must be updated when switching between BVCs. // must be updated when switching between BVCs.
[storageSwitcher changeStorageFromBrowserState:self.currentBVC.browserState [storageSwitcher
toBrowserState:bvc.browserState]; changeStorageFromBrowserState:self.currentBrowserCoordinator
.browserState
toBrowserState:browserCoordinator.browserState];
} }
self.currentBVC = bvc; _currentBrowserCoordinator = browserCoordinator;
// The internal state of the Handoff Manager depends on the current BVC. // The internal state of the Handoff Manager depends on the current BVC.
[self updateDeviceSharingManager]; [self updateDeviceSharingManager];
} }
- (BrowserCoordinator*)currentBrowserCoordinator { - (BrowserViewController*)currentBVC {
if (self.currentBVC == self.otrBVC) { return self.currentBrowserCoordinator.viewController;
return self.incognitoCoordinator;
}
return self.mainCoordinator;
} }
#pragma mark - BrowserViewInformation methods #pragma mark - BrowserViewInformation methods
- (TabModel*)currentTabModel { - (TabModel*)currentTabModel {
return self.currentBVC.tabModel; return self.currentBrowserCoordinator.tabModel;
} }
- (ios::ChromeBrowserState*)currentBrowserState { - (ios::ChromeBrowserState*)currentBrowserState {
return self.currentBVC.browserState; return self.currentBrowserCoordinator.browserState;
} }
- (void)haltAllTabs { - (void)haltAllTabs {
...@@ -245,9 +246,10 @@ ...@@ -245,9 +246,10 @@
[self.deviceSharingManager updateBrowserState:_browserState]; [self.deviceSharingManager updateBrowserState:_browserState];
GURL activeURL; GURL activeURL;
Tab* currentTab = [self.currentBVC tabModel].currentTab; Tab* currentTab = self.currentBrowserCoordinator.tabModel.currentTab;
// Set the active URL if there's a current tab and the current BVC is not OTR. // Set the active URL if there's a current tab and the current BVC is not OTR.
if (currentTab.webState && self.currentBVC != self.otrBVC) { if (currentTab.webState &&
self.currentBrowserCoordinator != self.incognitoBrowserCoordinator) {
activeURL = currentTab.webState->GetVisibleURL(); activeURL = currentTab.webState->GetVisibleURL();
} }
[self.deviceSharingManager updateActiveURL:activeURL]; [self.deviceSharingManager updateActiveURL:activeURL];
...@@ -263,19 +265,21 @@ ...@@ -263,19 +265,21 @@
// Stop watching the OTR tab model's state for crashes. // Stop watching the OTR tab model's state for crashes.
breakpad::StopMonitoringTabStateForTabModel(self.otrTabModel); breakpad::StopMonitoringTabStateForTabModel(self.otrTabModel);
// At this stage, a new OTR BVC shouldn't be lazily constructed by calling the // At this stage, a new incognitoBrowserCoordinator shouldn't be lazily
// .otrBVC property getter. // constructed by calling the property getter.
BOOL otrBVCIsCurrent = BOOL otrBVCIsCurrent =
self.currentBVC == self.incognitoCoordinator.viewController; self.currentBrowserCoordinator == _incognitoBrowserCoordinator;
@autoreleasepool { @autoreleasepool {
[self.incognitoCoordinator stop]; // At this stage, a new incognitoBrowserCoordinator shouldn't be lazily
self.incognitoCoordinator = nil; // constructed by calling the property getter.
[_incognitoBrowserCoordinator stop];
_incognitoBrowserCoordinator = nil;
// There's no guarantee the tab model was ever added to the BVC (or even // There's no guarantee the tab model was ever added to the BVC (or even
// that the BVC was created), so ensure the tab model gets notified. // that the BVC was created), so ensure the tab model gets notified.
self.otrTabModel = nil; self.otrTabModel = nil;
if (otrBVCIsCurrent) { if (otrBVCIsCurrent) {
_currentBVC = nil; _currentBrowserCoordinator = nil;
} }
} }
...@@ -290,7 +294,7 @@ ...@@ -290,7 +294,7 @@
DCHECK(_browserState->HasOffTheRecordChromeBrowserState()); DCHECK(_browserState->HasOffTheRecordChromeBrowserState());
if (otrBVCIsCurrent) { if (otrBVCIsCurrent) {
_currentBVC = self.otrBVC; _currentBrowserCoordinator = self.incognitoBrowserCoordinator;
} }
} }
...@@ -322,10 +326,12 @@ ...@@ -322,10 +326,12 @@
[_mainTabModel browserStateDestroyed]; [_mainTabModel browserStateDestroyed];
[_otrTabModel browserStateDestroyed]; [_otrTabModel browserStateDestroyed];
[self.mainCoordinator stop]; // At this stage, new BrowserCoordinators shouldn't be lazily constructed by
self.mainCoordinator = nil; // calling their property getters.
[self.incognitoCoordinator stop]; [_mainBrowserCoordinator stop];
self.incognitoCoordinator = nil; _mainBrowserCoordinator = nil;
[_incognitoBrowserCoordinator stop];
_incognitoBrowserCoordinator = nil;
_browserState = nullptr; _browserState = nullptr;
} }
......
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