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