| 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" | 7 #include "base/ios/weak_nsobject.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/scoped_block.h" | 9 #include "base/mac/scoped_block.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 ios::ChromeIdentityService* identityService = | 102 ios::ChromeIdentityService* identityService = |
| 103 ios::GetChromeBrowserProvider()->GetChromeIdentityService(); | 103 ios::GetChromeBrowserProvider()->GetChromeIdentityService(); |
| 104 if (identity) { | 104 if (identity) { |
| 105 DCHECK(identityService->IsValidIdentity(identity)); | 105 DCHECK(identityService->IsValidIdentity(identity)); |
| 106 DCHECK(!signinViewController_); | 106 DCHECK(!signinViewController_); |
| 107 [self showSigninViewControllerWithIdentity:identity identityAdded:NO]; | 107 [self showSigninViewControllerWithIdentity:identity identityAdded:NO]; |
| 108 } else if (identityService->HasIdentities()) { | 108 } else if (identityService->HasIdentities()) { |
| 109 DCHECK(!signinViewController_); | 109 DCHECK(!signinViewController_); |
| 110 [self showSigninViewControllerWithIdentity:nil identityAdded:NO]; | 110 [self showSigninViewControllerWithIdentity:nil identityAdded:NO]; |
| 111 } else { | 111 } else { |
| 112 identityInteractionManager_ = | 112 identityInteractionManager_.reset( |
| 113 identityService->NewChromeIdentityInteractionManager(browserState_, | 113 identityService->CreateChromeIdentityInteractionManager(browserState_, |
| 114 self); | 114 self)); |
| 115 if (!identityInteractionManager_) { | 115 if (!identityInteractionManager_) { |
| 116 // Abort sign-in if the ChromeIdentityInteractionManager returned is | 116 // Abort sign-in if the ChromeIdentityInteractionManager returned is |
| 117 // nil (this can happen when the iOS internal provider is not used). | 117 // nil (this can happen when the iOS internal provider is not used). |
| 118 [self runCompletionCallbackWithSuccess:NO executeCommand:nil]; | 118 [self runCompletionCallbackWithSuccess:NO executeCommand:nil]; |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 | 121 |
| 122 base::WeakNSObject<SigninInteractionController> weakSelf(self); | 122 base::WeakNSObject<SigninInteractionController> weakSelf(self); |
| 123 [identityInteractionManager_ | 123 [identityInteractionManager_ |
| 124 addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { | 124 addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 147 // | 147 // |
| 148 // Simply use the the last signed-in user email in this case and go though | 148 // 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. | 149 // the entire sign-in flow as sync needs to be configured. |
| 150 emailToReauthenticate = browserState_->GetPrefs()->GetString( | 150 emailToReauthenticate = browserState_->GetPrefs()->GetString( |
| 151 prefs::kGoogleServicesLastUsername); | 151 prefs::kGoogleServicesLastUsername); |
| 152 idToReauthenticate = browserState_->GetPrefs()->GetString( | 152 idToReauthenticate = browserState_->GetPrefs()->GetString( |
| 153 prefs::kGoogleServicesLastAccountId); | 153 prefs::kGoogleServicesLastAccountId); |
| 154 } | 154 } |
| 155 DCHECK(!emailToReauthenticate.empty()); | 155 DCHECK(!emailToReauthenticate.empty()); |
| 156 DCHECK(!idToReauthenticate.empty()); | 156 DCHECK(!idToReauthenticate.empty()); |
| 157 identityInteractionManager_ = | 157 identityInteractionManager_.reset( |
| 158 ios::GetChromeBrowserProvider() | 158 ios::GetChromeBrowserProvider() |
| 159 ->GetChromeIdentityService() | 159 ->GetChromeIdentityService() |
| 160 ->NewChromeIdentityInteractionManager(browserState_, self); | 160 ->CreateChromeIdentityInteractionManager(browserState_, self)); |
| 161 base::WeakNSObject<SigninInteractionController> weakSelf(self); | 161 base::WeakNSObject<SigninInteractionController> weakSelf(self); |
| 162 [identityInteractionManager_ | 162 [identityInteractionManager_ |
| 163 reauthenticateUserWithID:base::SysUTF8ToNSString(idToReauthenticate) | 163 reauthenticateUserWithID:base::SysUTF8ToNSString(idToReauthenticate) |
| 164 email:base::SysUTF8ToNSString(emailToReauthenticate) | 164 email:base::SysUTF8ToNSString(emailToReauthenticate) |
| 165 completion:^(ChromeIdentity* identity, NSError* error) { | 165 completion:^(ChromeIdentity* identity, NSError* error) { |
| 166 [weakSelf handleIdentityAdded:identity | 166 [weakSelf handleIdentityAdded:identity |
| 167 error:error | 167 error:error |
| 168 shouldSignIn:YES | 168 shouldSignIn:YES |
| 169 viewController:viewController]; | 169 viewController:viewController]; |
| 170 }]; | 170 }]; |
| 171 } | 171 } |
| 172 | 172 |
| 173 - (void)addAccountWithCompletion:(CompletionCallback)completion | 173 - (void)addAccountWithCompletion:(CompletionCallback)completion |
| 174 viewController:(UIViewController*)viewController { | 174 viewController:(UIViewController*)viewController { |
| 175 completionCallback_.reset(completion, base::scoped_policy::RETAIN); | 175 completionCallback_.reset(completion, base::scoped_policy::RETAIN); |
| 176 identityInteractionManager_ = | 176 identityInteractionManager_.reset( |
| 177 ios::GetChromeBrowserProvider() | 177 ios::GetChromeBrowserProvider() |
| 178 ->GetChromeIdentityService() | 178 ->GetChromeIdentityService() |
| 179 ->NewChromeIdentityInteractionManager(browserState_, self); | 179 ->CreateChromeIdentityInteractionManager(browserState_, self)); |
| 180 base::WeakNSObject<SigninInteractionController> weakSelf(self); | 180 base::WeakNSObject<SigninInteractionController> weakSelf(self); |
| 181 [identityInteractionManager_ | 181 [identityInteractionManager_ |
| 182 addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { | 182 addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { |
| 183 [weakSelf handleIdentityAdded:identity | 183 [weakSelf handleIdentityAdded:identity |
| 184 error:error | 184 error:error |
| 185 shouldSignIn:NO | 185 shouldSignIn:NO |
| 186 viewController:viewController]; | 186 viewController:viewController]; |
| 187 }]; | 187 }]; |
| 188 } | 188 } |
| 189 | 189 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 completionCallback_.get()(success); | 382 completionCallback_.get()(success); |
| 383 completionCallback_.reset(); | 383 completionCallback_.reset(); |
| 384 } | 384 } |
| 385 strongSelf.reset(); | 385 strongSelf.reset(); |
| 386 if (command) { | 386 if (command) { |
| 387 [presentingViewController chromeExecuteCommand:command]; | 387 [presentingViewController chromeExecuteCommand:command]; |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 @end | 391 @end |
| OLD | NEW |