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

Side by Side Diff: ios/public/provider/chrome/browser/signin/fake_chrome_identity_interaction_manager.mm

Issue 2930303002: [ObjC ARC] Converts ios/chrome/browser/signin:test_support to ARC. (Closed)
Patch Set: [ObjC ARC] Converts ios/public/provider/chrome/browser/signin:test_support to ARC. 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/public/provider/chrome/browser/signin/fake_chrome_identity_interact ion_manager.h" 5 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_interact ion_manager.h"
6 6
7 #include "base/mac/scoped_block.h" 7 #include "base/mac/scoped_block.h"
8 #include "base/mac/scoped_nsobject.h"
9 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" 8 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
10 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h" 9 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h"
11 #include "ios/public/provider/chrome/browser/signin/signin_error_provider.h" 10 #include "ios/public/provider/chrome/browser/signin/signin_error_provider.h"
12 11
13 @interface FakeAddAccountViewController : UIViewController { 12 @interface FakeAddAccountViewController : UIViewController {
14 FakeChromeIdentityInteractionManager* _manager; // Weak. 13 FakeChromeIdentityInteractionManager* _manager; // Weak.
15 base::scoped_nsobject<UIButton> _cancelButton; 14 UIButton* _cancelButton;
16 base::scoped_nsobject<UIButton> _signInButton; 15 UIButton* _signInButton;
17 } 16 }
18 @end 17 @end
19 18
20 @interface FakeChromeIdentityInteractionManager () { 19 @interface FakeChromeIdentityInteractionManager () {
21 base::mac::ScopedBlock<SigninCompletionCallback> _completionCallback; 20 SigninCompletionCallback _completionCallback;
22 base::scoped_nsobject<UIViewController> _viewController; 21 UIViewController* _viewController;
23 BOOL _isCanceling; 22 BOOL _isCanceling;
24 } 23 }
25 24
26 - (void)addAccountViewControllerDidTapSignIn:(FakeAddAccountViewController*)vc; 25 - (void)addAccountViewControllerDidTapSignIn:(FakeAddAccountViewController*)vc;
27 26
28 - (void)addAccountViewControllerDidTapCancel:(FakeAddAccountViewController*)vc; 27 - (void)addAccountViewControllerDidTapCancel:(FakeAddAccountViewController*)vc;
29 28
30 @end 29 @end
31 30
32 @implementation FakeAddAccountViewController 31 @implementation FakeAddAccountViewController
(...skipping 16 matching lines...) Expand all
49 forControlEvents:UIControlEventTouchUpInside]; 48 forControlEvents:UIControlEventTouchUpInside];
50 [super dealloc]; 49 [super dealloc];
51 } 50 }
52 51
53 - (void)viewDidLoad { 52 - (void)viewDidLoad {
54 [super viewDidLoad]; 53 [super viewDidLoad];
55 54
56 // Obnoxious color, this is a test screen. 55 // Obnoxious color, this is a test screen.
57 self.view.backgroundColor = [UIColor magentaColor]; 56 self.view.backgroundColor = [UIColor magentaColor];
58 57
59 _signInButton.reset([[UIButton buttonWithType:UIButtonTypeCustom] retain]); 58 _signInButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
60 [_signInButton setTitle:@"Sign in" forState:UIControlStateNormal]; 59 [_signInButton setTitle:@"Sign in" forState:UIControlStateNormal];
61 [_signInButton addTarget:self 60 [_signInButton addTarget:self
62 action:@selector(didTapSignIn:) 61 action:@selector(didTapSignIn:)
63 forControlEvents:UIControlEventTouchUpInside]; 62 forControlEvents:UIControlEventTouchUpInside];
64 [self.view addSubview:_signInButton]; 63 [self.view addSubview:_signInButton];
65 64
66 _cancelButton.reset([[UIButton buttonWithType:UIButtonTypeCustom] retain]); 65 _cancelButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
67 [_cancelButton setTitle:@"Cancel" forState:UIControlStateNormal]; 66 [_cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
68 [_cancelButton setAccessibilityIdentifier:@"cancel"]; 67 [_cancelButton setAccessibilityIdentifier:@"cancel"];
69 [_cancelButton addTarget:self 68 [_cancelButton addTarget:self
70 action:@selector(didTapCancel:) 69 action:@selector(didTapCancel:)
71 forControlEvents:UIControlEventTouchUpInside]; 70 forControlEvents:UIControlEventTouchUpInside];
72 [self.view addSubview:_cancelButton]; 71 [self.view addSubview:_cancelButton];
73 } 72 }
74 73
75 - (void)viewWillLayoutSubviews { 74 - (void)viewWillLayoutSubviews {
76 [super viewWillLayoutSubviews]; 75 [super viewWillLayoutSubviews];
(...skipping 19 matching lines...) Expand all
96 95
97 @implementation FakeChromeIdentityInteractionManager 96 @implementation FakeChromeIdentityInteractionManager
98 97
99 @synthesize fakeIdentity = _fakeIdentity; 98 @synthesize fakeIdentity = _fakeIdentity;
100 99
101 - (BOOL)isCanceling { 100 - (BOOL)isCanceling {
102 return _isCanceling; 101 return _isCanceling;
103 } 102 }
104 103
105 - (void)addAccountWithCompletion:(SigninCompletionCallback)completion { 104 - (void)addAccountWithCompletion:(SigninCompletionCallback)completion {
106 _completionCallback.reset(completion, base::scoped_policy::RETAIN); 105 _completionCallback = [completion copy];
107 _viewController.reset( 106 _viewController =
108 [[FakeAddAccountViewController alloc] initWithInteractionManager:self]); 107 [[FakeAddAccountViewController alloc] initWithInteractionManager:self];
109 [self.delegate interactionManager:self 108 [self.delegate interactionManager:self
110 presentViewController:_viewController 109 presentViewController:_viewController
111 animated:YES 110 animated:YES
112 completion:nil]; 111 completion:nil];
113 } 112 }
114 113
115 - (void)reauthenticateUserWithID:(NSString*)userID 114 - (void)reauthenticateUserWithID:(NSString*)userID
116 email:(NSString*)userEmail 115 email:(NSString*)userEmail
117 completion:(SigninCompletionCallback)completion { 116 completion:(SigninCompletionCallback)completion {
118 [self addAccountWithCompletion:completion]; 117 [self addAccountWithCompletion:completion];
(...skipping 26 matching lines...) Expand all
145 return; 144 return;
146 } 145 }
147 [self.delegate interactionManager:self 146 [self.delegate interactionManager:self
148 dismissViewControllerAnimated:animated 147 dismissViewControllerAnimated:animated
149 completion:^{ 148 completion:^{
150 [self runCompletionCallbackWithError:error]; 149 [self runCompletionCallbackWithError:error];
151 }]; 150 }];
152 } 151 }
153 152
154 - (void)runCompletionCallbackWithError:(NSError*)error { 153 - (void)runCompletionCallbackWithError:(NSError*)error {
155 _viewController.reset(); 154 _viewController = nil;
156 if (_completionCallback) { 155 if (_completionCallback) {
157 // Ensure self is not destroyed in the callback. 156 // Ensure self is not destroyed in the callback.
158 base::scoped_nsobject<FakeChromeIdentityInteractionManager> strongSelf( 157 #pragma clang diagnostic push
159 [self retain]); 158 #pragma clang diagnostic ignored "-Wunused-variable"
160 _completionCallback.get()(error ? nil : _fakeIdentity, error); 159 FakeChromeIdentityInteractionManager* strongSelf = self;
161 _completionCallback.reset(); 160 #pragma clang diagnostic pop
161 _completionCallback(error ? nil : _fakeIdentity, error);
162 _completionCallback = nil;
162 } 163 }
163 } 164 }
164 165
165 - (NSError*)canceledError { 166 - (NSError*)canceledError {
166 ios::SigninErrorProvider* provider = 167 ios::SigninErrorProvider* provider =
167 ios::GetChromeBrowserProvider()->GetSigninErrorProvider(); 168 ios::GetChromeBrowserProvider()->GetSigninErrorProvider();
168 return [NSError errorWithDomain:provider->GetSigninErrorDomain() 169 return [NSError errorWithDomain:provider->GetSigninErrorDomain()
169 code:provider->GetCode(ios::SigninError::CANCELED) 170 code:provider->GetCode(ios::SigninError::CANCELED)
170 userInfo:nil]; 171 userInfo:nil];
171 } 172 }
172 173
173 @end 174 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698