| OLD | NEW |
| 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 #include "base/ios/weak_nsobject.h" | 7 #include "base/ios/weak_nsobject.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/objc_property_releaser.h" | 9 #include "base/mac/objc_release_properties.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "components/autofill/core/browser/personal_data_manager.h" | 12 #include "components/autofill/core/browser/personal_data_manager.h" |
| 13 #include "components/autofill/core/common/autofill_pref_names.h" | 13 #include "components/autofill/core/common/autofill_pref_names.h" |
| 14 #include "components/autofill/ios/browser/credit_card_util.h" | 14 #include "components/autofill/ios/browser/credit_card_util.h" |
| 15 #import "components/autofill/ios/browser/personal_data_manager_observer_bridge.h
" | 15 #import "components/autofill/ios/browser/personal_data_manager_observer_bridge.h
" |
| 16 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 17 #include "ios/chrome/browser/application_context.h" | 17 #include "ios/chrome/browser/application_context.h" |
| 18 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" | 18 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
| 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 #pragma mark - AutofillCollectionViewController | 49 #pragma mark - AutofillCollectionViewController |
| 50 | 50 |
| 51 @interface AutofillCollectionViewController ()< | 51 @interface AutofillCollectionViewController ()< |
| 52 PersonalDataManagerObserverBridgeDelegate> { | 52 PersonalDataManagerObserverBridgeDelegate> { |
| 53 std::string _locale; // User locale. | 53 std::string _locale; // User locale. |
| 54 autofill::PersonalDataManager* _personalDataManager; | 54 autofill::PersonalDataManager* _personalDataManager; |
| 55 base::mac::ObjCPropertyReleaser | |
| 56 _propertyReleaser_AutofillCollectionViewController; | |
| 57 ios::ChromeBrowserState* _browserState; | 55 ios::ChromeBrowserState* _browserState; |
| 58 std::unique_ptr<autofill::PersonalDataManagerObserverBridge> _observer; | 56 std::unique_ptr<autofill::PersonalDataManagerObserverBridge> _observer; |
| 59 BOOL _deletionInProgress; | 57 BOOL _deletionInProgress; |
| 60 | 58 |
| 61 // Writing user-initiated switch state changes to the pref service results in | 59 // Writing user-initiated switch state changes to the pref service results in |
| 62 // an observer callback, which handles general data updates with a reloadData. | 60 // an observer callback, which handles general data updates with a reloadData. |
| 63 // It is better to handle user-initiated changes with more specific actions | 61 // 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 | 62 // such as inserting or removing items/sections. This boolean is used to |
| 65 // stop the observer callback from acting on user-initiated changes. | 63 // stop the observer callback from acting on user-initiated changes. |
| 66 BOOL _userInteractionInProgress; | 64 BOOL _userInteractionInProgress; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 79 self.shouldHideDoneButton = YES; | 77 self.shouldHideDoneButton = YES; |
| 80 _browserState = browserState; | 78 _browserState = browserState; |
| 81 _locale = GetApplicationContext()->GetApplicationLocale(); | 79 _locale = GetApplicationContext()->GetApplicationLocale(); |
| 82 _personalDataManager = | 80 _personalDataManager = |
| 83 autofill::PersonalDataManagerFactory::GetForBrowserState(_browserState); | 81 autofill::PersonalDataManagerFactory::GetForBrowserState(_browserState); |
| 84 _observer.reset(new autofill::PersonalDataManagerObserverBridge(self)); | 82 _observer.reset(new autofill::PersonalDataManagerObserverBridge(self)); |
| 85 _personalDataManager->AddObserver(_observer.get()); | 83 _personalDataManager->AddObserver(_observer.get()); |
| 86 | 84 |
| 87 [self updateEditButton]; | 85 [self updateEditButton]; |
| 88 [self loadModel]; | 86 [self loadModel]; |
| 89 | |
| 90 _propertyReleaser_AutofillCollectionViewController.Init( | |
| 91 self, [AutofillCollectionViewController class]); | |
| 92 } | 87 } |
| 93 return self; | 88 return self; |
| 94 } | 89 } |
| 95 | 90 |
| 96 - (void)dealloc { | 91 - (void)dealloc { |
| 97 _personalDataManager->RemoveObserver(_observer.get()); | 92 _personalDataManager->RemoveObserver(_observer.get()); |
| 93 base::mac::ReleaseProperties(self); |
| 98 [super dealloc]; | 94 [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]; |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 return _browserState->GetPrefs()->GetBoolean( | 616 return _browserState->GetPrefs()->GetBoolean( |
| 621 autofill::prefs::kAutofillWalletImportEnabled); | 617 autofill::prefs::kAutofillWalletImportEnabled); |
| 622 } | 618 } |
| 623 | 619 |
| 624 - (void)setWalletEnabled:(BOOL)isEnabled { | 620 - (void)setWalletEnabled:(BOOL)isEnabled { |
| 625 _browserState->GetPrefs()->SetBoolean( | 621 _browserState->GetPrefs()->SetBoolean( |
| 626 autofill::prefs::kAutofillWalletImportEnabled, isEnabled); | 622 autofill::prefs::kAutofillWalletImportEnabled, isEnabled); |
| 627 } | 623 } |
| 628 | 624 |
| 629 @end | 625 @end |
| OLD | NEW |