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

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

Powered by Google App Engine
This is Rietveld 408576698