| Index: ios/chrome/browser/ui/authentication/signin_interaction_controller.mm
|
| diff --git a/ios/chrome/browser/ui/authentication/signin_interaction_controller.mm b/ios/chrome/browser/ui/authentication/signin_interaction_controller.mm
|
| index 1f693f817abf71fb9e411a7811ed9a8ef4add697..797f5683619bd5724b923652895aa450ada9a3e3 100644
|
| --- a/ios/chrome/browser/ui/authentication/signin_interaction_controller.mm
|
| +++ b/ios/chrome/browser/ui/authentication/signin_interaction_controller.mm
|
| @@ -4,10 +4,7 @@
|
|
|
| #import "ios/chrome/browser/ui/authentication/signin_interaction_controller.h"
|
|
|
| -#include "base/ios/weak_nsobject.h"
|
| #include "base/logging.h"
|
| -#include "base/mac/scoped_block.h"
|
| -#include "base/mac/scoped_nsobject.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "components/prefs/pref_service.h"
|
| #include "components/signin/core/browser/signin_manager.h"
|
| @@ -27,6 +24,10 @@
|
| #import "ios/public/provider/chrome/browser/signin/chrome_identity_interaction_manager.h"
|
| #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h"
|
|
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| using signin_ui::CompletionCallback;
|
|
|
| @interface SigninInteractionController ()<
|
| @@ -35,17 +36,16 @@ using signin_ui::CompletionCallback;
|
| ios::ChromeBrowserState* browserState_;
|
| signin_metrics::AccessPoint accessPoint_;
|
| signin_metrics::PromoAction promoAction_;
|
| - base::scoped_nsobject<UIViewController> presentingViewController_;
|
| + UIViewController* presentingViewController_;
|
| BOOL isPresentedOnSettings_;
|
| BOOL isCancelling_;
|
| BOOL isDismissing_;
|
| BOOL interactionManagerDismissalIgnored_;
|
| - base::scoped_nsobject<AlertCoordinator> alertCoordinator_;
|
| - base::mac::ScopedBlock<CompletionCallback> completionCallback_;
|
| - base::scoped_nsobject<ChromeSigninViewController> signinViewController_;
|
| - base::scoped_nsobject<ChromeIdentityInteractionManager>
|
| - identityInteractionManager_;
|
| - base::scoped_nsobject<ChromeIdentity> signInIdentity_;
|
| + AlertCoordinator* alertCoordinator_;
|
| + CompletionCallback completionCallback_;
|
| + ChromeSigninViewController* signinViewController_;
|
| + ChromeIdentityInteractionManager* identityInteractionManager_;
|
| + ChromeIdentity* signInIdentity_;
|
| BOOL identityAdded_;
|
| }
|
| @end
|
| @@ -67,7 +67,7 @@ using signin_ui::CompletionCallback;
|
| DCHECK(browserState);
|
| DCHECK(presentingViewController);
|
| browserState_ = browserState;
|
| - presentingViewController_.reset([presentingViewController retain]);
|
| + presentingViewController_ = presentingViewController;
|
| isPresentedOnSettings_ = isPresentedOnSettings;
|
| accessPoint_ = accessPoint;
|
| promoAction_ = promoAction;
|
| @@ -79,7 +79,12 @@ using signin_ui::CompletionCallback;
|
| // Cancelling and dismissing the |identityInteractionManager_| may call the
|
| // |completionCallback_| which could lead to |self| being released before the
|
| // end of this method. |self| is retained here to prevent this from happening.
|
| - base::scoped_nsobject<SigninInteractionController> strongSelf([self retain]);
|
| +#pragma clang diagnostic push
|
| +#pragma clang diagnostic ignored "-Wunused-variable"
|
| + // Retain this object through the rest of this method in case this object's
|
| + // owner frees this object during the execution of the completion block.
|
| + SigninInteractionController* strongSelf = self;
|
| +#pragma clang diagnostic pop
|
| isCancelling_ = YES;
|
| [alertCoordinator_ executeCancelHandler];
|
| [alertCoordinator_ stop];
|
| @@ -98,7 +103,7 @@ using signin_ui::CompletionCallback;
|
| identity:(ChromeIdentity*)identity
|
| completion:(signin_ui::CompletionCallback)completion {
|
| signin_metrics::LogSigninAccessPointStarted(accessPoint_, promoAction_);
|
| - completionCallback_.reset(completion, base::scoped_policy::RETAIN);
|
| + completionCallback_ = [completion copy];
|
| ios::ChromeIdentityService* identityService =
|
| ios::GetChromeBrowserProvider()->GetChromeIdentityService();
|
| if (identity) {
|
| @@ -119,7 +124,7 @@ using signin_ui::CompletionCallback;
|
| return;
|
| }
|
|
|
| - base::WeakNSObject<SigninInteractionController> weakSelf(self);
|
| + __weak SigninInteractionController* weakSelf = self;
|
| [identityInteractionManager_
|
| addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) {
|
| [weakSelf handleIdentityAdded:identity
|
| @@ -133,7 +138,7 @@ using signin_ui::CompletionCallback;
|
| - (void)reAuthenticateWithCompletion:(CompletionCallback)completion
|
| viewController:(UIViewController*)viewController {
|
| signin_metrics::LogSigninAccessPointStarted(accessPoint_, promoAction_);
|
| - completionCallback_.reset(completion, base::scoped_policy::RETAIN);
|
| + completionCallback_ = [completion copy];
|
| AccountInfo accountInfo =
|
| ios::SigninManagerFactory::GetForBrowserState(browserState_)
|
| ->GetAuthenticatedAccountInfo();
|
| @@ -158,7 +163,7 @@ using signin_ui::CompletionCallback;
|
| ios::GetChromeBrowserProvider()
|
| ->GetChromeIdentityService()
|
| ->NewChromeIdentityInteractionManager(browserState_, self);
|
| - base::WeakNSObject<SigninInteractionController> weakSelf(self);
|
| + __weak SigninInteractionController* weakSelf = self;
|
| [identityInteractionManager_
|
| reauthenticateUserWithID:base::SysUTF8ToNSString(idToReauthenticate)
|
| email:base::SysUTF8ToNSString(emailToReauthenticate)
|
| @@ -172,12 +177,12 @@ using signin_ui::CompletionCallback;
|
|
|
| - (void)addAccountWithCompletion:(CompletionCallback)completion
|
| viewController:(UIViewController*)viewController {
|
| - completionCallback_.reset(completion, base::scoped_policy::RETAIN);
|
| + completionCallback_ = [completion copy];
|
| identityInteractionManager_ =
|
| ios::GetChromeBrowserProvider()
|
| ->GetChromeIdentityService()
|
| ->NewChromeIdentityInteractionManager(browserState_, self);
|
| - base::WeakNSObject<SigninInteractionController> weakSelf(self);
|
| + __weak SigninInteractionController* weakSelf = self;
|
| [identityInteractionManager_
|
| addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) {
|
| [weakSelf handleIdentityAdded:identity
|
| @@ -203,15 +208,14 @@ using signin_ui::CompletionCallback;
|
| return;
|
| }
|
|
|
| - base::WeakNSObject<SigninInteractionController> weakSelf(self);
|
| + __weak SigninInteractionController* weakSelf = self;
|
| ProceduralBlock dismissAction = ^{
|
| [weakSelf runCompletionCallbackWithSuccess:NO executeCommand:nil];
|
| };
|
|
|
| - alertCoordinator_.reset([ios_internal::ErrorCoordinator(
|
| + alertCoordinator_ = ios_internal::ErrorCoordinator(
|
| error, dismissAction,
|
| - top_view_controller::TopPresentedViewControllerFrom(viewController))
|
| - retain]);
|
| + top_view_controller::TopPresentedViewControllerFrom(viewController));
|
| [alertCoordinator_ start];
|
| return;
|
| }
|
| @@ -266,18 +270,18 @@ using signin_ui::CompletionCallback;
|
|
|
| - (void)showSigninViewControllerWithIdentity:(ChromeIdentity*)signInIdentity
|
| identityAdded:(BOOL)identityAdded {
|
| - signinViewController_.reset([[ChromeSigninViewController alloc]
|
| + signinViewController_ = [[ChromeSigninViewController alloc]
|
| initWithBrowserState:browserState_
|
| isPresentedOnSettings:isPresentedOnSettings_
|
| accessPoint:accessPoint_
|
| promoAction:promoAction_
|
| - signInIdentity:signInIdentity]);
|
| + signInIdentity:signInIdentity];
|
| [signinViewController_ setDelegate:self];
|
| [signinViewController_
|
| setModalPresentationStyle:UIModalPresentationFormSheet];
|
| [signinViewController_
|
| setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
|
| - signInIdentity_.reset([signInIdentity retain]);
|
| + signInIdentity_ = signInIdentity;
|
| identityAdded_ = identityAdded;
|
|
|
| UIViewController* presentingViewController = presentingViewController_;
|
| @@ -315,27 +319,27 @@ using signin_ui::CompletionCallback;
|
| #pragma mark - ChromeSigninViewControllerDelegate
|
|
|
| - (void)willStartSignIn:(ChromeSigninViewController*)controller {
|
| - DCHECK_EQ(controller, signinViewController_.get());
|
| + DCHECK_EQ(controller, signinViewController_);
|
| }
|
|
|
| - (void)willStartAddAccount:(ChromeSigninViewController*)controller {
|
| - DCHECK_EQ(controller, signinViewController_.get());
|
| + DCHECK_EQ(controller, signinViewController_);
|
| }
|
|
|
| - (void)didSkipSignIn:(ChromeSigninViewController*)controller {
|
| - DCHECK_EQ(controller, signinViewController_.get());
|
| + DCHECK_EQ(controller, signinViewController_);
|
| [self dismissSigninViewControllerWithSignInSuccess:NO executeCommand:nil];
|
| }
|
|
|
| - (void)didSignIn:(ChromeSigninViewController*)controller {
|
| - DCHECK_EQ(controller, signinViewController_.get());
|
| + DCHECK_EQ(controller, signinViewController_);
|
| }
|
|
|
| - (void)didUndoSignIn:(ChromeSigninViewController*)controller
|
| identity:(ChromeIdentity*)identity {
|
| - DCHECK_EQ(controller, signinViewController_.get());
|
| - if ([signInIdentity_.get() isEqual:identity]) {
|
| - signInIdentity_.reset();
|
| + DCHECK_EQ(controller, signinViewController_);
|
| + if ([signInIdentity_ isEqual:identity]) {
|
| + signInIdentity_ = nil;
|
| if (identityAdded_) {
|
| // This is best effort. If the operation fails, the account will be left
|
| // on the device. The user will not be warned either as this call is
|
| @@ -350,13 +354,13 @@ using signin_ui::CompletionCallback;
|
| }
|
|
|
| - (void)didFailSignIn:(ChromeSigninViewController*)controller {
|
| - DCHECK_EQ(controller, signinViewController_.get());
|
| + DCHECK_EQ(controller, signinViewController_);
|
| [self dismissSigninViewControllerWithSignInSuccess:NO executeCommand:nil];
|
| }
|
|
|
| - (void)didAcceptSignIn:(ChromeSigninViewController*)controller
|
| executeCommand:(GenericChromeCommand*)command {
|
| - DCHECK_EQ(controller, signinViewController_.get());
|
| + DCHECK_EQ(controller, signinViewController_);
|
| [self dismissSigninViewControllerWithSignInSuccess:YES
|
| executeCommand:command];
|
| }
|
| @@ -373,16 +377,16 @@ using signin_ui::CompletionCallback;
|
| [self dismissPresentedViewControllersAnimated:YES completion:nil];
|
| }
|
|
|
| - identityInteractionManager_.reset();
|
| - signinViewController_.reset();
|
| + identityInteractionManager_ = nil;
|
| + signinViewController_ = nil;
|
| UIViewController* presentingViewController = presentingViewController_;
|
| // Ensure self is not destroyed in the callbacks.
|
| - base::scoped_nsobject<SigninInteractionController> strongSelf([self retain]);
|
| + SigninInteractionController* strongSelf = self;
|
| if (completionCallback_) {
|
| - completionCallback_.get()(success);
|
| - completionCallback_.reset();
|
| + completionCallback_(success);
|
| + completionCallback_ = nil;
|
| }
|
| - strongSelf.reset();
|
| + strongSelf = nil;
|
| if (command) {
|
| [presentingViewController chromeExecuteCommand:command];
|
| }
|
|
|