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

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_state.cc

Issue 2262843002: Make PasswordFormManager::best_matches_ const (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@621355_pass_creds_to_update_by_value
Patch Set: Just rebased Created 4 years, 3 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 #include "chrome/browser/ui/passwords/manage_passwords_state.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_state.h"
6 6
7 #include <algorithm>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h" 11 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h"
11 #include "components/password_manager/core/browser/log_manager.h" 12 #include "components/password_manager/core/browser/log_manager.h"
12 #include "components/password_manager/core/browser/password_form_manager.h" 13 #include "components/password_manager/core/browser/password_form_manager.h"
13 #include "components/password_manager/core/browser/password_manager.h" 14 #include "components/password_manager/core/browser/password_manager.h"
14 #include "components/password_manager/core/browser/password_manager_client.h" 15 #include "components/password_manager/core/browser/password_manager_client.h"
15 16
16 using password_manager::PasswordFormManager; 17 using password_manager::PasswordFormManager;
17 using autofill::PasswordFormMap;
18 18
19 namespace { 19 namespace {
20 20
21 std::vector<std::unique_ptr<autofill::PasswordForm>> DeepCopyMapToVector( 21 std::vector<std::unique_ptr<autofill::PasswordForm>> DeepCopyMapToVector(
22 const PasswordFormMap& password_form_map) { 22 const std::map<base::string16, const autofill::PasswordForm*>&
23 password_form_map) {
23 std::vector<std::unique_ptr<autofill::PasswordForm>> ret; 24 std::vector<std::unique_ptr<autofill::PasswordForm>> ret;
24 ret.reserve(password_form_map.size()); 25 ret.reserve(password_form_map.size());
25 for (const auto& form_pair : password_form_map) 26 for (const auto& form_pair : password_form_map)
26 ret.push_back(base::MakeUnique<autofill::PasswordForm>(*form_pair.second)); 27 ret.push_back(base::MakeUnique<autofill::PasswordForm>(*form_pair.second));
27 return ret; 28 return ret;
28 } 29 }
29 30
30 void AppendDeepCopyVector( 31 void AppendDeepCopyVector(
31 const std::vector<std::unique_ptr<autofill::PasswordForm>>& forms, 32 const std::vector<const autofill::PasswordForm*>& forms,
32 std::vector<std::unique_ptr<autofill::PasswordForm>>* result) { 33 std::vector<std::unique_ptr<autofill::PasswordForm>>* result) {
33 result->reserve(result->size() + forms.size()); 34 result->reserve(result->size() + forms.size());
34 for (const auto& form : forms) 35 for (const auto& form : forms)
35 result->push_back(base::MakeUnique<autofill::PasswordForm>(*form)); 36 result->push_back(base::MakeUnique<autofill::PasswordForm>(*form));
36 } 37 }
37 38
38 // Updates one form in |forms| that has the same unique key as |updated_form|. 39 // Updates one form in |forms| that has the same unique key as |updated_form|.
39 // Returns true if the form was found and updated. 40 // Returns true if the form was found and updated.
40 bool UpdateFormInVector( 41 bool UpdateFormInVector(
41 const autofill::PasswordForm& updated_form, 42 const autofill::PasswordForm& updated_form,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 local_credentials_forms_.push_back(base::MakeUnique<autofill::PasswordForm>( 139 local_credentials_forms_.push_back(base::MakeUnique<autofill::PasswordForm>(
139 form_manager_->pending_credentials())); 140 form_manager_->pending_credentials()));
140 } 141 }
141 AppendDeepCopyVector(form_manager_->federated_matches(), 142 AppendDeepCopyVector(form_manager_->federated_matches(),
142 &local_credentials_forms_); 143 &local_credentials_forms_);
143 origin_ = form_manager_->observed_form().origin; 144 origin_ = form_manager_->observed_form().origin;
144 SetState(password_manager::ui::CONFIRMATION_STATE); 145 SetState(password_manager::ui::CONFIRMATION_STATE);
145 } 146 }
146 147
147 void ManagePasswordsState::OnPasswordAutofilled( 148 void ManagePasswordsState::OnPasswordAutofilled(
148 const PasswordFormMap& password_form_map, 149 const std::map<base::string16, const autofill::PasswordForm*>&
150 password_form_map,
149 const GURL& origin, 151 const GURL& origin,
150 const std::vector<std::unique_ptr<autofill::PasswordForm>>* 152 const std::vector<const autofill::PasswordForm*>* federated_matches) {
151 federated_matches) {
152 DCHECK(!password_form_map.empty()); 153 DCHECK(!password_form_map.empty());
153 ClearData(); 154 ClearData();
154 bool only_PSL_matches = 155 bool only_PSL_matches = std::all_of(
155 std::all_of(password_form_map.begin(), password_form_map.end(), 156 password_form_map.begin(), password_form_map.end(),
156 [](const PasswordFormMap::value_type& p) { 157 [](const std::map<base::string16,
157 return p.second->is_public_suffix_match; 158 const autofill::PasswordForm*>::value_type& p) {
158 }); 159 return p.second->is_public_suffix_match;
160 });
159 if (only_PSL_matches) { 161 if (only_PSL_matches) {
160 // Don't show the UI for PSL matched passwords. They are not stored for this 162 // Don't show the UI for PSL matched passwords. They are not stored for this
161 // page and cannot be deleted. 163 // page and cannot be deleted.
162 origin_ = GURL(); 164 origin_ = GURL();
163 SetState(password_manager::ui::INACTIVE_STATE); 165 SetState(password_manager::ui::INACTIVE_STATE);
164 } else { 166 } else {
165 local_credentials_forms_ = DeepCopyMapToVector(password_form_map); 167 local_credentials_forms_ = DeepCopyMapToVector(password_form_map);
166 if (federated_matches) 168 if (federated_matches)
167 AppendDeepCopyVector(*federated_matches, &local_credentials_forms_); 169 AppendDeepCopyVector(*federated_matches, &local_credentials_forms_);
168 origin_ = origin; 170 origin_ = origin;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 DCHECK(client_); 252 DCHECK(client_);
251 if (client_->GetLogManager()->IsLoggingActive()) { 253 if (client_->GetLogManager()->IsLoggingActive()) {
252 password_manager::BrowserSavePasswordProgressLogger logger( 254 password_manager::BrowserSavePasswordProgressLogger logger(
253 client_->GetLogManager()); 255 client_->GetLogManager());
254 logger.LogNumber( 256 logger.LogNumber(
255 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, 257 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE,
256 state); 258 state);
257 } 259 }
258 state_ = state; 260 state_ = state;
259 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698