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

Side by Side Diff: ios/chrome/browser/payments/payment_method_selection_coordinator.mm

Issue 2710493006: [ObjC ARC] Converts ios/chrome/browser/payments:payments to ARC. (Closed)
Patch Set: fixes compilation by reintroducing formal declaration of designated initializer Created 3 years, 10 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/chrome/browser/payments/payment_method_selection_coordinator.h" 5 #import "ios/chrome/browser/payments/payment_method_selection_coordinator.h"
6 6
7 #import "base/ios/weak_nsobject.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "components/autofill/core/browser/credit_card.h" 7 #include "components/autofill/core/browser/credit_card.h"
10 #include "ios/chrome/browser/payments/payment_request.h" 8 #include "ios/chrome/browser/payments/payment_request.h"
11 9
12 @interface PaymentMethodSelectionCoordinator () { 10 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 base::WeakNSProtocol<id<PaymentMethodSelectionCoordinatorDelegate>> _delegate; 11 #error "This file requires ARC support."
14 base::scoped_nsobject<PaymentMethodSelectionViewController> _viewController; 12 #endif
15 } 13
14 @interface PaymentMethodSelectionCoordinator ()
15 @property(nonatomic, strong)
16 PaymentMethodSelectionViewController* viewController;
16 17
17 // Called when the user selects a payment method. The cell is checked, the 18 // Called when the user selects a payment method. The cell is checked, the
18 // UI is locked so that the user can't interact with it, then the delegate is 19 // UI is locked so that the user can't interact with it, then the delegate is
19 // notified. The delay is here to let the user get a visual feedback of the 20 // notified. The delay is here to let the user get a visual feedback of the
20 // selection before this view disappears. 21 // selection before this view disappears.
21 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod; 22 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod;
22 23
23 @end 24 @end
24 25
25 @implementation PaymentMethodSelectionCoordinator 26 @implementation PaymentMethodSelectionCoordinator
26
27 @synthesize paymentRequest = _paymentRequest; 27 @synthesize paymentRequest = _paymentRequest;
28 28 @synthesize delegate = _delegate;
29 - (id<PaymentMethodSelectionCoordinatorDelegate>)delegate { 29 @synthesize viewController = _viewController;
30 return _delegate.get();
31 }
32
33 - (void)setDelegate:(id<PaymentMethodSelectionCoordinatorDelegate>)delegate {
34 _delegate.reset(delegate);
35 }
36 30
37 - (void)start { 31 - (void)start {
38 _viewController.reset([[PaymentMethodSelectionViewController alloc] 32 _viewController = [[PaymentMethodSelectionViewController alloc]
39 initWithPaymentRequest:_paymentRequest]); 33 initWithPaymentRequest:_paymentRequest];
40 [_viewController setDelegate:self]; 34 [_viewController setDelegate:self];
41 [_viewController loadModel]; 35 [_viewController loadModel];
42 36
43 DCHECK([self baseViewController].navigationController); 37 DCHECK([self baseViewController].navigationController);
44 [[self baseViewController].navigationController 38 [[self baseViewController].navigationController
45 pushViewController:_viewController 39 pushViewController:_viewController
46 animated:YES]; 40 animated:YES];
47 } 41 }
48 42
49 - (void)stop { 43 - (void)stop {
50 [[self baseViewController].navigationController 44 [[self baseViewController].navigationController
51 popViewControllerAnimated:YES]; 45 popViewControllerAnimated:YES];
52 _viewController.reset(); 46 _viewController = nil;
53 } 47 }
54 48
55 #pragma mark - PaymentMethodSelectionViewControllerDelegate 49 #pragma mark - PaymentMethodSelectionViewControllerDelegate
56 50
57 - (void)paymentMethodSelectionViewController: 51 - (void)paymentMethodSelectionViewController:
58 (PaymentMethodSelectionViewController*)controller 52 (PaymentMethodSelectionViewController*)controller
59 didSelectPaymentMethod: 53 didSelectPaymentMethod:
60 (autofill::CreditCard*)paymentMethod { 54 (autofill::CreditCard*)paymentMethod {
61 [self delayedNotifyDelegateOfSelection:paymentMethod]; 55 [self delayedNotifyDelegateOfSelection:paymentMethod];
62 } 56 }
63 57
64 - (void)paymentMethodSelectionViewControllerDidReturn: 58 - (void)paymentMethodSelectionViewControllerDidReturn:
65 (PaymentMethodSelectionViewController*)controller { 59 (PaymentMethodSelectionViewController*)controller {
66 [_delegate paymentMethodSelectionCoordinatorDidReturn:self]; 60 [_delegate paymentMethodSelectionCoordinatorDidReturn:self];
67 } 61 }
68 62
69 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod { 63 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod {
70 _viewController.get().view.userInteractionEnabled = NO; 64 _viewController.view.userInteractionEnabled = NO;
71 base::WeakNSObject<PaymentMethodSelectionCoordinator> weakSelf(self); 65 __weak PaymentMethodSelectionCoordinator* weakSelf = self;
72 dispatch_after( 66 dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
73 dispatch_time(DISPATCH_TIME_NOW, 67 static_cast<int64_t>(0.2 * NSEC_PER_SEC)),
74 static_cast<int64_t>(0.2 * NSEC_PER_SEC)), 68 dispatch_get_main_queue(), ^{
75 dispatch_get_main_queue(), ^{ 69 PaymentMethodSelectionCoordinator* strongSelf = weakSelf;
76 base::scoped_nsobject<PaymentMethodSelectionCoordinator> strongSelf( 70 // Early return if the coordinator has been deallocated.
77 [weakSelf retain]); 71 if (!strongSelf)
marq (ping after 24h) 2017/02/22 11:55:58 Nit: No need to early return here.
stkhapugin 2017/02/22 17:47:06 Done.
78 // Early return if the coordinator has been deallocated. 72 return;
79 if (!strongSelf)
80 return;
81 73
82 _viewController.get().view.userInteractionEnabled = YES; 74 strongSelf.viewController.view.userInteractionEnabled = YES;
83 [_delegate paymentMethodSelectionCoordinator:self 75 [strongSelf.delegate
84 didSelectPaymentMethod:paymentMethod]; 76 paymentMethodSelectionCoordinator:strongSelf
85 }); 77 didSelectPaymentMethod:paymentMethod];
78 });
86 } 79 }
87 80
88 @end 81 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698