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

Side by Side Diff: components/password_manager/core/browser/password_manager.cc

Issue 2900693002: [Password Manager] Convert |pending_login_managers_| to an array of scoped_refptr (Closed)
Patch Set: Rebase 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "components/password_manager/core/browser/password_manager.h" 5 #include "components/password_manager/core/browser/password_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (form_manager) { 231 if (form_manager) {
232 form_manager->set_generation_element(generation_element); 232 form_manager->set_generation_element(generation_element);
233 form_manager->set_is_manual_generation(is_manually_triggered); 233 form_manager->set_is_manual_generation(is_manually_triggered);
234 form_manager->set_generation_popup_was_shown(true); 234 form_manager->set_generation_popup_was_shown(true);
235 return; 235 return;
236 } 236 }
237 237
238 // If there is no corresponding PasswordFormManager, we create one. This is 238 // If there is no corresponding PasswordFormManager, we create one. This is
239 // not the common case, and should only happen when there is a bug in our 239 // not the common case, and should only happen when there is a bug in our
240 // ability to detect forms. 240 // ability to detect forms.
241 auto manager = base::MakeUnique<PasswordFormManager>( 241 auto manager = base::MakeRefCounted<PasswordFormManager>(
242 this, client_, driver->AsWeakPtr(), form, 242 this, client_, driver->AsWeakPtr(), form,
243 base::WrapUnique(new FormSaverImpl(client_->GetPasswordStore())), 243 base::WrapUnique(new FormSaverImpl(client_->GetPasswordStore())),
244 nullptr); 244 nullptr);
245 pending_login_managers_.push_back(std::move(manager)); 245 pending_login_managers_.push_back(std::move(manager));
246 } 246 }
247 247
248 void PasswordManager::SaveGenerationFieldDetectedByClassifier( 248 void PasswordManager::SaveGenerationFieldDetectedByClassifier(
249 const autofill::PasswordForm& form, 249 const autofill::PasswordForm& form,
250 const base::string16& generation_field) { 250 const base::string16& generation_field) {
251 if (!client_->IsSavingAndFillingEnabledForCurrentPage()) 251 if (!client_->IsSavingAndFillingEnabledForCurrentPage())
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 342 }
343 } 343 }
344 // If we didn't find a manager, this means a form was submitted without 344 // If we didn't find a manager, this means a form was submitted without
345 // first loading the page containing the form. Don't offer to save 345 // first loading the page containing the form. Don't offer to save
346 // passwords in this case. 346 // passwords in this case.
347 if (matched_manager_it == pending_login_managers_.end()) { 347 if (matched_manager_it == pending_login_managers_.end()) {
348 RecordFailure(NO_MATCHING_FORM, form.origin, logger.get()); 348 RecordFailure(NO_MATCHING_FORM, form.origin, logger.get());
349 return; 349 return;
350 } 350 }
351 351
352 std::unique_ptr<PasswordFormManager> manager; 352 // Copy ownership of the manager from |pending_login_managers_| to
353 // Transfer ownership of the manager from |pending_login_managers_| to
354 // |manager|. 353 // |manager|.
355 manager.swap(*matched_manager_it); 354 scoped_refptr<PasswordFormManager> manager(*matched_manager_it);
356 pending_login_managers_.erase(matched_manager_it);
357 355
358 PasswordForm submitted_form(form); 356 PasswordForm submitted_form(form);
359 submitted_form.preferred = true; 357 submitted_form.preferred = true;
360 if (logger) { 358 if (logger) {
361 logger->LogPasswordForm(Logger::STRING_PROVISIONALLY_SAVED_FORM, 359 logger->LogPasswordForm(Logger::STRING_PROVISIONALLY_SAVED_FORM,
362 submitted_form); 360 submitted_form);
363 } 361 }
364 PasswordFormManager::OtherPossibleUsernamesAction action = 362 PasswordFormManager::OtherPossibleUsernamesAction action =
365 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES; 363 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES;
366 if (OtherPossibleUsernamesEnabled()) 364 if (OtherPossibleUsernamesEnabled())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 401 }
404 402
405 void PasswordManager::UpdateFormManagers() { 403 void PasswordManager::UpdateFormManagers() {
406 for (const auto& form_manager : pending_login_managers_) { 404 for (const auto& form_manager : pending_login_managers_) {
407 form_manager->form_fetcher()->Fetch(); 405 form_manager->form_fetcher()->Fetch();
408 } 406 }
409 } 407 }
410 408
411 void PasswordManager::DropFormManagers() { 409 void PasswordManager::DropFormManagers() {
412 pending_login_managers_.clear(); 410 pending_login_managers_.clear();
413 provisional_save_manager_.reset(); 411 provisional_save_manager_ = nullptr;
414 all_visible_forms_.clear(); 412 all_visible_forms_.clear();
415 } 413 }
416 414
417 bool PasswordManager::IsPasswordFieldDetectedOnPage() { 415 bool PasswordManager::IsPasswordFieldDetectedOnPage() {
418 return !pending_login_managers_.empty(); 416 return !pending_login_managers_.empty();
419 } 417 }
420 418
421 void PasswordManager::RecordFailure(ProvisionalSaveFailure failure, 419 void PasswordManager::RecordFailure(ProvisionalSaveFailure failure,
422 const GURL& form_origin, 420 const GURL& form_origin,
423 BrowserSavePasswordProgressLogger* logger) { 421 BrowserSavePasswordProgressLogger* logger) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // are password change forms. 558 // are password change forms.
561 if (iter->username_element.empty()) { 559 if (iter->username_element.empty()) {
562 UMA_HISTOGRAM_BOOLEAN( 560 UMA_HISTOGRAM_BOOLEAN(
563 "PasswordManager.EmptyUsernames." 561 "PasswordManager.EmptyUsernames."
564 "FormWithoutUsernameFieldIsPasswordChangeForm", 562 "FormWithoutUsernameFieldIsPasswordChangeForm",
565 !iter->new_password_element.empty()); 563 !iter->new_password_element.empty());
566 } 564 }
567 565
568 if (logger) 566 if (logger)
569 logger->LogFormSignatures(Logger::STRING_ADDING_SIGNATURE, *iter); 567 logger->LogFormSignatures(Logger::STRING_ADDING_SIGNATURE, *iter);
570 auto manager = base::MakeUnique<PasswordFormManager>( 568 auto manager = base::MakeRefCounted<PasswordFormManager>(
571 this, client_, 569 this, client_,
572 (driver ? driver->AsWeakPtr() : base::WeakPtr<PasswordManagerDriver>()), 570 (driver ? driver->AsWeakPtr() : base::WeakPtr<PasswordManagerDriver>()),
573 *iter, base::WrapUnique(new FormSaverImpl(client_->GetPasswordStore())), 571 *iter, base::WrapUnique(new FormSaverImpl(client_->GetPasswordStore())),
574 nullptr); 572 nullptr);
575 pending_login_managers_.push_back(std::move(manager)); 573 pending_login_managers_.push_back(std::move(manager));
576 } 574 }
577 575
578 if (logger) { 576 if (logger) {
579 logger->LogNumber(Logger::STRING_NEW_NUMBER_LOGIN_MANAGERS, 577 logger->LogNumber(Logger::STRING_NEW_NUMBER_LOGIN_MANAGERS,
580 pending_login_managers_.size()); 578 pending_login_managers_.size());
(...skipping 15 matching lines...) Expand all
596 return false; 594 return false;
597 } 595 }
598 596
599 if (provisional_save_manager_->form_fetcher()->GetState() == 597 if (provisional_save_manager_->form_fetcher()->GetState() ==
600 FormFetcher::State::WAITING) { 598 FormFetcher::State::WAITING) {
601 // We have a provisional save manager, but it didn't finish matching yet. 599 // We have a provisional save manager, but it didn't finish matching yet.
602 // We just give up. 600 // We just give up.
603 RecordFailure(MATCHING_NOT_COMPLETE, 601 RecordFailure(MATCHING_NOT_COMPLETE,
604 provisional_save_manager_->observed_form().origin, 602 provisional_save_manager_->observed_form().origin,
605 logger.get()); 603 logger.get());
606 provisional_save_manager_.reset(); 604 provisional_save_manager_ = nullptr;
607 return false; 605 return false;
608 } 606 }
609 return true; 607 return true;
610 } 608 }
611 609
612 bool PasswordManager::ShouldBlockPasswordForSameOriginButDifferentScheme( 610 bool PasswordManager::ShouldBlockPasswordForSameOriginButDifferentScheme(
613 const PasswordForm& form) const { 611 const PasswordForm& form) const {
614 const GURL& old_origin = main_frame_url_.GetOrigin(); 612 const GURL& old_origin = main_frame_url_.GetOrigin();
615 const GURL& new_origin = form.origin.GetOrigin(); 613 const GURL& new_origin = form.origin.GetOrigin();
616 return old_origin.host_piece() == new_origin.host_piece() && 614 return old_origin.host_piece() == new_origin.host_piece() &&
(...skipping 26 matching lines...) Expand all
643 641
644 if (!CanProvisionalManagerSave()) 642 if (!CanProvisionalManagerSave())
645 return; 643 return;
646 644
647 // If the server throws an internal error, access denied page, page not 645 // If the server throws an internal error, access denied page, page not
648 // found etc. after a login attempt, we do not save the credentials. 646 // found etc. after a login attempt, we do not save the credentials.
649 if (client_->WasLastNavigationHTTPError()) { 647 if (client_->WasLastNavigationHTTPError()) {
650 if (logger) 648 if (logger)
651 logger->LogMessage(Logger::STRING_DECISION_DROP); 649 logger->LogMessage(Logger::STRING_DECISION_DROP);
652 provisional_save_manager_->LogSubmitFailed(); 650 provisional_save_manager_->LogSubmitFailed();
653 provisional_save_manager_.reset(); 651 provisional_save_manager_ = nullptr;
654 return; 652 return;
655 } 653 }
656 654
657 if (logger) { 655 if (logger) {
658 logger->LogNumber(Logger::STRING_NUMBER_OF_VISIBLE_FORMS, 656 logger->LogNumber(Logger::STRING_NUMBER_OF_VISIBLE_FORMS,
659 visible_forms.size()); 657 visible_forms.size());
660 } 658 }
661 659
662 // Record all visible forms from the frame. 660 // Record all visible forms from the frame.
663 all_visible_forms_.insert(all_visible_forms_.end(), 661 all_visible_forms_.insert(all_visible_forms_.end(),
(...skipping 16 matching lines...) Expand all
680 if (provisional_save_manager_ 678 if (provisional_save_manager_
681 ->is_possible_change_password_form_without_username() && 679 ->is_possible_change_password_form_without_username() &&
682 AreAllFieldsEmpty(all_visible_forms_[i])) 680 AreAllFieldsEmpty(all_visible_forms_[i]))
683 continue; 681 continue;
684 provisional_save_manager_->LogSubmitFailed(); 682 provisional_save_manager_->LogSubmitFailed();
685 if (logger) { 683 if (logger) {
686 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED, 684 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED,
687 all_visible_forms_[i]); 685 all_visible_forms_[i]);
688 logger->LogMessage(Logger::STRING_DECISION_DROP); 686 logger->LogMessage(Logger::STRING_DECISION_DROP);
689 } 687 }
690 provisional_save_manager_.reset(); 688 provisional_save_manager_ = nullptr;
691 // Clear all_visible_forms_ once we found the match. 689 // Clear all_visible_forms_ once we found the match.
692 all_visible_forms_.clear(); 690 all_visible_forms_.clear();
693 return; 691 return;
694 } 692 }
695 } 693 }
696 } else { 694 } else {
697 if (logger) 695 if (logger)
698 logger->LogMessage(Logger::STRING_PROVISIONALLY_SAVED_FORM_IS_NOT_HTML); 696 logger->LogMessage(Logger::STRING_PROVISIONALLY_SAVED_FORM_IS_NOT_HTML);
699 } 697 }
700 698
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 } 745 }
748 746
749 if (base::FeatureList::IsEnabled(features::kDropSyncCredential)) { 747 if (base::FeatureList::IsEnabled(features::kDropSyncCredential)) {
750 DCHECK(provisional_save_manager_->submitted_form()); 748 DCHECK(provisional_save_manager_->submitted_form());
751 if (!client_->GetStoreResultFilter()->ShouldSave( 749 if (!client_->GetStoreResultFilter()->ShouldSave(
752 *provisional_save_manager_->submitted_form())) { 750 *provisional_save_manager_->submitted_form())) {
753 provisional_save_manager_->WipeStoreCopyIfOutdated(); 751 provisional_save_manager_->WipeStoreCopyIfOutdated();
754 RecordFailure(SYNC_CREDENTIAL, 752 RecordFailure(SYNC_CREDENTIAL,
755 provisional_save_manager_->observed_form().origin, 753 provisional_save_manager_->observed_form().origin,
756 logger.get()); 754 logger.get());
757 provisional_save_manager_.reset(); 755 provisional_save_manager_ = nullptr;
758 return; 756 return;
759 } 757 }
760 } 758 }
761 759
762 provisional_save_manager_->LogSubmitPassed(); 760 provisional_save_manager_->LogSubmitPassed();
763 761
764 RecordWhetherTargetDomainDiffers(main_frame_url_, client_->GetMainFrameURL()); 762 RecordWhetherTargetDomainDiffers(main_frame_url_, client_->GetMainFrameURL());
765 763
766 if (ShouldPromptUserToSavePassword()) { 764 if (ShouldPromptUserToSavePassword()) {
767 bool empty_password = 765 bool empty_password =
(...skipping 19 matching lines...) Expand all
787 provisional_save_manager_->Save(); 785 provisional_save_manager_->Save();
788 786
789 if (!provisional_save_manager_->IsNewLogin()) { 787 if (!provisional_save_manager_->IsNewLogin()) {
790 client_->NotifySuccessfulLoginWithExistingPassword( 788 client_->NotifySuccessfulLoginWithExistingPassword(
791 provisional_save_manager_->pending_credentials()); 789 provisional_save_manager_->pending_credentials());
792 } 790 }
793 791
794 if (provisional_save_manager_->has_generated_password()) { 792 if (provisional_save_manager_->has_generated_password()) {
795 client_->AutomaticPasswordSave(std::move(provisional_save_manager_)); 793 client_->AutomaticPasswordSave(std::move(provisional_save_manager_));
796 } else { 794 } else {
797 provisional_save_manager_.reset(); 795 provisional_save_manager_ = nullptr;
798 } 796 }
799 } 797 }
800 } 798 }
801 799
802 bool PasswordManager::OtherPossibleUsernamesEnabled() const { 800 bool PasswordManager::OtherPossibleUsernamesEnabled() const {
803 return false; 801 return false;
804 } 802 }
805 803
806 void PasswordManager::Autofill( 804 void PasswordManager::Autofill(
807 password_manager::PasswordManagerDriver* driver, 805 password_manager::PasswordManagerDriver* driver,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 current_match_result = result; 943 current_match_result = result;
946 } else if (result > current_match_result) { 944 } else if (result > current_match_result) {
947 matched_manager = login_manager.get(); 945 matched_manager = login_manager.get();
948 current_match_result = result; 946 current_match_result = result;
949 } 947 }
950 } 948 }
951 return matched_manager; 949 return matched_manager;
952 } 950 }
953 951
954 } // namespace password_manager 952 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698