OLD | NEW |
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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 PasswordManager::~PasswordManager() { | 160 PasswordManager::~PasswordManager() { |
161 FOR_EACH_OBSERVER(LoginModelObserver, observers_, OnLoginModelDestroying()); | 161 FOR_EACH_OBSERVER(LoginModelObserver, observers_, OnLoginModelDestroying()); |
162 } | 162 } |
163 | 163 |
164 void PasswordManager::SetHasGeneratedPasswordForForm( | 164 void PasswordManager::SetHasGeneratedPasswordForForm( |
165 password_manager::PasswordManagerDriver* driver, | 165 password_manager::PasswordManagerDriver* driver, |
166 const PasswordForm& form, | 166 const PasswordForm& form, |
167 bool password_is_generated) { | 167 bool password_is_generated) { |
168 DCHECK(client_->IsSavingEnabledForCurrentPage()); | 168 DCHECK(client_->IsSavingEnabledForCurrentPage()); |
169 | 169 |
| 170 ScopedVector<PasswordFormManager>::iterator matched_manager_it = |
| 171 pending_login_managers_.end(); |
| 172 PasswordFormManager::MatchResultMask current_match_result = |
| 173 PasswordFormManager::RESULT_NO_MATCH; |
| 174 |
170 for (ScopedVector<PasswordFormManager>::iterator iter = | 175 for (ScopedVector<PasswordFormManager>::iterator iter = |
171 pending_login_managers_.begin(); | 176 pending_login_managers_.begin(); |
172 iter != pending_login_managers_.end(); ++iter) { | 177 iter != pending_login_managers_.end(); ++iter) { |
173 if ((*iter)->DoesManage(form) == | 178 PasswordFormManager::MatchResultMask result = (*iter)->DoesManage(form); |
174 PasswordFormManager::RESULT_COMPLETE_MATCH) { | 179 |
175 (*iter)->set_has_generated_password(password_is_generated); | 180 if (result == PasswordFormManager::RESULT_NO_MATCH) |
176 return; | 181 continue; |
| 182 |
| 183 if (result == PasswordFormManager::RESULT_COMPLETE_MATCH) { |
| 184 // If we find a manager that exactly matches the submitted form including |
| 185 // the action URL, exit the loop. |
| 186 matched_manager_it = iter; |
| 187 break; |
| 188 } else if (result == (PasswordFormManager::RESULT_COMPLETE_MATCH & |
| 189 ~PasswordFormManager::RESULT_ACTION_MATCH) && |
| 190 result > current_match_result) { |
| 191 // If the current manager matches the submitted form excluding the action |
| 192 // URL, remember it as a candidate and continue searching for an exact |
| 193 // match. See http://crbug.com/27246 for an example where actions can |
| 194 // change. |
| 195 matched_manager_it = iter; |
| 196 current_match_result = result; |
| 197 } else if (result > current_match_result) { |
| 198 matched_manager_it = iter; |
| 199 current_match_result = result; |
177 } | 200 } |
178 } | 201 } |
179 | 202 |
180 if (!password_is_generated) { | 203 if (matched_manager_it != pending_login_managers_.end()) { |
| 204 (*matched_manager_it)->set_has_generated_password(password_is_generated); |
181 return; | 205 return; |
182 } | 206 } |
183 | 207 |
| 208 UMA_HISTOGRAM_BOOLEAN("PasswordManager.GeneratedFormHasNoFormManager", |
| 209 password_is_generated); |
| 210 |
| 211 if (!password_is_generated) |
| 212 return; |
| 213 |
184 // If there is no corresponding PasswordFormManager, we create one. This is | 214 // If there is no corresponding PasswordFormManager, we create one. This is |
185 // not the common case, and should only happen when there is a bug in our | 215 // not the common case, and should only happen when there is a bug in our |
186 // ability to detect forms. | 216 // ability to detect forms. |
187 bool ssl_valid = form.origin.SchemeIsCryptographic(); | 217 bool ssl_valid = form.origin.SchemeIsCryptographic(); |
188 PasswordFormManager* manager = new PasswordFormManager( | 218 PasswordFormManager* manager = new PasswordFormManager( |
189 this, client_, driver->AsWeakPtr(), form, ssl_valid); | 219 this, client_, driver->AsWeakPtr(), form, ssl_valid); |
190 pending_login_managers_.push_back(manager); | 220 pending_login_managers_.push_back(manager); |
191 manager->set_has_generated_password(true); | 221 manager->set_has_generated_password(true); |
192 // TODO(gcasto): Add UMA stats to track this. | |
193 } | 222 } |
194 | 223 |
195 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { | 224 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { |
196 bool is_saving_enabled = client_->IsSavingEnabledForCurrentPage(); | 225 bool is_saving_enabled = client_->IsSavingEnabledForCurrentPage(); |
197 | 226 |
198 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 227 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
199 if (client_->IsLoggingActive()) { | 228 if (client_->IsLoggingActive()) { |
200 logger.reset(new BrowserSavePasswordProgressLogger(client_)); | 229 logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
201 logger->LogMessage(Logger::STRING_PROVISIONALLY_SAVE_PASSWORD_METHOD); | 230 logger->LogMessage(Logger::STRING_PROVISIONALLY_SAVE_PASSWORD_METHOD); |
202 logger->LogPasswordForm(Logger::STRING_PROVISIONALLY_SAVE_PASSWORD_FORM, | 231 logger->LogPasswordForm(Logger::STRING_PROVISIONALLY_SAVE_PASSWORD_FORM, |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 if (ServerTypeToPrediction((*field)->server_type(), &prediction_type)) | 757 if (ServerTypeToPrediction((*field)->server_type(), &prediction_type)) |
729 predictions[form->ToFormData()][prediction_type] = *(*field); | 758 predictions[form->ToFormData()][prediction_type] = *(*field); |
730 } | 759 } |
731 } | 760 } |
732 if (predictions.empty()) | 761 if (predictions.empty()) |
733 return; | 762 return; |
734 driver->AutofillDataReceived(predictions); | 763 driver->AutofillDataReceived(predictions); |
735 } | 764 } |
736 | 765 |
737 } // namespace password_manager | 766 } // namespace password_manager |
OLD | NEW |