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

Side by Side Diff: ios/chrome/browser/ui/settings/autofill_collection_view_controller.mm

Issue 2815513008: [ObjC ARC] Converts ios/chrome/browser/ui/settings:settings_arc to ARC. (Closed)
Patch Set: Removes accidental retain from another CL Created 3 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/settings/autofill_collection_view_controller.h" 5 #import "ios/chrome/browser/ui/settings/autofill_collection_view_controller.h"
6 6
7 #import "base/ios/weak_nsobject.h"
8 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
9 #import "base/mac/objc_property_releaser.h"
10 #import "base/mac/scoped_nsobject.h"
11 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
12 #include "components/autofill/core/browser/personal_data_manager.h" 9 #include "components/autofill/core/browser/personal_data_manager.h"
13 #include "components/autofill/core/common/autofill_pref_names.h" 10 #include "components/autofill/core/common/autofill_pref_names.h"
14 #import "components/autofill/ios/browser/credit_card_util.h" 11 #import "components/autofill/ios/browser/credit_card_util.h"
15 #import "components/autofill/ios/browser/personal_data_manager_observer_bridge.h " 12 #import "components/autofill/ios/browser/personal_data_manager_observer_bridge.h "
16 #include "components/prefs/pref_service.h" 13 #include "components/prefs/pref_service.h"
17 #include "ios/chrome/browser/application_context.h" 14 #include "ios/chrome/browser/application_context.h"
18 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" 15 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 16 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
20 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 17 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h" 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h"
22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
23 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 20 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
24 #import "ios/chrome/browser/ui/settings/autofill_credit_card_edit_collection_vie w_controller.h" 21 #import "ios/chrome/browser/ui/settings/autofill_credit_card_edit_collection_vie w_controller.h"
25 #import "ios/chrome/browser/ui/settings/autofill_profile_edit_collection_view_co ntroller.h" 22 #import "ios/chrome/browser/ui/settings/autofill_profile_edit_collection_view_co ntroller.h"
26 #import "ios/chrome/browser/ui/settings/cells/autofill_data_item.h" 23 #import "ios/chrome/browser/ui/settings/cells/autofill_data_item.h"
27 #include "ios/chrome/grit/ios_strings.h" 24 #include "ios/chrome/grit/ios_strings.h"
28 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 25 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
29 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
30 27
28 #if !defined(__has_feature) || !__has_feature(objc_arc)
29 #error "This file requires ARC support."
30 #endif
31
31 namespace { 32 namespace {
32 33
33 typedef NS_ENUM(NSInteger, SectionIdentifier) { 34 typedef NS_ENUM(NSInteger, SectionIdentifier) {
34 SectionIdentifierSwitches = kSectionIdentifierEnumZero, 35 SectionIdentifierSwitches = kSectionIdentifierEnumZero,
35 SectionIdentifierProfiles, 36 SectionIdentifierProfiles,
36 SectionIdentifierCards, 37 SectionIdentifierCards,
37 }; 38 };
38 39
39 typedef NS_ENUM(NSInteger, ItemType) { 40 typedef NS_ENUM(NSInteger, ItemType) {
40 ItemTypeAutofillSwitch = kItemTypeEnumZero, 41 ItemTypeAutofillSwitch = kItemTypeEnumZero,
41 ItemTypeWalletSwitch, 42 ItemTypeWalletSwitch,
42 ItemTypeAddress, 43 ItemTypeAddress,
43 ItemTypeCard, 44 ItemTypeCard,
44 ItemTypeHeader, 45 ItemTypeHeader,
45 }; 46 };
46 47
47 } // namespace 48 } // namespace
48 49
49 #pragma mark - AutofillCollectionViewController 50 #pragma mark - AutofillCollectionViewController
50 51
51 @interface AutofillCollectionViewController ()< 52 @interface AutofillCollectionViewController ()<
52 PersonalDataManagerObserverBridgeDelegate> { 53 PersonalDataManagerObserverBridgeDelegate> {
53 std::string _locale; // User locale. 54 std::string _locale; // User locale.
54 autofill::PersonalDataManager* _personalDataManager; 55 autofill::PersonalDataManager* _personalDataManager;
55 base::mac::ObjCPropertyReleaser 56
56 _propertyReleaser_AutofillCollectionViewController;
57 ios::ChromeBrowserState* _browserState; 57 ios::ChromeBrowserState* _browserState;
58 std::unique_ptr<autofill::PersonalDataManagerObserverBridge> _observer; 58 std::unique_ptr<autofill::PersonalDataManagerObserverBridge> _observer;
59 BOOL _deletionInProgress; 59 BOOL _deletionInProgress;
60 60
61 // Writing user-initiated switch state changes to the pref service results in 61 // Writing user-initiated switch state changes to the pref service results in
62 // an observer callback, which handles general data updates with a reloadData. 62 // an observer callback, which handles general data updates with a reloadData.
63 // It is better to handle user-initiated changes with more specific actions 63 // It is better to handle user-initiated changes with more specific actions
64 // such as inserting or removing items/sections. This boolean is used to 64 // such as inserting or removing items/sections. This boolean is used to
65 // stop the observer callback from acting on user-initiated changes. 65 // stop the observer callback from acting on user-initiated changes.
66 BOOL _userInteractionInProgress; 66 BOOL _userInteractionInProgress;
(...skipping 12 matching lines...) Expand all
79 self.shouldHideDoneButton = YES; 79 self.shouldHideDoneButton = YES;
80 _browserState = browserState; 80 _browserState = browserState;
81 _locale = GetApplicationContext()->GetApplicationLocale(); 81 _locale = GetApplicationContext()->GetApplicationLocale();
82 _personalDataManager = 82 _personalDataManager =
83 autofill::PersonalDataManagerFactory::GetForBrowserState(_browserState); 83 autofill::PersonalDataManagerFactory::GetForBrowserState(_browserState);
84 _observer.reset(new autofill::PersonalDataManagerObserverBridge(self)); 84 _observer.reset(new autofill::PersonalDataManagerObserverBridge(self));
85 _personalDataManager->AddObserver(_observer.get()); 85 _personalDataManager->AddObserver(_observer.get());
86 86
87 [self updateEditButton]; 87 [self updateEditButton];
88 [self loadModel]; 88 [self loadModel];
89
90 _propertyReleaser_AutofillCollectionViewController.Init(
91 self, [AutofillCollectionViewController class]);
92 } 89 }
93 return self; 90 return self;
94 } 91 }
95 92
96 - (void)dealloc { 93 - (void)dealloc {
97 _personalDataManager->RemoveObserver(_observer.get()); 94 _personalDataManager->RemoveObserver(_observer.get());
98 [super dealloc];
99 } 95 }
100 96
101 #pragma mark - CollectionViewController 97 #pragma mark - CollectionViewController
102 98
103 - (void)loadModel { 99 - (void)loadModel {
104 [super loadModel]; 100 [super loadModel];
105 CollectionViewModel* model = self.collectionViewModel; 101 CollectionViewModel* model = self.collectionViewModel;
106 102
107 [model addSectionWithIdentifier:SectionIdentifierSwitches]; 103 [model addSectionWithIdentifier:SectionIdentifierSwitches];
108 [model addItem:[self autofillSwitchItem] 104 [model addItem:[self autofillSwitchItem]
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 forSectionWithIdentifier:SectionIdentifierCards]; 143 forSectionWithIdentifier:SectionIdentifierCards];
148 for (autofill::CreditCard* creditCard : creditCards) { 144 for (autofill::CreditCard* creditCard : creditCards) {
149 DCHECK(creditCard); 145 DCHECK(creditCard);
150 [model addItem:[self itemForCreditCard:*creditCard] 146 [model addItem:[self itemForCreditCard:*creditCard]
151 toSectionWithIdentifier:SectionIdentifierCards]; 147 toSectionWithIdentifier:SectionIdentifierCards];
152 } 148 }
153 } 149 }
154 } 150 }
155 151
156 - (CollectionViewItem*)autofillSwitchItem { 152 - (CollectionViewItem*)autofillSwitchItem {
157 CollectionViewSwitchItem* switchItem = [[[CollectionViewSwitchItem alloc] 153 CollectionViewSwitchItem* switchItem =
158 initWithType:ItemTypeAutofillSwitch] autorelease]; 154 [[CollectionViewSwitchItem alloc] initWithType:ItemTypeAutofillSwitch];
159 switchItem.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL); 155 switchItem.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL);
160 switchItem.on = [self isAutofillEnabled]; 156 switchItem.on = [self isAutofillEnabled];
161 return switchItem; 157 return switchItem;
162 } 158 }
163 159
164 - (CollectionViewItem*)walletSwitchItem { 160 - (CollectionViewItem*)walletSwitchItem {
165 CollectionViewSwitchItem* switchItem = [[[CollectionViewSwitchItem alloc] 161 CollectionViewSwitchItem* switchItem =
166 initWithType:ItemTypeWalletSwitch] autorelease]; 162 [[CollectionViewSwitchItem alloc] initWithType:ItemTypeWalletSwitch];
167 switchItem.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_USE_WALLET_DATA); 163 switchItem.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_USE_WALLET_DATA);
168 switchItem.on = [self isWalletEnabled]; 164 switchItem.on = [self isWalletEnabled];
169 return switchItem; 165 return switchItem;
170 } 166 }
171 167
172 - (CollectionViewItem*)profileSectionHeader { 168 - (CollectionViewItem*)profileSectionHeader {
173 CollectionViewTextItem* header = [self genericHeader]; 169 CollectionViewTextItem* header = [self genericHeader];
174 header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_ADDRESSES_GROUP_NAME); 170 header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_ADDRESSES_GROUP_NAME);
175 return header; 171 return header;
176 } 172 }
177 173
178 - (CollectionViewItem*)cardSectionHeader { 174 - (CollectionViewItem*)cardSectionHeader {
179 CollectionViewTextItem* header = [self genericHeader]; 175 CollectionViewTextItem* header = [self genericHeader];
180 header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_CREDITCARDS_GROUP_NAME); 176 header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_CREDITCARDS_GROUP_NAME);
181 return header; 177 return header;
182 } 178 }
183 179
184 - (CollectionViewTextItem*)genericHeader { 180 - (CollectionViewTextItem*)genericHeader {
185 CollectionViewTextItem* header = [ 181 CollectionViewTextItem* header =
186 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; 182 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
187 header.textColor = [[MDCPalette greyPalette] tint500]; 183 header.textColor = [[MDCPalette greyPalette] tint500];
188 return header; 184 return header;
189 } 185 }
190 186
191 - (CollectionViewItem*)itemForProfile: 187 - (CollectionViewItem*)itemForProfile:
192 (const autofill::AutofillProfile&)autofillProfile { 188 (const autofill::AutofillProfile&)autofillProfile {
193 std::string guid(autofillProfile.guid()); 189 std::string guid(autofillProfile.guid());
194 NSString* title = base::SysUTF16ToNSString(autofillProfile.GetInfo( 190 NSString* title = base::SysUTF16ToNSString(autofillProfile.GetInfo(
195 autofill::AutofillType(autofill::NAME_FULL), _locale)); 191 autofill::AutofillType(autofill::NAME_FULL), _locale));
196 NSString* subTitle = base::SysUTF16ToNSString(autofillProfile.GetInfo( 192 NSString* subTitle = base::SysUTF16ToNSString(autofillProfile.GetInfo(
197 autofill::AutofillType(autofill::ADDRESS_HOME_LINE1), _locale)); 193 autofill::AutofillType(autofill::ADDRESS_HOME_LINE1), _locale));
198 bool isServerProfile = autofillProfile.record_type() == 194 bool isServerProfile = autofillProfile.record_type() ==
199 autofill::AutofillProfile::SERVER_PROFILE; 195 autofill::AutofillProfile::SERVER_PROFILE;
200 196
201 AutofillDataItem* item = 197 AutofillDataItem* item =
202 [[[AutofillDataItem alloc] initWithType:ItemTypeAddress] autorelease]; 198 [[AutofillDataItem alloc] initWithType:ItemTypeAddress];
203 item.text = title; 199 item.text = title;
204 item.leadingDetailText = subTitle; 200 item.leadingDetailText = subTitle;
205 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; 201 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
206 item.accessibilityIdentifier = title; 202 item.accessibilityIdentifier = title;
207 item.GUID = guid; 203 item.GUID = guid;
208 item.deletable = !isServerProfile; 204 item.deletable = !isServerProfile;
209 if (isServerProfile) { 205 if (isServerProfile) {
210 item.trailingDetailText = 206 item.trailingDetailText =
211 l10n_util::GetNSString(IDS_IOS_AUTOFILL_WALLET_SERVER_NAME); 207 l10n_util::GetNSString(IDS_IOS_AUTOFILL_WALLET_SERVER_NAME);
212 } 208 }
213 return item; 209 return item;
214 } 210 }
215 211
216 - (CollectionViewItem*)itemForCreditCard: 212 - (CollectionViewItem*)itemForCreditCard:
217 (const autofill::CreditCard&)creditCard { 213 (const autofill::CreditCard&)creditCard {
218 std::string guid(creditCard.guid()); 214 std::string guid(creditCard.guid());
219 NSString* creditCardName = autofill::GetCreditCardName(creditCard, _locale); 215 NSString* creditCardName = autofill::GetCreditCardName(creditCard, _locale);
220 216
221 AutofillDataItem* item = 217 AutofillDataItem* item = [[AutofillDataItem alloc] initWithType:ItemTypeCard];
222 [[[AutofillDataItem alloc] initWithType:ItemTypeCard] autorelease];
223 item.text = creditCardName; 218 item.text = creditCardName;
224 item.leadingDetailText = autofill::GetCreditCardObfuscatedNumber(creditCard); 219 item.leadingDetailText = autofill::GetCreditCardObfuscatedNumber(creditCard);
225 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; 220 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
226 item.accessibilityIdentifier = creditCardName; 221 item.accessibilityIdentifier = creditCardName;
227 item.deletable = autofill::IsCreditCardLocal(creditCard); 222 item.deletable = autofill::IsCreditCardLocal(creditCard);
228 item.GUID = guid; 223 item.GUID = guid;
229 if (![item isDeletable]) { 224 if (![item isDeletable]) {
230 item.trailingDetailText = 225 item.trailingDetailText =
231 l10n_util::GetNSString(IDS_IOS_AUTOFILL_WALLET_SERVER_NAME); 226 l10n_util::GetNSString(IDS_IOS_AUTOFILL_WALLET_SERVER_NAME);
232 } 227 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 #pragma mark - Switch Callbacks 272 #pragma mark - Switch Callbacks
278 273
279 - (void)autofillSwitchChanged:(UISwitch*)switchView { 274 - (void)autofillSwitchChanged:(UISwitch*)switchView {
280 [self setSwitchItemOn:[switchView isOn] itemType:ItemTypeAutofillSwitch]; 275 [self setSwitchItemOn:[switchView isOn] itemType:ItemTypeAutofillSwitch];
281 _userInteractionInProgress = YES; 276 _userInteractionInProgress = YES;
282 [self setAutofillEnabled:[switchView isOn]]; 277 [self setAutofillEnabled:[switchView isOn]];
283 _userInteractionInProgress = NO; 278 _userInteractionInProgress = NO;
284 [self updateEditButton]; 279 [self updateEditButton];
285 280
286 // Avoid reference cycle in block. 281 // Avoid reference cycle in block.
287 base::WeakNSObject<AutofillCollectionViewController> weakSelf(self); 282 __weak AutofillCollectionViewController* weakSelf = self;
288 [self.collectionView performBatchUpdates:^{ 283 [self.collectionView performBatchUpdates:^{
289 // Obtain strong reference again. 284 // Obtain strong reference again.
290 base::scoped_nsobject<AutofillCollectionViewController> strongSelf( 285 AutofillCollectionViewController* strongSelf = weakSelf;
291 [weakSelf retain]);
292 if (!strongSelf) { 286 if (!strongSelf) {
293 return; 287 return;
294 } 288 }
295 289
296 if ([switchView isOn]) { 290 if ([switchView isOn]) {
297 [strongSelf insertWalletSwitchItem]; 291 [strongSelf insertWalletSwitchItem];
298 [strongSelf insertProfileAndCardSections]; 292 [strongSelf insertProfileAndCardSections];
299 } else { 293 } else {
300 [strongSelf removeWalletSwitchItem]; 294 [strongSelf removeWalletSwitchItem];
301 [strongSelf removeProfileAndCardSections]; 295 [strongSelf removeProfileAndCardSections];
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 367 }
374 if ([self.collectionViewModel 368 if ([self.collectionViewModel
375 hasSectionForSectionIdentifier:SectionIdentifierCards]) { 369 hasSectionForSectionIdentifier:SectionIdentifierCards]) {
376 [self.collectionViewModel 370 [self.collectionViewModel
377 removeSectionWithIdentifier:SectionIdentifierCards]; 371 removeSectionWithIdentifier:SectionIdentifierCards];
378 } 372 }
379 [self.collectionView deleteSections:sections]; 373 [self.collectionView deleteSections:sections];
380 } 374 }
381 375
382 - (NSIndexSet*)indexSetForExistingProfileAndCardSections { 376 - (NSIndexSet*)indexSetForExistingProfileAndCardSections {
383 NSMutableIndexSet* sections = [[[NSMutableIndexSet alloc] init] autorelease]; 377 NSMutableIndexSet* sections = [[NSMutableIndexSet alloc] init];
384 if ([self.collectionViewModel 378 if ([self.collectionViewModel
385 hasSectionForSectionIdentifier:SectionIdentifierProfiles]) { 379 hasSectionForSectionIdentifier:SectionIdentifierProfiles]) {
386 [sections 380 [sections
387 addIndex:[self.collectionViewModel 381 addIndex:[self.collectionViewModel
388 sectionForSectionIdentifier:SectionIdentifierProfiles]]; 382 sectionForSectionIdentifier:SectionIdentifierProfiles]];
389 } 383 }
390 if ([self.collectionViewModel 384 if ([self.collectionViewModel
391 hasSectionForSectionIdentifier:SectionIdentifierCards]) { 385 hasSectionForSectionIdentifier:SectionIdentifierCards]) {
392 [sections addIndex:[self.collectionViewModel 386 [sections addIndex:[self.collectionViewModel
393 sectionForSectionIdentifier:SectionIdentifierCards]]; 387 sectionForSectionIdentifier:SectionIdentifierCards]];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 444 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
451 445
452 // Edit mode is the state where the user can select and delete entries. In 446 // Edit mode is the state where the user can select and delete entries. In
453 // edit mode, selection is handled by the superclass. When not in edit mode 447 // edit mode, selection is handled by the superclass. When not in edit mode
454 // selection presents the editing controller for the selected entry. 448 // selection presents the editing controller for the selected entry.
455 if ([self.editor isEditing]) { 449 if ([self.editor isEditing]) {
456 return; 450 return;
457 } 451 }
458 452
459 CollectionViewModel* model = self.collectionViewModel; 453 CollectionViewModel* model = self.collectionViewModel;
460 base::scoped_nsobject<UIViewController> controller; 454 UIViewController* controller;
461 switch ([model itemTypeForIndexPath:indexPath]) { 455 switch ([model itemTypeForIndexPath:indexPath]) {
462 case ItemTypeAddress: { 456 case ItemTypeAddress: {
463 const std::vector<autofill::AutofillProfile*> autofillProfiles = 457 const std::vector<autofill::AutofillProfile*> autofillProfiles =
464 _personalDataManager->GetProfiles(); 458 _personalDataManager->GetProfiles();
465 controller.reset([[AutofillProfileEditCollectionViewController 459 controller = [AutofillProfileEditCollectionViewController
466 controllerWithProfile:*autofillProfiles[indexPath.item] 460 controllerWithProfile:*autofillProfiles[indexPath.item]
467 personalDataManager:_personalDataManager] retain]); 461 personalDataManager:_personalDataManager];
468 break; 462 break;
469 } 463 }
470 case ItemTypeCard: { 464 case ItemTypeCard: {
471 const std::vector<autofill::CreditCard*>& creditCards = 465 const std::vector<autofill::CreditCard*>& creditCards =
472 _personalDataManager->GetCreditCards(); 466 _personalDataManager->GetCreditCards();
473 controller.reset([[AutofillCreditCardEditCollectionViewController alloc] 467 controller = [[AutofillCreditCardEditCollectionViewController alloc]
474 initWithCreditCard:*creditCards[indexPath.item] 468 initWithCreditCard:*creditCards[indexPath.item]
475 personalDataManager:_personalDataManager]); 469 personalDataManager:_personalDataManager];
476 break; 470 break;
477 } 471 }
478 default: 472 default:
479 break; 473 break;
480 } 474 }
481 475
482 if (controller.get()) { 476 if (controller) {
483 [self.navigationController pushViewController:controller animated:YES]; 477 [self.navigationController pushViewController:controller animated:YES];
484 } 478 }
485 } 479 }
486 480
487 #pragma mark - MDCCollectionViewEditingDelegate 481 #pragma mark - MDCCollectionViewEditingDelegate
488 482
489 - (BOOL)collectionViewAllowsEditing:(UICollectionView*)collectionView { 483 - (BOOL)collectionViewAllowsEditing:(UICollectionView*)collectionView {
490 return YES; 484 return YES;
491 } 485 }
492 486
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 - (void)removeSectionIfEmptyForSectionWithIdentifier: 526 - (void)removeSectionIfEmptyForSectionWithIdentifier:
533 (SectionIdentifier)sectionIdentifier { 527 (SectionIdentifier)sectionIdentifier {
534 if (![self.collectionViewModel 528 if (![self.collectionViewModel
535 hasSectionForSectionIdentifier:sectionIdentifier]) { 529 hasSectionForSectionIdentifier:sectionIdentifier]) {
536 return; 530 return;
537 } 531 }
538 NSInteger section = 532 NSInteger section =
539 [self.collectionViewModel sectionForSectionIdentifier:sectionIdentifier]; 533 [self.collectionViewModel sectionForSectionIdentifier:sectionIdentifier];
540 if ([self.collectionView numberOfItemsInSection:section] == 0) { 534 if ([self.collectionView numberOfItemsInSection:section] == 0) {
541 // Avoid reference cycle in block. 535 // Avoid reference cycle in block.
542 base::WeakNSObject<AutofillCollectionViewController> weakSelf(self); 536 __weak AutofillCollectionViewController* weakSelf = self;
543 [self.collectionView performBatchUpdates:^{ 537 [self.collectionView performBatchUpdates:^{
544 // Obtain strong reference again. 538 // Obtain strong reference again.
545 base::scoped_nsobject<AutofillCollectionViewController> strongSelf( 539 AutofillCollectionViewController* strongSelf = weakSelf;
546 [weakSelf retain]);
547 if (!strongSelf) { 540 if (!strongSelf) {
548 return; 541 return;
549 } 542 }
550 543
551 // Remove section from model and collectionView. 544 // Remove section from model and collectionView.
552 [[strongSelf collectionViewModel] 545 [[strongSelf collectionViewModel]
553 removeSectionWithIdentifier:sectionIdentifier]; 546 removeSectionWithIdentifier:sectionIdentifier];
554 [[strongSelf collectionView] 547 [[strongSelf collectionView]
555 deleteSections:[NSIndexSet indexSetWithIndex:section]]; 548 deleteSections:[NSIndexSet indexSetWithIndex:section]];
556 } 549 }
557 completion:^(BOOL finished) { 550 completion:^(BOOL finished) {
558 // Obtain strong reference again. 551 // Obtain strong reference again.
559 base::scoped_nsobject<AutofillCollectionViewController> strongSelf( 552 AutofillCollectionViewController* strongSelf = weakSelf;
560 [weakSelf retain]);
561 if (!strongSelf) { 553 if (!strongSelf) {
562 return; 554 return;
563 } 555 }
564 556
565 // Turn off edit mode if there is nothing to edit. 557 // Turn off edit mode if there is nothing to edit.
566 if (![strongSelf localProfilesOrCreditCardsExist]) { 558 if (![strongSelf localProfilesOrCreditCardsExist]) {
567 [[strongSelf editor] setEditing:NO]; 559 [[strongSelf editor] setEditing:NO];
568 } 560 }
569 [strongSelf updateEditButton]; 561 [strongSelf updateEditButton];
570 strongSelf.get()->_deletionInProgress = NO; 562 strongSelf->_deletionInProgress = NO;
571 }]; 563 }];
572 } 564 }
573 } 565 }
574 566
575 #pragma mark PersonalDataManagerObserverBridgeDelegate 567 #pragma mark PersonalDataManagerObserverBridgeDelegate
576 568
577 - (void)onPersonalDataChanged { 569 - (void)onPersonalDataChanged {
578 // If the change is due to local editing, or if local editing is happening 570 // If the change is due to local editing, or if local editing is happening
579 // concurrently, updates are handled by collection view editing callbacks. 571 // concurrently, updates are handled by collection view editing callbacks.
580 // Data is reloaded at the end of deletion to make sure entries are in sync. 572 // Data is reloaded at the end of deletion to make sure entries are in sync.
(...skipping 30 matching lines...) Expand all
611 return _browserState->GetPrefs()->GetBoolean( 603 return _browserState->GetPrefs()->GetBoolean(
612 autofill::prefs::kAutofillWalletImportEnabled); 604 autofill::prefs::kAutofillWalletImportEnabled);
613 } 605 }
614 606
615 - (void)setWalletEnabled:(BOOL)isEnabled { 607 - (void)setWalletEnabled:(BOOL)isEnabled {
616 _browserState->GetPrefs()->SetBoolean( 608 _browserState->GetPrefs()->SetBoolean(
617 autofill::prefs::kAutofillWalletImportEnabled, isEnabled); 609 autofill::prefs::kAutofillWalletImportEnabled, isEnabled);
618 } 610 }
619 611
620 @end 612 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698