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

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

Issue 2617243002: Remove ScopedVector from ios/. (Closed)
Patch Set: rebase Created 3 years, 11 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/save_passwords_collection_view_controlle r.h" 5 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle r.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector>
8 9
9 #include "base/ios/ios_util.h" 10 #include "base/ios/ios_util.h"
10 #import "base/ios/weak_nsobject.h" 11 #import "base/ios/weak_nsobject.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/mac/foundation_util.h" 13 #include "base/mac/foundation_util.h"
13 #import "base/mac/objc_property_releaser.h" 14 #import "base/mac/objc_property_releaser.h"
14 #import "base/mac/scoped_nsobject.h" 15 #import "base/mac/scoped_nsobject.h"
15 #include "base/memory/scoped_vector.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/numerics/safe_conversions.h" 17 #include "base/numerics/safe_conversions.h"
17 #include "base/strings/sys_string_conversions.h" 18 #include "base/strings/sys_string_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "components/autofill/core/common/password_form.h" 20 #include "components/autofill/core/common/password_form.h"
20 #include "components/google/core/browser/google_util.h" 21 #include "components/google/core/browser/google_util.h"
21 #include "components/keyed_service/core/service_access_type.h" 22 #include "components/keyed_service/core/service_access_type.h"
22 #include "components/password_manager/core/browser/affiliation_utils.h" 23 #include "components/password_manager/core/browser/affiliation_utils.h"
23 #include "components/password_manager/core/browser/password_manager_constants.h" 24 #include "components/password_manager/core/browser/password_manager_constants.h"
24 #include "components/password_manager/core/browser/password_store.h" 25 #include "components/password_manager/core/browser/password_store.h"
25 #include "components/password_manager/core/browser/password_store_consumer.h" 26 #include "components/password_manager/core/browser/password_store_consumer.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 scoped_refptr<password_manager::PasswordStore> passwordStore_; 138 scoped_refptr<password_manager::PasswordStore> passwordStore_;
138 // A helper object for passing data about saved passwords from a finished 139 // A helper object for passing data about saved passwords from a finished
139 // password store request to the SavePasswordsCollectionViewController. 140 // password store request to the SavePasswordsCollectionViewController.
140 std::unique_ptr<password_manager::SavePasswordsConsumer> 141 std::unique_ptr<password_manager::SavePasswordsConsumer>
141 savedPasswordsConsumer_; 142 savedPasswordsConsumer_;
142 // A helper object for passing data about blacklisted sites from a finished 143 // A helper object for passing data about blacklisted sites from a finished
143 // password store request to the SavePasswordsCollectionViewController. 144 // password store request to the SavePasswordsCollectionViewController.
144 std::unique_ptr<password_manager::SavePasswordsConsumer> 145 std::unique_ptr<password_manager::SavePasswordsConsumer>
145 blacklistPasswordsConsumer_; 146 blacklistPasswordsConsumer_;
146 // The list of the user's saved passwords. 147 // The list of the user's saved passwords.
147 ScopedVector<autofill::PasswordForm> savedForms_; 148 std::vector<std::unique_ptr<autofill::PasswordForm>> savedForms_;
148 // The list of the user's blacklisted sites. 149 // The list of the user's blacklisted sites.
149 ScopedVector<autofill::PasswordForm> blacklistedForms_; 150 std::vector<std::unique_ptr<autofill::PasswordForm>> blacklistedForms_;
150 // Deletion of password being asynchronous, and the method taking a reference 151 // Deletion of password being asynchronous, and the method taking a reference
151 // to the PasswordForm, the PasswordForm must outlive the calls to 152 // to the PasswordForm, the PasswordForm must outlive the calls to
152 // RemoveLogin. This vector will ensure this. 153 // RemoveLogin. This vector will ensure this.
153 ScopedVector<autofill::PasswordForm> deletedForms_; 154 std::vector<std::unique_ptr<autofill::PasswordForm>> deletedForms_;
154 // The current Chrome browser state. 155 // The current Chrome browser state.
155 ios::ChromeBrowserState* browserState_; 156 ios::ChromeBrowserState* browserState_;
156 // Object storing the time of the previous successful re-authentication. 157 // Object storing the time of the previous successful re-authentication.
157 // This is meant to be used by the |ReauthenticationModule| for keeping 158 // This is meant to be used by the |ReauthenticationModule| for keeping
158 // re-authentications valid for a certain time interval within the scope 159 // re-authentications valid for a certain time interval within the scope
159 // of the Save Passwords Settings. 160 // of the Save Passwords Settings.
160 base::scoped_nsobject<NSDate> successfulReauthTime_; 161 base::scoped_nsobject<NSDate> successfulReauthTime_;
161 // Module containing the reauthentication mechanism for viewing and copying 162 // Module containing the reauthentication mechanism for viewing and copying
162 // passwords. 163 // passwords.
163 base::scoped_nsobject<ReauthenticationModule> reauthenticationModule_; 164 base::scoped_nsobject<ReauthenticationModule> reauthenticationModule_;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // Saved passwords. 229 // Saved passwords.
229 if ([passwordManagerEnabled_ value]) { 230 if ([passwordManagerEnabled_ value]) {
230 if (!savedForms_.empty()) { 231 if (!savedForms_.empty()) {
231 [model addSectionWithIdentifier:SectionIdentifierSavedPasswords]; 232 [model addSectionWithIdentifier:SectionIdentifierSavedPasswords];
232 CollectionViewTextItem* headerItem = [[[CollectionViewTextItem alloc] 233 CollectionViewTextItem* headerItem = [[[CollectionViewTextItem alloc]
233 initWithType:ItemTypeHeader] autorelease]; 234 initWithType:ItemTypeHeader] autorelease];
234 headerItem.text = 235 headerItem.text =
235 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE); 236 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE);
236 [model setHeader:headerItem 237 [model setHeader:headerItem
237 forSectionWithIdentifier:SectionIdentifierSavedPasswords]; 238 forSectionWithIdentifier:SectionIdentifierSavedPasswords];
238 for (size_t i = 0; i < savedForms_.size(); ++i) { 239 for (const auto& form : savedForms_) {
239 autofill::PasswordForm* form = savedForms_[i]; 240 [model addItem:[self savedFormItemWithForm:form.get()]
240 [model addItem:[self savedFormItemWithForm:form]
241 toSectionWithIdentifier:SectionIdentifierSavedPasswords]; 241 toSectionWithIdentifier:SectionIdentifierSavedPasswords];
242 } 242 }
243 } 243 }
244 if (!blacklistedForms_.empty()) { 244 if (!blacklistedForms_.empty()) {
245 [model addSectionWithIdentifier:SectionIdentifierBlacklist]; 245 [model addSectionWithIdentifier:SectionIdentifierBlacklist];
246 CollectionViewTextItem* headerItem = [[[CollectionViewTextItem alloc] 246 CollectionViewTextItem* headerItem = [[[CollectionViewTextItem alloc]
247 initWithType:ItemTypeHeader] autorelease]; 247 initWithType:ItemTypeHeader] autorelease];
248 headerItem.text = 248 headerItem.text =
249 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_EXCEPTIONS_TAB_TITLE); 249 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_EXCEPTIONS_TAB_TITLE);
250 [model setHeader:headerItem 250 [model setHeader:headerItem
251 forSectionWithIdentifier:SectionIdentifierBlacklist]; 251 forSectionWithIdentifier:SectionIdentifierBlacklist];
252 for (size_t i = 0; i < blacklistedForms_.size(); ++i) { 252 for (const auto& form : blacklistedForms_) {
253 autofill::PasswordForm* form = blacklistedForms_[i]; 253 [model addItem:[self blacklistedFormItemWithForm:form.get()]
254 [model addItem:[self blacklistedFormItemWithForm:form]
255 toSectionWithIdentifier:SectionIdentifierBlacklist]; 254 toSectionWithIdentifier:SectionIdentifierBlacklist];
256 } 255 }
257 } 256 }
258 } 257 }
259 } 258 }
260 259
261 #pragma mark - Items 260 #pragma mark - Items
262 261
263 - (CollectionViewItem*)manageAccountLinkItem { 262 - (CollectionViewItem*)manageAccountLinkItem {
264 CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc] 263 CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc]
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 passwordStore_->GetAutofillableLogins(savedPasswordsConsumer_.get()); 439 passwordStore_->GetAutofillableLogins(savedPasswordsConsumer_.get());
441 blacklistPasswordsConsumer_.reset( 440 blacklistPasswordsConsumer_.reset(
442 new password_manager::SavePasswordsConsumer(self)); 441 new password_manager::SavePasswordsConsumer(self));
443 passwordStore_->GetBlacklistLogins(blacklistPasswordsConsumer_.get()); 442 passwordStore_->GetBlacklistLogins(blacklistPasswordsConsumer_.get());
444 } 443 }
445 444
446 - (void)onGetPasswordStoreResults: 445 - (void)onGetPasswordStoreResults:
447 (const std::vector<std::unique_ptr<autofill::PasswordForm>>&)result { 446 (const std::vector<std::unique_ptr<autofill::PasswordForm>>&)result {
448 for (auto it = result.begin(); it != result.end(); ++it) { 447 for (auto it = result.begin(); it != result.end(); ++it) {
449 // PasswordForm is needed when user wants to delete the site/password. 448 // PasswordForm is needed when user wants to delete the site/password.
450 autofill::PasswordForm* form = new autofill::PasswordForm(**it); 449 auto form = base::MakeUnique<autofill::PasswordForm>(**it);
451 if (form->blacklisted_by_user) 450 if (form->blacklisted_by_user)
452 blacklistedForms_.push_back(form); 451 blacklistedForms_.push_back(std::move(form));
453 else 452 else
454 savedForms_.push_back(form); 453 savedForms_.push_back(std::move(form));
455 } 454 }
456 455
457 [self updateEditButton]; 456 [self updateEditButton];
458 [self reloadData]; 457 [self reloadData];
459 } 458 }
460 459
461 - (BOOL)shouldShowEditButton { 460 - (BOOL)shouldShowEditButton {
462 return [passwordManagerEnabled_ value]; 461 return [passwordManagerEnabled_ value];
463 } 462 }
464 463
(...skipping 12 matching lines...) Expand all
477 if (self.editing) { 476 if (self.editing) {
478 return; 477 return;
479 } 478 }
480 479
481 CollectionViewModel* model = self.collectionViewModel; 480 CollectionViewModel* model = self.collectionViewModel;
482 if ([model itemTypeForIndexPath:indexPath] == ItemTypeSavedPassword) { 481 if ([model itemTypeForIndexPath:indexPath] == ItemTypeSavedPassword) {
483 DCHECK_EQ([model sectionIdentifierForSection:indexPath.section], 482 DCHECK_EQ([model sectionIdentifierForSection:indexPath.section],
484 SectionIdentifierSavedPasswords); 483 SectionIdentifierSavedPasswords);
485 if (experimental_flags::IsViewCopyPasswordsEnabled()) { 484 if (experimental_flags::IsViewCopyPasswordsEnabled()) {
486 DCHECK_LT(base::checked_cast<size_t>(indexPath.item), savedForms_.size()); 485 DCHECK_LT(base::checked_cast<size_t>(indexPath.item), savedForms_.size());
487 autofill::PasswordForm* form = savedForms_[indexPath.item]; 486 autofill::PasswordForm* form = savedForms_[indexPath.item].get();
488 NSString* username = base::SysUTF16ToNSString(form->username_value); 487 NSString* username = base::SysUTF16ToNSString(form->username_value);
489 NSString* password = base::SysUTF16ToNSString(form->password_value); 488 NSString* password = base::SysUTF16ToNSString(form->password_value);
490 NSString* origin = 489 NSString* origin =
491 base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); 490 base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form));
492 base::scoped_nsobject<UIViewController> controller( 491 base::scoped_nsobject<UIViewController> controller(
493 [[PasswordDetailsCollectionViewController alloc] 492 [[PasswordDetailsCollectionViewController alloc]
494 initWithPasswordForm:*form 493 initWithPasswordForm:*form
495 delegate:self 494 delegate:self
496 reauthenticationModule:reauthenticationModule_ 495 reauthenticationModule:reauthenticationModule_
497 username:username 496 username:username
(...skipping 26 matching lines...) Expand all
524 int blacklistedDeleted = 0; 523 int blacklistedDeleted = 0;
525 for (NSIndexPath* indexPath in sortedIndexPaths) { 524 for (NSIndexPath* indexPath in sortedIndexPaths) {
526 // Only form items are editable. 525 // Only form items are editable.
527 CollectionViewTextItem* item = 526 CollectionViewTextItem* item =
528 base::mac::ObjCCastStrict<CollectionViewTextItem>( 527 base::mac::ObjCCastStrict<CollectionViewTextItem>(
529 [self.collectionViewModel itemAtIndexPath:indexPath]); 528 [self.collectionViewModel itemAtIndexPath:indexPath]);
530 BOOL blacklisted = [item isKindOfClass:[BlacklistedFormContentItem class]]; 529 BOOL blacklisted = [item isKindOfClass:[BlacklistedFormContentItem class]];
531 unsigned int formIndex = (unsigned int)indexPath.item; 530 unsigned int formIndex = (unsigned int)indexPath.item;
532 // Adjust index to account for deleted items. 531 // Adjust index to account for deleted items.
533 formIndex -= blacklisted ? blacklistedDeleted : passwordsDeleted; 532 formIndex -= blacklisted ? blacklistedDeleted : passwordsDeleted;
534 ScopedVector<autofill::PasswordForm>& forms = 533 auto& forms = blacklisted ? blacklistedForms_ : savedForms_;
535 blacklisted ? blacklistedForms_ : savedForms_;
536 DCHECK_LT(formIndex, forms.size()); 534 DCHECK_LT(formIndex, forms.size());
537 auto formIterator = forms.begin() + formIndex; 535 auto formIterator = forms.begin() + formIndex;
538 passwordStore_->RemoveLogin(**formIterator); 536 std::unique_ptr<autofill::PasswordForm> form = std::move(*formIterator);
539 deletedForms_.push_back(*formIterator); 537 forms.erase(formIterator);
540 forms.weak_erase(formIterator); 538 passwordStore_->RemoveLogin(*form);
539 deletedForms_.push_back(std::move(form));
541 if (blacklisted) { 540 if (blacklisted) {
542 ++blacklistedDeleted; 541 ++blacklistedDeleted;
543 } else { 542 } else {
544 ++passwordsDeleted; 543 ++passwordsDeleted;
545 } 544 }
546 } 545 }
547 546
548 // Must call super at the end of the child implementation. 547 // Must call super at the end of the child implementation.
549 [super collectionView:collectionView willDeleteItemsAtIndexPaths:indexPaths]; 548 [super collectionView:collectionView willDeleteItemsAtIndexPaths:indexPaths];
550 } 549 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 [strongSelf updateEditButton]; 589 [strongSelf updateEditButton];
591 }]; 590 }];
592 } 591 }
593 592
594 #pragma mark PasswordDetailsCollectionViewControllerDelegate 593 #pragma mark PasswordDetailsCollectionViewControllerDelegate
595 594
596 - (void)deletePassword:(const autofill::PasswordForm&)form { 595 - (void)deletePassword:(const autofill::PasswordForm&)form {
597 passwordStore_->RemoveLogin(form); 596 passwordStore_->RemoveLogin(form);
598 for (auto it = savedForms_.begin(); it != savedForms_.end(); ++it) { 597 for (auto it = savedForms_.begin(); it != savedForms_.end(); ++it) {
599 if (**it == form) { 598 if (**it == form) {
600 savedForms_.weak_erase(it); 599 savedForms_.erase(it);
601 return; 600 return;
602 } 601 }
603 } 602 }
604 [self.navigationController popViewControllerAnimated:YES]; 603 [self.navigationController popViewControllerAnimated:YES];
605 } 604 }
606 605
607 #pragma mark SuccessfulReauthTimeAccessor 606 #pragma mark SuccessfulReauthTimeAccessor
608 607
609 - (void)updateSuccessfulReauthTime { 608 - (void)updateSuccessfulReauthTime {
610 successfulReauthTime_.reset([[NSDate alloc] init]); 609 successfulReauthTime_.reset([[NSDate alloc] init]);
611 } 610 }
612 611
613 - (NSDate*)lastSuccessfulReauthTime { 612 - (NSDate*)lastSuccessfulReauthTime {
614 return successfulReauthTime_.get(); 613 return successfulReauthTime_.get();
615 } 614 }
616 615
617 @end 616 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/bookmarks/bookmark_utils_ios_unittest.mm ('k') | ios/chrome/browser/ui/webui/crashes_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698