| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/authentication/signin_interaction_controller.h" | 5 #import "ios/chrome/browser/ui/authentication/signin_interaction_controller.h" |
| 6 | 6 |
| 7 #include "base/ios/weak_nsobject.h" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "base/mac/scoped_block.h" | |
| 10 #include "base/mac/scoped_nsobject.h" | |
| 11 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 12 #include "components/prefs/pref_service.h" | 9 #include "components/prefs/pref_service.h" |
| 13 #include "components/signin/core/browser/signin_manager.h" | 10 #include "components/signin/core/browser/signin_manager.h" |
| 14 #include "components/signin/core/common/signin_pref_names.h" | 11 #include "components/signin/core/common/signin_pref_names.h" |
| 15 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" | 12 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 16 #include "ios/chrome/browser/signin/authentication_service.h" | 13 #include "ios/chrome/browser/signin/authentication_service.h" |
| 17 #include "ios/chrome/browser/signin/authentication_service_factory.h" | 14 #include "ios/chrome/browser/signin/authentication_service_factory.h" |
| 18 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 15 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
| 19 #import "ios/chrome/browser/signin/signin_util.h" | 16 #import "ios/chrome/browser/signin/signin_util.h" |
| 20 #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" | 17 #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" |
| 21 #import "ios/chrome/browser/ui/authentication/authentication_ui_util.h" | 18 #import "ios/chrome/browser/ui/authentication/authentication_ui_util.h" |
| 22 #import "ios/chrome/browser/ui/authentication/chrome_signin_view_controller.h" | 19 #import "ios/chrome/browser/ui/authentication/chrome_signin_view_controller.h" |
| 23 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 20 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 24 #import "ios/chrome/browser/ui/util/top_view_controller.h" | 21 #import "ios/chrome/browser/ui/util/top_view_controller.h" |
| 25 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 22 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 26 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 23 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
| 27 #import "ios/public/provider/chrome/browser/signin/chrome_identity_interaction_m
anager.h" | 24 #import "ios/public/provider/chrome/browser/signin/chrome_identity_interaction_m
anager.h" |
| 28 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" | 25 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
| 29 | 26 |
| 27 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 28 #error "This file requires ARC support." |
| 29 #endif |
| 30 |
| 30 using signin_ui::CompletionCallback; | 31 using signin_ui::CompletionCallback; |
| 31 | 32 |
| 32 @interface SigninInteractionController ()< | 33 @interface SigninInteractionController ()< |
| 33 ChromeIdentityInteractionManagerDelegate, | 34 ChromeIdentityInteractionManagerDelegate, |
| 34 ChromeSigninViewControllerDelegate> { | 35 ChromeSigninViewControllerDelegate> { |
| 35 ios::ChromeBrowserState* browserState_; | 36 ios::ChromeBrowserState* browserState_; |
| 36 signin_metrics::AccessPoint accessPoint_; | 37 signin_metrics::AccessPoint accessPoint_; |
| 37 signin_metrics::PromoAction promoAction_; | 38 signin_metrics::PromoAction promoAction_; |
| 38 base::scoped_nsobject<UIViewController> presentingViewController_; | 39 UIViewController* presentingViewController_; |
| 39 BOOL isPresentedOnSettings_; | 40 BOOL isPresentedOnSettings_; |
| 40 BOOL isCancelling_; | 41 BOOL isCancelling_; |
| 41 BOOL isDismissing_; | 42 BOOL isDismissing_; |
| 42 BOOL interactionManagerDismissalIgnored_; | 43 BOOL interactionManagerDismissalIgnored_; |
| 43 base::scoped_nsobject<AlertCoordinator> alertCoordinator_; | 44 AlertCoordinator* alertCoordinator_; |
| 44 base::mac::ScopedBlock<CompletionCallback> completionCallback_; | 45 CompletionCallback completionCallback_; |
| 45 base::scoped_nsobject<ChromeSigninViewController> signinViewController_; | 46 ChromeSigninViewController* signinViewController_; |
| 46 base::scoped_nsobject<ChromeIdentityInteractionManager> | 47 ChromeIdentityInteractionManager* identityInteractionManager_; |
| 47 identityInteractionManager_; | 48 ChromeIdentity* signInIdentity_; |
| 48 base::scoped_nsobject<ChromeIdentity> signInIdentity_; | |
| 49 BOOL identityAdded_; | 49 BOOL identityAdded_; |
| 50 } | 50 } |
| 51 @end | 51 @end |
| 52 | 52 |
| 53 @implementation SigninInteractionController | 53 @implementation SigninInteractionController |
| 54 | 54 |
| 55 - (id)init { | 55 - (id)init { |
| 56 NOTREACHED(); | 56 NOTREACHED(); |
| 57 return nil; | 57 return nil; |
| 58 } | 58 } |
| 59 | 59 |
| 60 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 60 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 61 presentingViewController:(UIViewController*)presentingViewController | 61 presentingViewController:(UIViewController*)presentingViewController |
| 62 isPresentedOnSettings:(BOOL)isPresentedOnSettings | 62 isPresentedOnSettings:(BOOL)isPresentedOnSettings |
| 63 accessPoint:(signin_metrics::AccessPoint)accessPoint | 63 accessPoint:(signin_metrics::AccessPoint)accessPoint |
| 64 promoAction:(signin_metrics::PromoAction)promoAction { | 64 promoAction:(signin_metrics::PromoAction)promoAction { |
| 65 self = [super init]; | 65 self = [super init]; |
| 66 if (self) { | 66 if (self) { |
| 67 DCHECK(browserState); | 67 DCHECK(browserState); |
| 68 DCHECK(presentingViewController); | 68 DCHECK(presentingViewController); |
| 69 browserState_ = browserState; | 69 browserState_ = browserState; |
| 70 presentingViewController_.reset([presentingViewController retain]); | 70 presentingViewController_ = presentingViewController; |
| 71 isPresentedOnSettings_ = isPresentedOnSettings; | 71 isPresentedOnSettings_ = isPresentedOnSettings; |
| 72 accessPoint_ = accessPoint; | 72 accessPoint_ = accessPoint; |
| 73 promoAction_ = promoAction; | 73 promoAction_ = promoAction; |
| 74 } | 74 } |
| 75 return self; | 75 return self; |
| 76 } | 76 } |
| 77 | 77 |
| 78 - (void)cancel { | 78 - (void)cancel { |
| 79 // Cancelling and dismissing the |identityInteractionManager_| may call the | 79 // Cancelling and dismissing the |identityInteractionManager_| may call the |
| 80 // |completionCallback_| which could lead to |self| being released before the | 80 // |completionCallback_| which could lead to |self| being released before the |
| 81 // end of this method. |self| is retained here to prevent this from happening. | 81 // end of this method. |self| is retained here to prevent this from happening. |
| 82 base::scoped_nsobject<SigninInteractionController> strongSelf([self retain]); | 82 #pragma clang diagnostic push |
| 83 #pragma clang diagnostic ignored "-Wunused-variable" |
| 84 // Retain this object through the rest of this method in case this object's |
| 85 // owner frees this object during the execution of the completion block. |
| 86 SigninInteractionController* strongSelf = self; |
| 87 #pragma clang diagnostic pop |
| 83 isCancelling_ = YES; | 88 isCancelling_ = YES; |
| 84 [alertCoordinator_ executeCancelHandler]; | 89 [alertCoordinator_ executeCancelHandler]; |
| 85 [alertCoordinator_ stop]; | 90 [alertCoordinator_ stop]; |
| 86 [identityInteractionManager_ cancelAndDismissAnimated:NO]; | 91 [identityInteractionManager_ cancelAndDismissAnimated:NO]; |
| 87 [signinViewController_ cancel]; | 92 [signinViewController_ cancel]; |
| 88 isCancelling_ = NO; | 93 isCancelling_ = NO; |
| 89 } | 94 } |
| 90 | 95 |
| 91 - (void)cancelAndDismiss { | 96 - (void)cancelAndDismiss { |
| 92 isDismissing_ = YES; | 97 isDismissing_ = YES; |
| 93 [self cancel]; | 98 [self cancel]; |
| 94 isDismissing_ = NO; | 99 isDismissing_ = NO; |
| 95 } | 100 } |
| 96 | 101 |
| 97 - (void)signInWithViewController:(UIViewController*)viewController | 102 - (void)signInWithViewController:(UIViewController*)viewController |
| 98 identity:(ChromeIdentity*)identity | 103 identity:(ChromeIdentity*)identity |
| 99 completion:(signin_ui::CompletionCallback)completion { | 104 completion:(signin_ui::CompletionCallback)completion { |
| 100 signin_metrics::LogSigninAccessPointStarted(accessPoint_, promoAction_); | 105 signin_metrics::LogSigninAccessPointStarted(accessPoint_, promoAction_); |
| 101 completionCallback_.reset(completion, base::scoped_policy::RETAIN); | 106 completionCallback_ = [completion copy]; |
| 102 ios::ChromeIdentityService* identityService = | 107 ios::ChromeIdentityService* identityService = |
| 103 ios::GetChromeBrowserProvider()->GetChromeIdentityService(); | 108 ios::GetChromeBrowserProvider()->GetChromeIdentityService(); |
| 104 if (identity) { | 109 if (identity) { |
| 105 DCHECK(identityService->IsValidIdentity(identity)); | 110 DCHECK(identityService->IsValidIdentity(identity)); |
| 106 DCHECK(!signinViewController_); | 111 DCHECK(!signinViewController_); |
| 107 [self showSigninViewControllerWithIdentity:identity identityAdded:NO]; | 112 [self showSigninViewControllerWithIdentity:identity identityAdded:NO]; |
| 108 } else if (identityService->HasIdentities()) { | 113 } else if (identityService->HasIdentities()) { |
| 109 DCHECK(!signinViewController_); | 114 DCHECK(!signinViewController_); |
| 110 [self showSigninViewControllerWithIdentity:nil identityAdded:NO]; | 115 [self showSigninViewControllerWithIdentity:nil identityAdded:NO]; |
| 111 } else { | 116 } else { |
| 112 identityInteractionManager_ = | 117 identityInteractionManager_ = |
| 113 identityService->NewChromeIdentityInteractionManager(browserState_, | 118 identityService->NewChromeIdentityInteractionManager(browserState_, |
| 114 self); | 119 self); |
| 115 if (!identityInteractionManager_) { | 120 if (!identityInteractionManager_) { |
| 116 // Abort sign-in if the ChromeIdentityInteractionManager returned is | 121 // Abort sign-in if the ChromeIdentityInteractionManager returned is |
| 117 // nil (this can happen when the iOS internal provider is not used). | 122 // nil (this can happen when the iOS internal provider is not used). |
| 118 [self runCompletionCallbackWithSuccess:NO executeCommand:nil]; | 123 [self runCompletionCallbackWithSuccess:NO executeCommand:nil]; |
| 119 return; | 124 return; |
| 120 } | 125 } |
| 121 | 126 |
| 122 base::WeakNSObject<SigninInteractionController> weakSelf(self); | 127 __weak SigninInteractionController* weakSelf = self; |
| 123 [identityInteractionManager_ | 128 [identityInteractionManager_ |
| 124 addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { | 129 addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { |
| 125 [weakSelf handleIdentityAdded:identity | 130 [weakSelf handleIdentityAdded:identity |
| 126 error:error | 131 error:error |
| 127 shouldSignIn:YES | 132 shouldSignIn:YES |
| 128 viewController:viewController]; | 133 viewController:viewController]; |
| 129 }]; | 134 }]; |
| 130 } | 135 } |
| 131 } | 136 } |
| 132 | 137 |
| 133 - (void)reAuthenticateWithCompletion:(CompletionCallback)completion | 138 - (void)reAuthenticateWithCompletion:(CompletionCallback)completion |
| 134 viewController:(UIViewController*)viewController { | 139 viewController:(UIViewController*)viewController { |
| 135 signin_metrics::LogSigninAccessPointStarted(accessPoint_, promoAction_); | 140 signin_metrics::LogSigninAccessPointStarted(accessPoint_, promoAction_); |
| 136 completionCallback_.reset(completion, base::scoped_policy::RETAIN); | 141 completionCallback_ = [completion copy]; |
| 137 AccountInfo accountInfo = | 142 AccountInfo accountInfo = |
| 138 ios::SigninManagerFactory::GetForBrowserState(browserState_) | 143 ios::SigninManagerFactory::GetForBrowserState(browserState_) |
| 139 ->GetAuthenticatedAccountInfo(); | 144 ->GetAuthenticatedAccountInfo(); |
| 140 std::string emailToReauthenticate = accountInfo.email; | 145 std::string emailToReauthenticate = accountInfo.email; |
| 141 std::string idToReauthenticate = accountInfo.gaia; | 146 std::string idToReauthenticate = accountInfo.gaia; |
| 142 if (emailToReauthenticate.empty() || idToReauthenticate.empty()) { | 147 if (emailToReauthenticate.empty() || idToReauthenticate.empty()) { |
| 143 // This corresponds to a re-authenticate request after the user was signed | 148 // This corresponds to a re-authenticate request after the user was signed |
| 144 // out. This corresponds to the case where the identity was removed as a | 149 // out. This corresponds to the case where the identity was removed as a |
| 145 // result of the permissions being removed on the server or the identity | 150 // result of the permissions being removed on the server or the identity |
| 146 // being removed from another app. | 151 // being removed from another app. |
| 147 // | 152 // |
| 148 // Simply use the the last signed-in user email in this case and go though | 153 // Simply use the the last signed-in user email in this case and go though |
| 149 // the entire sign-in flow as sync needs to be configured. | 154 // the entire sign-in flow as sync needs to be configured. |
| 150 emailToReauthenticate = browserState_->GetPrefs()->GetString( | 155 emailToReauthenticate = browserState_->GetPrefs()->GetString( |
| 151 prefs::kGoogleServicesLastUsername); | 156 prefs::kGoogleServicesLastUsername); |
| 152 idToReauthenticate = browserState_->GetPrefs()->GetString( | 157 idToReauthenticate = browserState_->GetPrefs()->GetString( |
| 153 prefs::kGoogleServicesLastAccountId); | 158 prefs::kGoogleServicesLastAccountId); |
| 154 } | 159 } |
| 155 DCHECK(!emailToReauthenticate.empty()); | 160 DCHECK(!emailToReauthenticate.empty()); |
| 156 DCHECK(!idToReauthenticate.empty()); | 161 DCHECK(!idToReauthenticate.empty()); |
| 157 identityInteractionManager_ = | 162 identityInteractionManager_ = |
| 158 ios::GetChromeBrowserProvider() | 163 ios::GetChromeBrowserProvider() |
| 159 ->GetChromeIdentityService() | 164 ->GetChromeIdentityService() |
| 160 ->NewChromeIdentityInteractionManager(browserState_, self); | 165 ->NewChromeIdentityInteractionManager(browserState_, self); |
| 161 base::WeakNSObject<SigninInteractionController> weakSelf(self); | 166 __weak SigninInteractionController* weakSelf = self; |
| 162 [identityInteractionManager_ | 167 [identityInteractionManager_ |
| 163 reauthenticateUserWithID:base::SysUTF8ToNSString(idToReauthenticate) | 168 reauthenticateUserWithID:base::SysUTF8ToNSString(idToReauthenticate) |
| 164 email:base::SysUTF8ToNSString(emailToReauthenticate) | 169 email:base::SysUTF8ToNSString(emailToReauthenticate) |
| 165 completion:^(ChromeIdentity* identity, NSError* error) { | 170 completion:^(ChromeIdentity* identity, NSError* error) { |
| 166 [weakSelf handleIdentityAdded:identity | 171 [weakSelf handleIdentityAdded:identity |
| 167 error:error | 172 error:error |
| 168 shouldSignIn:YES | 173 shouldSignIn:YES |
| 169 viewController:viewController]; | 174 viewController:viewController]; |
| 170 }]; | 175 }]; |
| 171 } | 176 } |
| 172 | 177 |
| 173 - (void)addAccountWithCompletion:(CompletionCallback)completion | 178 - (void)addAccountWithCompletion:(CompletionCallback)completion |
| 174 viewController:(UIViewController*)viewController { | 179 viewController:(UIViewController*)viewController { |
| 175 completionCallback_.reset(completion, base::scoped_policy::RETAIN); | 180 completionCallback_ = [completion copy]; |
| 176 identityInteractionManager_ = | 181 identityInteractionManager_ = |
| 177 ios::GetChromeBrowserProvider() | 182 ios::GetChromeBrowserProvider() |
| 178 ->GetChromeIdentityService() | 183 ->GetChromeIdentityService() |
| 179 ->NewChromeIdentityInteractionManager(browserState_, self); | 184 ->NewChromeIdentityInteractionManager(browserState_, self); |
| 180 base::WeakNSObject<SigninInteractionController> weakSelf(self); | 185 __weak SigninInteractionController* weakSelf = self; |
| 181 [identityInteractionManager_ | 186 [identityInteractionManager_ |
| 182 addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { | 187 addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { |
| 183 [weakSelf handleIdentityAdded:identity | 188 [weakSelf handleIdentityAdded:identity |
| 184 error:error | 189 error:error |
| 185 shouldSignIn:NO | 190 shouldSignIn:NO |
| 186 viewController:viewController]; | 191 viewController:viewController]; |
| 187 }]; | 192 }]; |
| 188 } | 193 } |
| 189 | 194 |
| 190 #pragma mark - ChromeIdentityInteractionManager operations | 195 #pragma mark - ChromeIdentityInteractionManager operations |
| 191 | 196 |
| 192 - (void)handleIdentityAdded:(ChromeIdentity*)identity | 197 - (void)handleIdentityAdded:(ChromeIdentity*)identity |
| 193 error:(NSError*)error | 198 error:(NSError*)error |
| 194 shouldSignIn:(BOOL)shouldSignIn | 199 shouldSignIn:(BOOL)shouldSignIn |
| 195 viewController:(UIViewController*)viewController { | 200 viewController:(UIViewController*)viewController { |
| 196 if (!identityInteractionManager_) | 201 if (!identityInteractionManager_) |
| 197 return; | 202 return; |
| 198 | 203 |
| 199 if (error) { | 204 if (error) { |
| 200 // Filter out cancel and errors handled internally by ChromeIdentity. | 205 // Filter out cancel and errors handled internally by ChromeIdentity. |
| 201 if (!ShouldHandleSigninError(error)) { | 206 if (!ShouldHandleSigninError(error)) { |
| 202 [self runCompletionCallbackWithSuccess:NO executeCommand:nil]; | 207 [self runCompletionCallbackWithSuccess:NO executeCommand:nil]; |
| 203 return; | 208 return; |
| 204 } | 209 } |
| 205 | 210 |
| 206 base::WeakNSObject<SigninInteractionController> weakSelf(self); | 211 __weak SigninInteractionController* weakSelf = self; |
| 207 ProceduralBlock dismissAction = ^{ | 212 ProceduralBlock dismissAction = ^{ |
| 208 [weakSelf runCompletionCallbackWithSuccess:NO executeCommand:nil]; | 213 [weakSelf runCompletionCallbackWithSuccess:NO executeCommand:nil]; |
| 209 }; | 214 }; |
| 210 | 215 |
| 211 alertCoordinator_.reset([ios_internal::ErrorCoordinator( | 216 alertCoordinator_ = ios_internal::ErrorCoordinator( |
| 212 error, dismissAction, | 217 error, dismissAction, |
| 213 top_view_controller::TopPresentedViewControllerFrom(viewController)) | 218 top_view_controller::TopPresentedViewControllerFrom(viewController)); |
| 214 retain]); | |
| 215 [alertCoordinator_ start]; | 219 [alertCoordinator_ start]; |
| 216 return; | 220 return; |
| 217 } | 221 } |
| 218 if (shouldSignIn) { | 222 if (shouldSignIn) { |
| 219 [self showSigninViewControllerWithIdentity:identity identityAdded:YES]; | 223 [self showSigninViewControllerWithIdentity:identity identityAdded:YES]; |
| 220 } else { | 224 } else { |
| 221 [self runCompletionCallbackWithSuccess:YES executeCommand:nil]; | 225 [self runCompletionCallbackWithSuccess:YES executeCommand:nil]; |
| 222 } | 226 } |
| 223 } | 227 } |
| 224 | 228 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (completion) { | 263 if (completion) { |
| 260 completion(); | 264 completion(); |
| 261 } | 265 } |
| 262 } | 266 } |
| 263 } | 267 } |
| 264 | 268 |
| 265 #pragma mark - ChromeSigninViewController operations | 269 #pragma mark - ChromeSigninViewController operations |
| 266 | 270 |
| 267 - (void)showSigninViewControllerWithIdentity:(ChromeIdentity*)signInIdentity | 271 - (void)showSigninViewControllerWithIdentity:(ChromeIdentity*)signInIdentity |
| 268 identityAdded:(BOOL)identityAdded { | 272 identityAdded:(BOOL)identityAdded { |
| 269 signinViewController_.reset([[ChromeSigninViewController alloc] | 273 signinViewController_ = [[ChromeSigninViewController alloc] |
| 270 initWithBrowserState:browserState_ | 274 initWithBrowserState:browserState_ |
| 271 isPresentedOnSettings:isPresentedOnSettings_ | 275 isPresentedOnSettings:isPresentedOnSettings_ |
| 272 accessPoint:accessPoint_ | 276 accessPoint:accessPoint_ |
| 273 promoAction:promoAction_ | 277 promoAction:promoAction_ |
| 274 signInIdentity:signInIdentity]); | 278 signInIdentity:signInIdentity]; |
| 275 [signinViewController_ setDelegate:self]; | 279 [signinViewController_ setDelegate:self]; |
| 276 [signinViewController_ | 280 [signinViewController_ |
| 277 setModalPresentationStyle:UIModalPresentationFormSheet]; | 281 setModalPresentationStyle:UIModalPresentationFormSheet]; |
| 278 [signinViewController_ | 282 [signinViewController_ |
| 279 setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; | 283 setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; |
| 280 signInIdentity_.reset([signInIdentity retain]); | 284 signInIdentity_ = signInIdentity; |
| 281 identityAdded_ = identityAdded; | 285 identityAdded_ = identityAdded; |
| 282 | 286 |
| 283 UIViewController* presentingViewController = presentingViewController_; | 287 UIViewController* presentingViewController = presentingViewController_; |
| 284 if (identityInteractionManager_) { | 288 if (identityInteractionManager_) { |
| 285 // If |identityInteractionManager_| is currently displayed, | 289 // If |identityInteractionManager_| is currently displayed, |
| 286 // |signinViewController_| is presented on top of it (instead of on top of | 290 // |signinViewController_| is presented on top of it (instead of on top of |
| 287 // |presentingViewController_|), to avoid an awkward transition (dismissing | 291 // |presentingViewController_|), to avoid an awkward transition (dismissing |
| 288 // |identityInteractionManager_|, followed by presenting | 292 // |identityInteractionManager_|, followed by presenting |
| 289 // |signinViewController_|). | 293 // |signinViewController_|). |
| 290 while (presentingViewController.presentedViewController) { | 294 while (presentingViewController.presentedViewController) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 308 } | 312 } |
| 309 ProceduralBlock completion = ^{ | 313 ProceduralBlock completion = ^{ |
| 310 [self runCompletionCallbackWithSuccess:success executeCommand:command]; | 314 [self runCompletionCallbackWithSuccess:success executeCommand:command]; |
| 311 }; | 315 }; |
| 312 [self dismissPresentedViewControllersAnimated:YES completion:completion]; | 316 [self dismissPresentedViewControllersAnimated:YES completion:completion]; |
| 313 } | 317 } |
| 314 | 318 |
| 315 #pragma mark - ChromeSigninViewControllerDelegate | 319 #pragma mark - ChromeSigninViewControllerDelegate |
| 316 | 320 |
| 317 - (void)willStartSignIn:(ChromeSigninViewController*)controller { | 321 - (void)willStartSignIn:(ChromeSigninViewController*)controller { |
| 318 DCHECK_EQ(controller, signinViewController_.get()); | 322 DCHECK_EQ(controller, signinViewController_); |
| 319 } | 323 } |
| 320 | 324 |
| 321 - (void)willStartAddAccount:(ChromeSigninViewController*)controller { | 325 - (void)willStartAddAccount:(ChromeSigninViewController*)controller { |
| 322 DCHECK_EQ(controller, signinViewController_.get()); | 326 DCHECK_EQ(controller, signinViewController_); |
| 323 } | 327 } |
| 324 | 328 |
| 325 - (void)didSkipSignIn:(ChromeSigninViewController*)controller { | 329 - (void)didSkipSignIn:(ChromeSigninViewController*)controller { |
| 326 DCHECK_EQ(controller, signinViewController_.get()); | 330 DCHECK_EQ(controller, signinViewController_); |
| 327 [self dismissSigninViewControllerWithSignInSuccess:NO executeCommand:nil]; | 331 [self dismissSigninViewControllerWithSignInSuccess:NO executeCommand:nil]; |
| 328 } | 332 } |
| 329 | 333 |
| 330 - (void)didSignIn:(ChromeSigninViewController*)controller { | 334 - (void)didSignIn:(ChromeSigninViewController*)controller { |
| 331 DCHECK_EQ(controller, signinViewController_.get()); | 335 DCHECK_EQ(controller, signinViewController_); |
| 332 } | 336 } |
| 333 | 337 |
| 334 - (void)didUndoSignIn:(ChromeSigninViewController*)controller | 338 - (void)didUndoSignIn:(ChromeSigninViewController*)controller |
| 335 identity:(ChromeIdentity*)identity { | 339 identity:(ChromeIdentity*)identity { |
| 336 DCHECK_EQ(controller, signinViewController_.get()); | 340 DCHECK_EQ(controller, signinViewController_); |
| 337 if ([signInIdentity_.get() isEqual:identity]) { | 341 if ([signInIdentity_ isEqual:identity]) { |
| 338 signInIdentity_.reset(); | 342 signInIdentity_ = nil; |
| 339 if (identityAdded_) { | 343 if (identityAdded_) { |
| 340 // This is best effort. If the operation fails, the account will be left | 344 // This is best effort. If the operation fails, the account will be left |
| 341 // on the device. The user will not be warned either as this call is | 345 // on the device. The user will not be warned either as this call is |
| 342 // asynchronous (but undo is not), the application might be in an unknown | 346 // asynchronous (but undo is not), the application might be in an unknown |
| 343 // state when the forget identity operation finishes. | 347 // state when the forget identity operation finishes. |
| 344 ios::GetChromeBrowserProvider() | 348 ios::GetChromeBrowserProvider() |
| 345 ->GetChromeIdentityService() | 349 ->GetChromeIdentityService() |
| 346 ->ForgetIdentity(identity, nil); | 350 ->ForgetIdentity(identity, nil); |
| 347 } | 351 } |
| 348 [self dismissSigninViewControllerWithSignInSuccess:NO executeCommand:nil]; | 352 [self dismissSigninViewControllerWithSignInSuccess:NO executeCommand:nil]; |
| 349 } | 353 } |
| 350 } | 354 } |
| 351 | 355 |
| 352 - (void)didFailSignIn:(ChromeSigninViewController*)controller { | 356 - (void)didFailSignIn:(ChromeSigninViewController*)controller { |
| 353 DCHECK_EQ(controller, signinViewController_.get()); | 357 DCHECK_EQ(controller, signinViewController_); |
| 354 [self dismissSigninViewControllerWithSignInSuccess:NO executeCommand:nil]; | 358 [self dismissSigninViewControllerWithSignInSuccess:NO executeCommand:nil]; |
| 355 } | 359 } |
| 356 | 360 |
| 357 - (void)didAcceptSignIn:(ChromeSigninViewController*)controller | 361 - (void)didAcceptSignIn:(ChromeSigninViewController*)controller |
| 358 executeCommand:(GenericChromeCommand*)command { | 362 executeCommand:(GenericChromeCommand*)command { |
| 359 DCHECK_EQ(controller, signinViewController_.get()); | 363 DCHECK_EQ(controller, signinViewController_); |
| 360 [self dismissSigninViewControllerWithSignInSuccess:YES | 364 [self dismissSigninViewControllerWithSignInSuccess:YES |
| 361 executeCommand:command]; | 365 executeCommand:command]; |
| 362 } | 366 } |
| 363 | 367 |
| 364 #pragma mark - Utility methods | 368 #pragma mark - Utility methods |
| 365 | 369 |
| 366 - (void)runCompletionCallbackWithSuccess:(BOOL)success | 370 - (void)runCompletionCallbackWithSuccess:(BOOL)success |
| 367 executeCommand:(GenericChromeCommand*)command { | 371 executeCommand:(GenericChromeCommand*)command { |
| 368 // In order to avoid awkward double transitions, |identityInteractionManager_| | 372 // In order to avoid awkward double transitions, |identityInteractionManager_| |
| 369 // is not dismissed when requested (except when canceling). However, in case | 373 // is not dismissed when requested (except when canceling). However, in case |
| 370 // of errors, |identityInteractionManager_| needs to be directly dismissed, | 374 // of errors, |identityInteractionManager_| needs to be directly dismissed, |
| 371 // which is done here. | 375 // which is done here. |
| 372 if (interactionManagerDismissalIgnored_) { | 376 if (interactionManagerDismissalIgnored_) { |
| 373 [self dismissPresentedViewControllersAnimated:YES completion:nil]; | 377 [self dismissPresentedViewControllersAnimated:YES completion:nil]; |
| 374 } | 378 } |
| 375 | 379 |
| 376 identityInteractionManager_.reset(); | 380 identityInteractionManager_ = nil; |
| 377 signinViewController_.reset(); | 381 signinViewController_ = nil; |
| 378 UIViewController* presentingViewController = presentingViewController_; | 382 UIViewController* presentingViewController = presentingViewController_; |
| 379 // Ensure self is not destroyed in the callbacks. | 383 // Ensure self is not destroyed in the callbacks. |
| 380 base::scoped_nsobject<SigninInteractionController> strongSelf([self retain]); | 384 SigninInteractionController* strongSelf = self; |
| 381 if (completionCallback_) { | 385 if (completionCallback_) { |
| 382 completionCallback_.get()(success); | 386 completionCallback_(success); |
| 383 completionCallback_.reset(); | 387 completionCallback_ = nil; |
| 384 } | 388 } |
| 385 strongSelf.reset(); | 389 strongSelf = nil; |
| 386 if (command) { | 390 if (command) { |
| 387 [presentingViewController chromeExecuteCommand:command]; | 391 [presentingViewController chromeExecuteCommand:command]; |
| 388 } | 392 } |
| 389 } | 393 } |
| 390 | 394 |
| 391 @end | 395 @end |
| OLD | NEW |