Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_form_manager.h" | 5 #include "chrome/browser/password_manager/password_form_manager.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" | 
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" | 
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 32 manager_action_(kManagerActionNone), | 32 manager_action_(kManagerActionNone), | 
| 33 user_action_(kUserActionNone), | 33 user_action_(kUserActionNone), | 
| 34 submit_result_(kSubmitResultNotSubmitted) { | 34 submit_result_(kSubmitResultNotSubmitted) { | 
| 35 DCHECK(profile_); | 35 DCHECK(profile_); | 
| 36 if (observed_form_.origin.is_valid()) | 36 if (observed_form_.origin.is_valid()) | 
| 37 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); | 37 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); | 
| 38 observed_form_.ssl_valid = ssl_valid; | 38 observed_form_.ssl_valid = ssl_valid; | 
| 39 } | 39 } | 
| 40 | 40 | 
| 41 PasswordFormManager::~PasswordFormManager() { | 41 PasswordFormManager::~PasswordFormManager() { | 
| 42 CancelLoginsQuery(); | |
| 43 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", | 42 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", | 
| 44 GetActionsTaken(), | 43 GetActionsTaken(), | 
| 45 kMaxNumActionsTaken); | 44 kMaxNumActionsTaken); | 
| 46 } | 45 } | 
| 47 | 46 | 
| 48 int PasswordFormManager::GetActionsTaken() { | 47 int PasswordFormManager::GetActionsTaken() { | 
| 49 return user_action_ + kUserActionMax * (manager_action_ + | 48 return user_action_ + kUserActionMax * (manager_action_ + | 
| 50 kManagerActionMax * submit_result_); | 49 kManagerActionMax * submit_result_); | 
| 51 }; | 50 }; | 
| 52 | 51 | 
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 preferred_match_->action.GetWithEmptyPath(); | 298 preferred_match_->action.GetWithEmptyPath(); | 
| 300 if (wait_for_username) | 299 if (wait_for_username) | 
| 301 manager_action_ = kManagerActionNone; | 300 manager_action_ = kManagerActionNone; | 
| 302 else | 301 else | 
| 303 manager_action_ = kManagerActionAutoFilled; | 302 manager_action_ = kManagerActionAutoFilled; | 
| 304 password_manager_->Autofill(observed_form_, best_matches_, | 303 password_manager_->Autofill(observed_form_, best_matches_, | 
| 305 preferred_match_, wait_for_username); | 304 preferred_match_, wait_for_username); | 
| 306 } | 305 } | 
| 307 | 306 | 
| 308 void PasswordFormManager::OnPasswordStoreRequestDone( | 307 void PasswordFormManager::OnPasswordStoreRequestDone( | 
| 309 int handle, const std::vector<PasswordForm*>& result) { | 308 PasswordStore::Handle handle, | 
| 309 const std::vector<PasswordForm*>& result) { | |
| 310 DCHECK_EQ(state_, MATCHING_PHASE); | 310 DCHECK_EQ(state_, MATCHING_PHASE); | 
| 311 DCHECK_EQ(pending_login_query_, handle); | 311 DCHECK_EQ(pending_login_query_, handle); | 
| 312 | 312 | 
| 313 if (result.empty()) { | 313 if (result.empty()) { | 
| 314 state_ = POST_MATCHING_PHASE; | 314 state_ = POST_MATCHING_PHASE; | 
| 315 return; | 315 return; | 
| 316 } | 316 } | 
| 317 | 317 | 
| 318 OnRequestDone(handle, result); | 318 OnRequestDone(handle, result); | 
| 319 pending_login_query_ = PasswordStore::Handle(0); | |
| 
 
James Hawkins
2011/03/21 01:45:06
You're ignoring the fact that PasswordStore::Handl
 
Sheridan Rawlins
2011/03/21 05:20:17
Stuart said something similar before.  I think thi
 
 | |
| 319 } | 320 } | 
| 320 | 321 | 
| 321 bool PasswordFormManager::IgnoreResult(const PasswordForm& form) const { | 322 bool PasswordFormManager::IgnoreResult(const PasswordForm& form) const { | 
| 322 // Ignore change password forms until we have some change password | 323 // Ignore change password forms until we have some change password | 
| 323 // functionality | 324 // functionality | 
| 324 if (observed_form_.old_password_element.length() != 0) { | 325 if (observed_form_.old_password_element.length() != 0) { | 
| 325 return true; | 326 return true; | 
| 326 } | 327 } | 
| 327 // Don't match an invalid SSL form with one saved under secure | 328 // Don't match an invalid SSL form with one saved under secure | 
| 328 // circumstances. | 329 // circumstances. | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 // TODO(timsteele): Bug 1188626 - expire the master copies. | 414 // TODO(timsteele): Bug 1188626 - expire the master copies. | 
| 414 PasswordForm copy(pending_credentials_); | 415 PasswordForm copy(pending_credentials_); | 
| 415 copy.origin = observed_form_.origin; | 416 copy.origin = observed_form_.origin; | 
| 416 copy.action = observed_form_.action; | 417 copy.action = observed_form_.action; | 
| 417 password_store->AddLogin(copy); | 418 password_store->AddLogin(copy); | 
| 418 } else { | 419 } else { | 
| 419 password_store->UpdateLogin(pending_credentials_); | 420 password_store->UpdateLogin(pending_credentials_); | 
| 420 } | 421 } | 
| 421 } | 422 } | 
| 422 | 423 | 
| 423 void PasswordFormManager::CancelLoginsQuery() { | |
| 424 PasswordStore* password_store = | |
| 425 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); | |
| 426 if (!password_store) { | |
| 427 // Can be NULL in unit tests. | |
| 428 return; | |
| 429 } | |
| 430 password_store->CancelLoginsQuery(pending_login_query_); | |
| 431 } | |
| 432 | |
| 433 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { | 424 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { | 
| 434 DCHECK_EQ(state_, MATCHING_PHASE); | 425 DCHECK_EQ(state_, MATCHING_PHASE); | 
| 435 // For scoring of candidate login data: | 426 // For scoring of candidate login data: | 
| 436 // The most important element that should match is the origin, followed by | 427 // The most important element that should match is the origin, followed by | 
| 437 // the action, the password name, the submit button name, and finally the | 428 // the action, the password name, the submit button name, and finally the | 
| 438 // username input field name. | 429 // username input field name. | 
| 439 // Exact origin match gives an addition of 32 (1 << 5) + # of matching url | 430 // Exact origin match gives an addition of 32 (1 << 5) + # of matching url | 
| 440 // dirs. | 431 // dirs. | 
| 441 // Partial match gives an addition of 16 (1 << 4) + # matching url dirs | 432 // Partial match gives an addition of 16 (1 << 4) + # matching url dirs | 
| 442 // That way, a partial match cannot trump an exact match even if | 433 // That way, a partial match cannot trump an exact match even if | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 return score; | 470 return score; | 
| 480 } | 471 } | 
| 481 | 472 | 
| 482 void PasswordFormManager::SubmitPassed() { | 473 void PasswordFormManager::SubmitPassed() { | 
| 483 submit_result_ = kSubmitResultPassed; | 474 submit_result_ = kSubmitResultPassed; | 
| 484 } | 475 } | 
| 485 | 476 | 
| 486 void PasswordFormManager::SubmitFailed() { | 477 void PasswordFormManager::SubmitFailed() { | 
| 487 submit_result_ = kSubmitResultFailed; | 478 submit_result_ = kSubmitResultFailed; | 
| 488 } | 479 } | 
| OLD | NEW |