Skip to content

Commit

Permalink
[iOS] Create teardownUI method for SignedInAccountsViewController
Browse files Browse the repository at this point in the history
SignedInAccountsViewController needs to be torn down and set all
services to null, during UI shutdown.
This patch needs to be cherry-picked in M115.

(cherry picked from commit 79f214a)

Fixed: 1447447
Change-Id: Ic5a408ad1cb419cde9c5742890f392e5bcd353a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4580009
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Auto-Submit: Jérôme Lebel <jlebel@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1152572}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4604748
Cr-Commit-Position: refs/branch-heads/5790@{#530}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Jérôme Lebel authored and Chromium LUCI CQ committed Jun 9, 2023
1 parent 956e650 commit 1097cd9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
Expand Up @@ -250,6 +250,9 @@ @interface SceneController () <AppStateObserver,
std::unique_ptr<WebStateListObserverBridge> _webStateListForwardingObserver;
std::unique_ptr<PolicyWatcherBrowserAgentObserverBridge>
_policyWatcherObserverBridge;
// View controller presents the signed in accounts when they have changed
// while the application was in background.
__weak SignedInAccountsViewController* _accountsViewController;
}

// Navigation View controller for the settings.
Expand Down Expand Up @@ -1167,6 +1170,9 @@ - (void)teardownUI {
return; // Nothing to do.
}

[_accountsViewController teardownUI];
_accountsViewController = nil;

// The UI should be stopped before the models they observe are stopped.
// SigninCoordinator teardown is performed by the `signinCompletion` on
// termination of async events, do not add additional teardown here.
Expand Down Expand Up @@ -2920,14 +2926,15 @@ - (void)presentSignedInAccountsViewControllerForBrowserState:
id<ApplicationSettingsCommands> settingsHandler =
HandlerForProtocol(self.mainInterface.browser->GetCommandDispatcher(),
ApplicationSettingsCommands);
UIViewController* accountsViewController =
SignedInAccountsViewController* accountsViewController =
[[SignedInAccountsViewController alloc]
initWithBrowserState:browserState
dispatcher:settingsHandler];
[[self topPresentedViewController]
presentViewController:accountsViewController
animated:YES
completion:nil];
_accountsViewController = accountsViewController;
}

// Close Settings, or Signin or the 3rd-party intents Incognito interstitial.
Expand Down
Expand Up @@ -18,6 +18,9 @@ class ChromeBrowserState;
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithStyle:(UITableViewStyle)style NS_UNAVAILABLE;

// Called when the UI will be torn down.
- (void)teardownUI;

@end

#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_SIGNED_IN_ACCOUNTS_SIGNED_IN_ACCOUNTS_TABLE_VIEW_CONTROLLER_H_
Expand Up @@ -58,6 +58,11 @@ new ChromeAccountManagerServiceObserverBridge(self,
return self;
}

- (void)teardownUI {
_accountManagerServiceObserver.reset();
_accountManagerService = nullptr;
}

#pragma mark - UIViewController

- (void)viewDidLoad {
Expand Down
Expand Up @@ -27,6 +27,9 @@ class ChromeBrowserState;

- (instancetype)initWithCoder:(NSCoder*)coder NS_UNAVAILABLE;

// Called when the UI will be torn down.
- (void)teardownUI;

@end

#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_SIGNED_IN_ACCOUNTS_SIGNED_IN_ACCOUNTS_VIEW_CONTROLLER_H_
Expand Up @@ -117,6 +117,11 @@ - (void)dealloc {
forControlEvents:UIControlEventTouchDown];
}

- (void)teardownUI {
[_accountTableView teardownUI];
_browserState = nullptr;
}

#pragma mark UIViewController

- (CGSize)preferredContentSize {
Expand Down

0 comments on commit 1097cd9

Please sign in to comment.