Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: ios/chrome/browser/ui/authentication/authentication_flow_performer.mm

Issue 2936583002: [ObjC ARC] Converts ios/chrome/browser/ui/authentication:authentication to ARC. (Closed)
Patch Set: Review fixes. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/authentication_flow_performer.h" 5 #import "ios/chrome/browser/ui/authentication/authentication_flow_performer.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/ios/block_types.h" 9 #include "base/ios/block_types.h"
10 #include "base/ios/weak_nsobject.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/mac/bind_objc_block.h" 11 #include "base/mac/bind_objc_block.h"
13 #include "base/mac/scoped_nsobject.h"
14 #include "base/metrics/user_metrics.h" 12 #include "base/metrics/user_metrics.h"
15 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
16 #include "base/time/time.h" 14 #include "base/time/time.h"
17 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
18 #include "components/prefs/pref_service.h" 16 #include "components/prefs/pref_service.h"
19 #include "components/signin/core/browser/account_tracker_service.h" 17 #include "components/signin/core/browser/account_tracker_service.h"
20 #include "components/signin/core/browser/signin_manager.h" 18 #include "components/signin/core/browser/signin_manager.h"
21 #include "components/signin/core/common/signin_pref_names.h" 19 #include "components/signin/core/common/signin_pref_names.h"
22 #include "components/strings/grit/components_strings.h" 20 #include "components/strings/grit/components_strings.h"
23 #include "google_apis/gaia/gaia_auth_util.h" 21 #include "google_apis/gaia/gaia_auth_util.h"
(...skipping 10 matching lines...) Expand all
34 #include "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" 32 #include "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
35 #import "ios/chrome/browser/ui/authentication/authentication_ui_util.h" 33 #import "ios/chrome/browser/ui/authentication/authentication_ui_util.h"
36 #import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h " 34 #import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h "
37 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" 35 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
38 #include "ios/chrome/grit/ios_chromium_strings.h" 36 #include "ios/chrome/grit/ios_chromium_strings.h"
39 #include "ios/chrome/grit/ios_strings.h" 37 #include "ios/chrome/grit/ios_strings.h"
40 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 38 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
41 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" 39 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
42 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
43 41
42 #if !defined(__has_feature) || !__has_feature(objc_arc)
43 #error "This file requires ARC support."
44 #endif
45
44 using signin_ui::CompletionCallback; 46 using signin_ui::CompletionCallback;
45 47
46 namespace { 48 namespace {
47 49
48 const int64_t kAuthenticationFlowTimeoutSeconds = 10; 50 const int64_t kAuthenticationFlowTimeoutSeconds = 10;
49 51
50 } // namespace 52 } // namespace
51 53
52 @interface AuthenticationFlowPerformer ()<ImportDataControllerDelegate, 54 @interface AuthenticationFlowPerformer ()<ImportDataControllerDelegate,
53 SettingsNavigationControllerDelegate> 55 SettingsNavigationControllerDelegate>
54 56
55 // Starts the watchdog timer with a timeout of 57 // Starts the watchdog timer with a timeout of
56 // |kAuthenticationFlowTimeoutSeconds| for the fetching managed status 58 // |kAuthenticationFlowTimeoutSeconds| for the fetching managed status
57 // operation. It will notify |_delegate| of the failure unless 59 // operation. It will notify |_delegate| of the failure unless
58 // |stopWatchdogTimer| is called before it times out. 60 // |stopWatchdogTimer| is called before it times out.
59 - (void)startWatchdogTimerForManagedStatus; 61 - (void)startWatchdogTimerForManagedStatus;
60 62
61 // Stops the watchdog timer, and doesn't call the |timeoutDelegateSelector|. 63 // Stops the watchdog timer, and doesn't call the |timeoutDelegateSelector|.
62 // Returns whether the watchdog was actually running. 64 // Returns whether the watchdog was actually running.
63 - (BOOL)stopWatchdogTimer; 65 - (BOOL)stopWatchdogTimer;
64 66
65 // Callback for when the alert is dismissed. 67 // Callback for when the alert is dismissed.
66 - (void)alertControllerDidDisappear:(AlertCoordinator*)alertCoordinator; 68 - (void)alertControllerDidDisappear:(AlertCoordinator*)alertCoordinator;
67 69
68 @end 70 @end
69 71
70 @implementation AuthenticationFlowPerformer { 72 @implementation AuthenticationFlowPerformer {
71 base::WeakNSProtocol<id<AuthenticationFlowPerformerDelegate>> _delegate; 73 __weak id<AuthenticationFlowPerformerDelegate> _delegate;
72 base::scoped_nsobject<AlertCoordinator> _alertCoordinator; 74 AlertCoordinator* _alertCoordinator;
73 base::scoped_nsobject<SettingsNavigationController> _navigationController; 75 SettingsNavigationController* _navigationController;
74 std::unique_ptr<base::Timer> _watchdogTimer; 76 std::unique_ptr<base::Timer> _watchdogTimer;
75 } 77 }
76 78
77 - (id<AuthenticationFlowPerformerDelegate>)delegate { 79 - (id<AuthenticationFlowPerformerDelegate>)delegate {
78 return _delegate.get(); 80 return _delegate;
79 } 81 }
80 82
81 - (instancetype)initWithDelegate: 83 - (instancetype)initWithDelegate:
82 (id<AuthenticationFlowPerformerDelegate>)delegate { 84 (id<AuthenticationFlowPerformerDelegate>)delegate {
83 self = [super init]; 85 self = [super init];
84 if (self) 86 if (self)
85 _delegate.reset(delegate); 87 _delegate = delegate;
86 return self; 88 return self;
87 } 89 }
88 90
89 - (void)cancelAndDismiss { 91 - (void)cancelAndDismiss {
90 [_alertCoordinator executeCancelHandler]; 92 [_alertCoordinator executeCancelHandler];
91 [_alertCoordinator stop]; 93 [_alertCoordinator stop];
92 if (_navigationController) { 94 if (_navigationController) {
93 [_navigationController settingsWillBeDismissed]; 95 [_navigationController settingsWillBeDismissed];
94 _navigationController.reset(); 96 _navigationController = nil;
95 [[_delegate presentingViewController] dismissViewControllerAnimated:NO 97 [[_delegate presentingViewController] dismissViewControllerAnimated:NO
96 completion:nil]; 98 completion:nil];
97 } 99 }
98 [self stopWatchdogTimer]; 100 [self stopWatchdogTimer];
99 } 101 }
100 102
101 - (void)commitSyncForBrowserState:(ios::ChromeBrowserState*)browserState { 103 - (void)commitSyncForBrowserState:(ios::ChromeBrowserState*)browserState {
102 SyncSetupServiceFactory::GetForBrowserState(browserState)->CommitChanges(); 104 SyncSetupServiceFactory::GetForBrowserState(browserState)->CommitChanges();
103 } 105 }
104 106
105 - (void)startWatchdogTimerForManagedStatus { 107 - (void)startWatchdogTimerForManagedStatus {
106 base::WeakNSObject<AuthenticationFlowPerformer> weakSelf(self); 108 __weak AuthenticationFlowPerformer* weakSelf = self;
107 ProceduralBlock onTimeout = ^{ 109 ProceduralBlock onTimeout = ^{
108 base::scoped_nsobject<AuthenticationFlowPerformer> strongSelf( 110 AuthenticationFlowPerformer* strongSelf = weakSelf;
109 [weakSelf retain]);
110 if (!strongSelf) 111 if (!strongSelf)
111 return; 112 return;
112 [strongSelf stopWatchdogTimer]; 113 [strongSelf stopWatchdogTimer];
113 NSError* error = [NSError errorWithDomain:kAuthenticationErrorDomain 114 NSError* error = [NSError errorWithDomain:kAuthenticationErrorDomain
114 code:TIMED_OUT_FETCH_POLICY 115 code:TIMED_OUT_FETCH_POLICY
115 userInfo:nil]; 116 userInfo:nil];
116 [strongSelf.get()->_delegate didFailFetchManagedStatus:error]; 117 [strongSelf->_delegate didFailFetchManagedStatus:error];
117 }; 118 };
118 _watchdogTimer.reset(new base::Timer(false, false)); 119 _watchdogTimer.reset(new base::Timer(false, false));
119 _watchdogTimer->Start(FROM_HERE, base::TimeDelta::FromSeconds( 120 _watchdogTimer->Start(
120 kAuthenticationFlowTimeoutSeconds), 121 FROM_HERE,
121 base::BindBlock(onTimeout)); 122 base::TimeDelta::FromSeconds(kAuthenticationFlowTimeoutSeconds),
123 base::BindBlockArc(onTimeout));
122 } 124 }
123 125
124 - (BOOL)stopWatchdogTimer { 126 - (BOOL)stopWatchdogTimer {
125 if (_watchdogTimer) { 127 if (_watchdogTimer) {
126 _watchdogTimer->Stop(); 128 _watchdogTimer->Stop();
127 _watchdogTimer.reset(); 129 _watchdogTimer.reset();
128 return YES; 130 return YES;
129 } 131 }
130 return NO; 132 return NO;
131 } 133 }
132 134
133 - (void)fetchManagedStatus:(ios::ChromeBrowserState*)browserState 135 - (void)fetchManagedStatus:(ios::ChromeBrowserState*)browserState
134 forIdentity:(ChromeIdentity*)identity { 136 forIdentity:(ChromeIdentity*)identity {
135 if (!experimental_flags::IsMDMIntegrationEnabled()) { 137 if (!experimental_flags::IsMDMIntegrationEnabled()) {
136 [_delegate didFetchManagedStatus:nil]; 138 [_delegate didFetchManagedStatus:nil];
137 return; 139 return;
138 } 140 }
139 if (gaia::ExtractDomainName(gaia::CanonicalizeEmail( 141 if (gaia::ExtractDomainName(gaia::CanonicalizeEmail(
140 base::SysNSStringToUTF8(identity.userEmail))) == "gmail.com") { 142 base::SysNSStringToUTF8(identity.userEmail))) == "gmail.com") {
141 // Do nothing for @gmail.com addresses as they can't have a hosted domain. 143 // Do nothing for @gmail.com addresses as they can't have a hosted domain.
142 // This avoids waiting for this step to complete (and a network call). 144 // This avoids waiting for this step to complete (and a network call).
143 [_delegate didFetchManagedStatus:nil]; 145 [_delegate didFetchManagedStatus:nil];
144 return; 146 return;
145 } 147 }
146 148
147 [self startWatchdogTimerForManagedStatus]; 149 [self startWatchdogTimerForManagedStatus];
148 base::WeakNSObject<AuthenticationFlowPerformer> weakSelf(self); 150 __weak AuthenticationFlowPerformer* weakSelf = self;
149 ios::GetChromeBrowserProvider() 151 ios::GetChromeBrowserProvider()
150 ->GetChromeIdentityService() 152 ->GetChromeIdentityService()
151 ->GetHostedDomainForIdentity( 153 ->GetHostedDomainForIdentity(
152 identity, ^(NSString* hosted_domain, NSError* error) { 154 identity, ^(NSString* hosted_domain, NSError* error) {
153 [weakSelf handleGetHostedDomain:hosted_domain 155 [weakSelf handleGetHostedDomain:hosted_domain
154 error:error 156 error:error
155 browserState:browserState]; 157 browserState:browserState];
156 }); 158 });
157 } 159 }
158 160
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 DCHECK(!_alertCoordinator); 199 DCHECK(!_alertCoordinator);
198 NSString* title = l10n_util::GetNSString(IDS_IOS_MANAGED_SWITCH_TITLE); 200 NSString* title = l10n_util::GetNSString(IDS_IOS_MANAGED_SWITCH_TITLE);
199 NSString* subtitle = l10n_util::GetNSStringF( 201 NSString* subtitle = l10n_util::GetNSStringF(
200 IDS_IOS_MANAGED_SWITCH_SUBTITLE, base::SysNSStringToUTF16(managedEmail), 202 IDS_IOS_MANAGED_SWITCH_SUBTITLE, base::SysNSStringToUTF16(managedEmail),
201 base::SysNSStringToUTF16(toEmail), 203 base::SysNSStringToUTF16(toEmail),
202 base::SysNSStringToUTF16(hostedDomain)); 204 base::SysNSStringToUTF16(hostedDomain));
203 NSString* acceptLabel = 205 NSString* acceptLabel =
204 l10n_util::GetNSString(IDS_IOS_MANAGED_SWITCH_ACCEPT_BUTTON); 206 l10n_util::GetNSString(IDS_IOS_MANAGED_SWITCH_ACCEPT_BUTTON);
205 NSString* cancelLabel = l10n_util::GetNSString(IDS_CANCEL); 207 NSString* cancelLabel = l10n_util::GetNSString(IDS_CANCEL);
206 208
207 _alertCoordinator.reset([[AlertCoordinator alloc] 209 _alertCoordinator =
208 initWithBaseViewController:viewController 210 [[AlertCoordinator alloc] initWithBaseViewController:viewController
209 title:title 211 title:title
210 message:subtitle]); 212 message:subtitle];
211 213
212 base::WeakNSObject<AuthenticationFlowPerformer> weakSelf(self); 214 __weak AuthenticationFlowPerformer* weakSelf = self;
213 base::WeakNSObject<AlertCoordinator> weakAlert(_alertCoordinator); 215 __weak AlertCoordinator* weakAlert = _alertCoordinator;
214 ProceduralBlock acceptBlock = ^{ 216 ProceduralBlock acceptBlock = ^{
215 base::scoped_nsobject<AuthenticationFlowPerformer> strongSelf( 217 AuthenticationFlowPerformer* strongSelf = weakSelf;
216 [weakSelf retain]);
217 if (!strongSelf) 218 if (!strongSelf)
218 return; 219 return;
219 [[strongSelf delegate] 220 [[strongSelf delegate]
220 didChooseClearDataPolicy:SHOULD_CLEAR_DATA_CLEAR_DATA]; 221 didChooseClearDataPolicy:SHOULD_CLEAR_DATA_CLEAR_DATA];
221 [strongSelf alertControllerDidDisappear:weakAlert]; 222 [strongSelf alertControllerDidDisappear:weakAlert];
222 }; 223 };
223 ProceduralBlock cancelBlock = ^{ 224 ProceduralBlock cancelBlock = ^{
224 base::scoped_nsobject<AuthenticationFlowPerformer> strongSelf( 225 AuthenticationFlowPerformer* strongSelf = weakSelf;
225 [weakSelf retain]);
226 if (!strongSelf) 226 if (!strongSelf)
227 return; 227 return;
228 [[strongSelf delegate] didChooseCancel]; 228 [[strongSelf delegate] didChooseCancel];
229 [strongSelf alertControllerDidDisappear:weakAlert]; 229 [strongSelf alertControllerDidDisappear:weakAlert];
230 }; 230 };
231 231
232 [_alertCoordinator addItemWithTitle:cancelLabel 232 [_alertCoordinator addItemWithTitle:cancelLabel
233 action:cancelBlock 233 action:cancelBlock
234 style:UIAlertActionStyleCancel]; 234 style:UIAlertActionStyleCancel];
235 [_alertCoordinator addItemWithTitle:acceptLabel 235 [_alertCoordinator addItemWithTitle:acceptLabel
(...skipping 22 matching lines...) Expand all
258 NSString* hostedDomain = base::SysUTF8ToNSString( 258 NSString* hostedDomain = base::SysUTF8ToNSString(
259 ios::SigninManagerFactory::GetForBrowserState(browserState) 259 ios::SigninManagerFactory::GetForBrowserState(browserState)
260 ->GetAuthenticatedAccountInfo() 260 ->GetAuthenticatedAccountInfo()
261 .hosted_domain); 261 .hosted_domain);
262 [self promptSwitchFromManagedEmail:lastSignedInEmail 262 [self promptSwitchFromManagedEmail:lastSignedInEmail
263 withHostedDomain:hostedDomain 263 withHostedDomain:hostedDomain
264 toEmail:[identity userEmail] 264 toEmail:[identity userEmail]
265 viewController:viewController]; 265 viewController:viewController];
266 return; 266 return;
267 } 267 }
268 _navigationController.reset([SettingsNavigationController 268 _navigationController =
269 newImportDataController:browserState 269 [SettingsNavigationController newImportDataController:browserState
270 delegate:self 270 delegate:self
271 importDataDelegate:self 271 importDataDelegate:self
272 fromEmail:lastSignedInEmail 272 fromEmail:lastSignedInEmail
273 toEmail:[identity userEmail] 273 toEmail:[identity userEmail]
274 isSignedIn:isSignedIn]); 274 isSignedIn:isSignedIn];
275 [_navigationController setShouldCommitSyncChangesOnDismissal:NO]; 275 [_navigationController setShouldCommitSyncChangesOnDismissal:NO];
276 [[_delegate presentingViewController] 276 [[_delegate presentingViewController]
277 presentViewController:_navigationController 277 presentViewController:_navigationController
278 animated:YES 278 animated:YES
279 completion:nil]; 279 completion:nil];
280 } 280 }
281 281
282 - (void)clearData:(ios::ChromeBrowserState*)browserState { 282 - (void)clearData:(ios::ChromeBrowserState*)browserState {
283 DCHECK(!AuthenticationServiceFactory::GetForBrowserState(browserState) 283 DCHECK(!AuthenticationServiceFactory::GetForBrowserState(browserState)
284 ->GetAuthenticatedUserEmail()); 284 ->GetAuthenticatedUserEmail());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 viewController: 317 viewController:
318 (UIViewController*)viewController { 318 (UIViewController*)viewController {
319 DCHECK(!_alertCoordinator); 319 DCHECK(!_alertCoordinator);
320 NSString* title = l10n_util::GetNSString(IDS_IOS_MANAGED_SIGNIN_TITLE); 320 NSString* title = l10n_util::GetNSString(IDS_IOS_MANAGED_SIGNIN_TITLE);
321 NSString* subtitle = l10n_util::GetNSStringF( 321 NSString* subtitle = l10n_util::GetNSStringF(
322 IDS_IOS_MANAGED_SIGNIN_SUBTITLE, base::SysNSStringToUTF16(hostedDomain)); 322 IDS_IOS_MANAGED_SIGNIN_SUBTITLE, base::SysNSStringToUTF16(hostedDomain));
323 NSString* acceptLabel = 323 NSString* acceptLabel =
324 l10n_util::GetNSString(IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON); 324 l10n_util::GetNSString(IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON);
325 NSString* cancelLabel = l10n_util::GetNSString(IDS_CANCEL); 325 NSString* cancelLabel = l10n_util::GetNSString(IDS_CANCEL);
326 326
327 _alertCoordinator.reset([[AlertCoordinator alloc] 327 _alertCoordinator =
328 initWithBaseViewController:viewController 328 [[AlertCoordinator alloc] initWithBaseViewController:viewController
329 title:title 329 title:title
330 message:subtitle]); 330 message:subtitle];
331 331
332 base::WeakNSObject<AuthenticationFlowPerformer> weakSelf(self); 332 __weak AuthenticationFlowPerformer* weakSelf = self;
333 base::WeakNSObject<AlertCoordinator> weakAlert(_alertCoordinator); 333 __weak AlertCoordinator* weakAlert = _alertCoordinator;
334 ProceduralBlock acceptBlock = ^{ 334 ProceduralBlock acceptBlock = ^{
335 base::scoped_nsobject<AuthenticationFlowPerformer> strongSelf( 335 AuthenticationFlowPerformer* strongSelf = weakSelf;
336 [weakSelf retain]);
337 if (!strongSelf) 336 if (!strongSelf)
338 return; 337 return;
339 [[strongSelf delegate] didAcceptManagedConfirmation]; 338 [[strongSelf delegate] didAcceptManagedConfirmation];
340 [strongSelf alertControllerDidDisappear:weakAlert]; 339 [strongSelf alertControllerDidDisappear:weakAlert];
341 }; 340 };
342 ProceduralBlock cancelBlock = ^{ 341 ProceduralBlock cancelBlock = ^{
343 base::scoped_nsobject<AuthenticationFlowPerformer> strongSelf( 342 AuthenticationFlowPerformer* strongSelf = weakSelf;
344 [weakSelf retain]);
345 if (!strongSelf) 343 if (!strongSelf)
346 return; 344 return;
347 [[strongSelf delegate] didCancelManagedConfirmation]; 345 [[strongSelf delegate] didCancelManagedConfirmation];
348 [strongSelf alertControllerDidDisappear:weakAlert]; 346 [strongSelf alertControllerDidDisappear:weakAlert];
349 }; 347 };
350 348
351 [_alertCoordinator addItemWithTitle:cancelLabel 349 [_alertCoordinator addItemWithTitle:cancelLabel
352 action:cancelBlock 350 action:cancelBlock
353 style:UIAlertActionStyleCancel]; 351 style:UIAlertActionStyleCancel];
354 [_alertCoordinator addItemWithTitle:acceptLabel 352 [_alertCoordinator addItemWithTitle:acceptLabel
355 action:acceptBlock 353 action:acceptBlock
356 style:UIAlertActionStyleDefault]; 354 style:UIAlertActionStyleDefault];
357 [_alertCoordinator setCancelAction:cancelBlock]; 355 [_alertCoordinator setCancelAction:cancelBlock];
358 [_alertCoordinator start]; 356 [_alertCoordinator start];
359 } 357 }
360 358
361 - (void)showAuthenticationError:(NSError*)error 359 - (void)showAuthenticationError:(NSError*)error
362 withCompletion:(ProceduralBlock)callback 360 withCompletion:(ProceduralBlock)callback
363 viewController:(UIViewController*)viewController { 361 viewController:(UIViewController*)viewController {
364 DCHECK(!_alertCoordinator); 362 DCHECK(!_alertCoordinator);
365 363
366 _alertCoordinator.reset( 364 _alertCoordinator =
367 [ios_internal::ErrorCoordinatorNoItem(error, viewController) retain]); 365 ios_internal::ErrorCoordinatorNoItem(error, viewController);
368 366
369 base::WeakNSObject<AuthenticationFlowPerformer> weakSelf(self); 367 __weak AuthenticationFlowPerformer* weakSelf = self;
370 base::WeakNSObject<AlertCoordinator> weakAlert(_alertCoordinator); 368 __weak AlertCoordinator* weakAlert = _alertCoordinator;
371 ProceduralBlock dismissAction = ^{ 369 ProceduralBlock dismissAction = ^{
372 if (callback) 370 if (callback)
373 callback(); 371 callback();
374 [weakSelf alertControllerDidDisappear:weakAlert]; 372 [weakSelf alertControllerDidDisappear:weakAlert];
375 }; 373 };
376 374
377 NSString* okButtonLabel = l10n_util::GetNSString(IDS_OK); 375 NSString* okButtonLabel = l10n_util::GetNSString(IDS_OK);
378 [_alertCoordinator addItemWithTitle:okButtonLabel 376 [_alertCoordinator addItemWithTitle:okButtonLabel
379 action:dismissAction 377 action:dismissAction
380 style:UIAlertActionStyleDefault]; 378 style:UIAlertActionStyleDefault];
381 379
382 [_alertCoordinator setCancelAction:dismissAction]; 380 [_alertCoordinator setCancelAction:dismissAction];
383 381
384 [_alertCoordinator start]; 382 [_alertCoordinator start];
385 } 383 }
386 384
387 - (void)alertControllerDidDisappear:(AlertCoordinator*)alertCoordinator { 385 - (void)alertControllerDidDisappear:(AlertCoordinator*)alertCoordinator {
388 if (_alertCoordinator.get() != alertCoordinator) { 386 if (_alertCoordinator != alertCoordinator) {
389 // Do not reset the |_alertCoordinator| if it has changed. This typically 387 // Do not reset the |_alertCoordinator| if it has changed. This typically
390 // happens when the user taps on any of the actions on "Clear Data Before 388 // happens when the user taps on any of the actions on "Clear Data Before
391 // Syncing?" dialog, as the sign-in confirmation dialog is created before 389 // Syncing?" dialog, as the sign-in confirmation dialog is created before
392 // the "Clear Data Before Syncing?" dialog is dismissed. 390 // the "Clear Data Before Syncing?" dialog is dismissed.
393 return; 391 return;
394 } 392 }
395 _alertCoordinator.reset(); 393 _alertCoordinator = nil;
396 } 394 }
397 395
398 #pragma mark - ImportDataControllerDelegate 396 #pragma mark - ImportDataControllerDelegate
399 397
400 - (void)didChooseClearDataPolicy:(ImportDataCollectionViewController*)controller 398 - (void)didChooseClearDataPolicy:(ImportDataCollectionViewController*)controller
401 shouldClearData:(ShouldClearData)shouldClearData { 399 shouldClearData:(ShouldClearData)shouldClearData {
402 DCHECK_NE(SHOULD_CLEAR_DATA_USER_CHOICE, shouldClearData); 400 DCHECK_NE(SHOULD_CLEAR_DATA_USER_CHOICE, shouldClearData);
403 if (shouldClearData == SHOULD_CLEAR_DATA_CLEAR_DATA) { 401 if (shouldClearData == SHOULD_CLEAR_DATA_CLEAR_DATA) {
404 base::RecordAction( 402 base::RecordAction(
405 base::UserMetricsAction("Signin_ImportDataPrompt_DontImport")); 403 base::UserMetricsAction("Signin_ImportDataPrompt_DontImport"));
406 } else { 404 } else {
407 base::RecordAction( 405 base::RecordAction(
408 base::UserMetricsAction("Signin_ImportDataPrompt_ImportData")); 406 base::UserMetricsAction("Signin_ImportDataPrompt_ImportData"));
409 } 407 }
410 408
411 base::WeakNSObject<AuthenticationFlowPerformer> weakSelf(self); 409 __weak AuthenticationFlowPerformer* weakSelf = self;
412 ProceduralBlock block = ^{ 410 ProceduralBlock block = ^{
413 base::scoped_nsobject<AuthenticationFlowPerformer> strongSelf( 411 AuthenticationFlowPerformer* strongSelf = weakSelf;
414 [weakSelf retain]);
415 if (!strongSelf) 412 if (!strongSelf)
416 return; 413 return;
417 strongSelf.get()->_navigationController.reset(); 414 strongSelf->_navigationController = nil;
418 [[strongSelf delegate] didChooseClearDataPolicy:shouldClearData]; 415 [[strongSelf delegate] didChooseClearDataPolicy:shouldClearData];
419 }; 416 };
420 [_navigationController settingsWillBeDismissed]; 417 [_navigationController settingsWillBeDismissed];
421 [[_delegate presentingViewController] dismissViewControllerAnimated:YES 418 [[_delegate presentingViewController] dismissViewControllerAnimated:YES
422 completion:block]; 419 completion:block];
423 } 420 }
424 421
425 #pragma mark - SettingsNavigationControllerDelegate 422 #pragma mark - SettingsNavigationControllerDelegate
426 423
427 - (void)closeSettings { 424 - (void)closeSettings {
428 base::RecordAction(base::UserMetricsAction("Signin_ImportDataPrompt_Cancel")); 425 base::RecordAction(base::UserMetricsAction("Signin_ImportDataPrompt_Cancel"));
429 426
430 base::WeakNSObject<AuthenticationFlowPerformer> weakSelf(self); 427 __weak AuthenticationFlowPerformer* weakSelf = self;
431 ProceduralBlock block = ^{ 428 ProceduralBlock block = ^{
432 base::scoped_nsobject<AuthenticationFlowPerformer> strongSelf( 429 AuthenticationFlowPerformer* strongSelf = weakSelf;
433 [weakSelf retain]);
434 if (!strongSelf) 430 if (!strongSelf)
435 return; 431 return;
436 strongSelf.get()->_navigationController.reset(); 432 strongSelf->_navigationController = nil;
437 [[strongSelf delegate] didChooseCancel]; 433 [[strongSelf delegate] didChooseCancel];
438 }; 434 };
439 [_navigationController settingsWillBeDismissed]; 435 [_navigationController settingsWillBeDismissed];
440 [[_delegate presentingViewController] dismissViewControllerAnimated:YES 436 [[_delegate presentingViewController] dismissViewControllerAnimated:YES
441 completion:block]; 437 completion:block];
442 } 438 }
443 439
444 - (void)closeSettingsAndOpenNewIncognitoTab { 440 - (void)closeSettingsAndOpenNewIncognitoTab {
445 NOTREACHED(); 441 NOTREACHED();
446 } 442 }
447 443
448 - (void)closeSettingsAndOpenUrl:(OpenUrlCommand*)command { 444 - (void)closeSettingsAndOpenUrl:(OpenUrlCommand*)command {
449 NOTREACHED(); 445 NOTREACHED();
450 } 446 }
451 447
452 @end 448 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698