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 "chrome/browser/password_manager/password_manager.h" | 5 #include "chrome/browser/password_manager/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.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 manager->SetHasGeneratedPassword(); | 130 manager->SetHasGeneratedPassword(); |
131 // TODO(gcasto): Add UMA stats to track this. | 131 // TODO(gcasto): Add UMA stats to track this. |
132 } | 132 } |
133 | 133 |
134 bool PasswordManager::IsSavingEnabled() const { | 134 bool PasswordManager::IsSavingEnabled() const { |
135 return *password_manager_enabled_ && | 135 return *password_manager_enabled_ && |
136 !delegate_->GetProfile()->IsOffTheRecord(); | 136 !delegate_->GetProfile()->IsOffTheRecord(); |
137 } | 137 } |
138 | 138 |
139 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { | 139 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { |
140 if (!IsSavingEnabled()) | 140 if (!IsSavingEnabled()) { |
| 141 RecordFailure(SAVING_DISABLED); |
141 return; | 142 return; |
| 143 } |
142 | 144 |
143 // No password to save? Then don't. | 145 // No password to save? Then don't. |
144 if (form.password_value.empty()) | 146 if (form.password_value.empty()) { |
| 147 RecordFailure(EMPTY_PASSWORD); |
145 return; | 148 return; |
| 149 } |
146 | 150 |
147 scoped_ptr<PasswordFormManager> manager; | 151 scoped_ptr<PasswordFormManager> manager; |
148 ScopedVector<PasswordFormManager>::iterator matched_manager_it = | 152 ScopedVector<PasswordFormManager>::iterator matched_manager_it = |
149 pending_login_managers_.end(); | 153 pending_login_managers_.end(); |
150 for (ScopedVector<PasswordFormManager>::iterator iter = | 154 for (ScopedVector<PasswordFormManager>::iterator iter = |
151 pending_login_managers_.begin(); | 155 pending_login_managers_.begin(); |
152 iter != pending_login_managers_.end(); ++iter) { | 156 iter != pending_login_managers_.end(); ++iter) { |
153 // If we find a manager that exactly matches the submitted form including | 157 // If we find a manager that exactly matches the submitted form including |
154 // the action URL, exit the loop. | 158 // the action URL, exit the loop. |
155 if ((*iter)->DoesManage( | 159 if ((*iter)->DoesManage( |
(...skipping 10 matching lines...) Expand all Loading... |
166 } | 170 } |
167 // If we didn't find a manager, this means a form was submitted without | 171 // If we didn't find a manager, this means a form was submitted without |
168 // first loading the page containing the form. Don't offer to save | 172 // first loading the page containing the form. Don't offer to save |
169 // passwords in this case. | 173 // passwords in this case. |
170 if (matched_manager_it != pending_login_managers_.end()) { | 174 if (matched_manager_it != pending_login_managers_.end()) { |
171 // Transfer ownership of the manager from |pending_login_managers_| to | 175 // Transfer ownership of the manager from |pending_login_managers_| to |
172 // |manager|. | 176 // |manager|. |
173 manager.reset(*matched_manager_it); | 177 manager.reset(*matched_manager_it); |
174 pending_login_managers_.weak_erase(matched_manager_it); | 178 pending_login_managers_.weak_erase(matched_manager_it); |
175 } else { | 179 } else { |
| 180 RecordFailure(NO_MATCHING_FORM); |
176 return; | 181 return; |
177 } | 182 } |
178 | 183 |
179 // If we found a manager but it didn't finish matching yet, the user has | 184 // If we found a manager but it didn't finish matching yet, the user has |
180 // tried to submit credentials before we had time to even find matching | 185 // tried to submit credentials before we had time to even find matching |
181 // results for the given form and autofill. If this is the case, we just | 186 // results for the given form and autofill. If this is the case, we just |
182 // give up. | 187 // give up. |
183 if (!manager->HasCompletedMatching()) | 188 if (!manager->HasCompletedMatching()) { |
| 189 RecordFailure(MATCHING_NOT_COMPLETE); |
184 return; | 190 return; |
| 191 } |
185 | 192 |
186 // Also get out of here if the user told us to 'never remember' passwords for | 193 // Also get out of here if the user told us to 'never remember' passwords for |
187 // this form. | 194 // this form. |
188 if (manager->IsBlacklisted()) | 195 if (manager->IsBlacklisted()) { |
| 196 RecordFailure(FORM_BLACKLISTED); |
189 return; | 197 return; |
| 198 } |
190 | 199 |
191 // Bail if we're missing any of the necessary form components. | 200 // Bail if we're missing any of the necessary form components. |
192 if (!manager->HasValidPasswordForm()) | 201 if (!manager->HasValidPasswordForm()) { |
| 202 RecordFailure(INVALID_FORM); |
193 return; | 203 return; |
| 204 } |
194 | 205 |
195 // Always save generated passwords, as the user expresses explicit intent for | 206 // Always save generated passwords, as the user expresses explicit intent for |
196 // Chrome to manage such passwords. For other passwords, respect the | 207 // Chrome to manage such passwords. For other passwords, respect the |
197 // autocomplete attribute. | 208 // autocomplete attribute. |
198 if (!manager->HasGeneratedPassword() && !form.password_autocomplete_set) | 209 if (!manager->HasGeneratedPassword() && !form.password_autocomplete_set) { |
| 210 RecordFailure(AUTOCOMPLETE_OFF); |
199 return; | 211 return; |
| 212 } |
200 | 213 |
201 PasswordForm provisionally_saved_form(form); | 214 PasswordForm provisionally_saved_form(form); |
202 provisionally_saved_form.ssl_valid = form.origin.SchemeIsSecure() && | 215 provisionally_saved_form.ssl_valid = form.origin.SchemeIsSecure() && |
203 !delegate_->DidLastPageLoadEncounterSSLErrors(); | 216 !delegate_->DidLastPageLoadEncounterSSLErrors(); |
204 provisionally_saved_form.preferred = true; | 217 provisionally_saved_form.preferred = true; |
205 PasswordFormManager::OtherPossibleUsernamesAction action = | 218 PasswordFormManager::OtherPossibleUsernamesAction action = |
206 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES; | 219 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES; |
207 if (OtherPossibleUsernamesEnabled()) | 220 if (OtherPossibleUsernamesEnabled()) |
208 action = PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES; | 221 action = PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES; |
209 manager->ProvisionallySave(provisionally_saved_form, action); | 222 manager->ProvisionallySave(provisionally_saved_form, action); |
210 provisional_save_manager_.swap(manager); | 223 provisional_save_manager_.swap(manager); |
211 } | 224 } |
212 | 225 |
| 226 void PasswordManager::RecordFailure(ProvisionalSaveFailure failure) { |
| 227 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ProvisionalSaveFailure", |
| 228 failure, MAX_FAILURE_VALUE); |
| 229 } |
| 230 |
213 void PasswordManager::AddObserver(LoginModelObserver* observer) { | 231 void PasswordManager::AddObserver(LoginModelObserver* observer) { |
214 observers_.AddObserver(observer); | 232 observers_.AddObserver(observer); |
215 } | 233 } |
216 | 234 |
217 void PasswordManager::RemoveObserver(LoginModelObserver* observer) { | 235 void PasswordManager::RemoveObserver(LoginModelObserver* observer) { |
218 observers_.RemoveObserver(observer); | 236 observers_.RemoveObserver(observer); |
219 } | 237 } |
220 | 238 |
221 void PasswordManager::DidNavigateAnyFrame( | 239 void PasswordManager::DidNavigateAnyFrame( |
222 const content::LoadCommittedDetails& details, | 240 const content::LoadCommittedDetails& details, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 return; | 404 return; |
387 } | 405 } |
388 default: | 406 default: |
389 FOR_EACH_OBSERVER( | 407 FOR_EACH_OBSERVER( |
390 LoginModelObserver, | 408 LoginModelObserver, |
391 observers_, | 409 observers_, |
392 OnAutofillDataAvailable(preferred_match.username_value, | 410 OnAutofillDataAvailable(preferred_match.username_value, |
393 preferred_match.password_value)); | 411 preferred_match.password_value)); |
394 } | 412 } |
395 } | 413 } |
OLD | NEW |