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

Side by Side Diff: chrome/browser/password_manager/password_form_manager.cc

Issue 6646051: Fix DCHECK, memory leak, and refactor PasswordStore to use CancelableRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use non-zero tests until http://crbug.com/77650 is addressed. Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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"
12 #include "chrome/browser/password_manager/password_manager.h" 12 #include "chrome/browser/password_manager/password_manager.h"
13 #include "chrome/browser/password_manager/password_store.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "webkit/glue/password_form_dom_manager.h" 15 #include "webkit/glue/password_form_dom_manager.h"
15 16
16 using base::Time; 17 using base::Time;
17 using webkit_glue::PasswordForm; 18 using webkit_glue::PasswordForm;
18 using webkit_glue::PasswordFormMap; 19 using webkit_glue::PasswordFormMap;
19 20
20 PasswordFormManager::PasswordFormManager(Profile* profile, 21 PasswordFormManager::PasswordFormManager(Profile* profile,
21 PasswordManager* password_manager, 22 PasswordManager* password_manager,
22 const PasswordForm& observed_form, 23 const PasswordForm& observed_form,
23 bool ssl_valid) 24 bool ssl_valid)
24 : best_matches_deleter_(&best_matches_), 25 : best_matches_deleter_(&best_matches_),
25 observed_form_(observed_form), 26 observed_form_(observed_form),
26 is_new_login_(true), 27 is_new_login_(true),
27 password_manager_(password_manager), 28 password_manager_(password_manager),
28 pending_login_query_(0), 29 pending_login_query_(0),
29 preferred_match_(NULL), 30 preferred_match_(NULL),
30 state_(PRE_MATCHING_PHASE), 31 state_(PRE_MATCHING_PHASE),
31 profile_(profile), 32 profile_(profile),
32 manager_action_(kManagerActionNone), 33 manager_action_(kManagerActionNone),
33 user_action_(kUserActionNone), 34 user_action_(kUserActionNone),
34 submit_result_(kSubmitResultNotSubmitted) { 35 submit_result_(kSubmitResultNotSubmitted) {
35 DCHECK(profile_); 36 DCHECK(profile_);
36 if (observed_form_.origin.is_valid()) 37 if (observed_form_.origin.is_valid())
37 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); 38 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_);
38 observed_form_.ssl_valid = ssl_valid; 39 observed_form_.ssl_valid = ssl_valid;
39 } 40 }
40 41
41 PasswordFormManager::~PasswordFormManager() { 42 PasswordFormManager::~PasswordFormManager() {
42 CancelLoginsQuery();
43 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", 43 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken",
44 GetActionsTaken(), 44 GetActionsTaken(),
45 kMaxNumActionsTaken); 45 kMaxNumActionsTaken);
46 } 46 }
47 47
48 int PasswordFormManager::GetActionsTaken() { 48 int PasswordFormManager::GetActionsTaken() {
49 return user_action_ + kUserActionMax * (manager_action_ + 49 return user_action_ + kUserActionMax * (manager_action_ +
50 kManagerActionMax * submit_result_); 50 kManagerActionMax * submit_result_);
51 }; 51 };
52 52
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 preferred_match_->action.GetWithEmptyPath(); 299 preferred_match_->action.GetWithEmptyPath();
300 if (wait_for_username) 300 if (wait_for_username)
301 manager_action_ = kManagerActionNone; 301 manager_action_ = kManagerActionNone;
302 else 302 else
303 manager_action_ = kManagerActionAutofilled; 303 manager_action_ = kManagerActionAutofilled;
304 password_manager_->Autofill(observed_form_, best_matches_, 304 password_manager_->Autofill(observed_form_, best_matches_,
305 preferred_match_, wait_for_username); 305 preferred_match_, wait_for_username);
306 } 306 }
307 307
308 void PasswordFormManager::OnPasswordStoreRequestDone( 308 void PasswordFormManager::OnPasswordStoreRequestDone(
309 int handle, const std::vector<PasswordForm*>& result) { 309 CancelableRequestProvider::Handle handle,
310 const std::vector<PasswordForm*>& result) {
310 DCHECK_EQ(state_, MATCHING_PHASE); 311 DCHECK_EQ(state_, MATCHING_PHASE);
311 DCHECK_EQ(pending_login_query_, handle); 312 DCHECK_EQ(pending_login_query_, handle);
312 313
313 if (result.empty()) { 314 if (result.empty()) {
314 state_ = POST_MATCHING_PHASE; 315 state_ = POST_MATCHING_PHASE;
315 return; 316 return;
316 } 317 }
317 318
318 OnRequestDone(handle, result); 319 OnRequestDone(handle, result);
320 pending_login_query_ = 0;
319 } 321 }
320 322
321 bool PasswordFormManager::IgnoreResult(const PasswordForm& form) const { 323 bool PasswordFormManager::IgnoreResult(const PasswordForm& form) const {
322 // Ignore change password forms until we have some change password 324 // Ignore change password forms until we have some change password
323 // functionality 325 // functionality
324 if (observed_form_.old_password_element.length() != 0) { 326 if (observed_form_.old_password_element.length() != 0) {
325 return true; 327 return true;
326 } 328 }
327 // Don't match an invalid SSL form with one saved under secure 329 // Don't match an invalid SSL form with one saved under secure
328 // circumstances. 330 // circumstances.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // TODO(timsteele): Bug 1188626 - expire the master copies. 415 // TODO(timsteele): Bug 1188626 - expire the master copies.
414 PasswordForm copy(pending_credentials_); 416 PasswordForm copy(pending_credentials_);
415 copy.origin = observed_form_.origin; 417 copy.origin = observed_form_.origin;
416 copy.action = observed_form_.action; 418 copy.action = observed_form_.action;
417 password_store->AddLogin(copy); 419 password_store->AddLogin(copy);
418 } else { 420 } else {
419 password_store->UpdateLogin(pending_credentials_); 421 password_store->UpdateLogin(pending_credentials_);
420 } 422 }
421 } 423 }
422 424
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 { 425 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const {
434 DCHECK_EQ(state_, MATCHING_PHASE); 426 DCHECK_EQ(state_, MATCHING_PHASE);
435 // For scoring of candidate login data: 427 // For scoring of candidate login data:
436 // The most important element that should match is the origin, followed by 428 // 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 429 // the action, the password name, the submit button name, and finally the
438 // username input field name. 430 // username input field name.
439 // Exact origin match gives an addition of 32 (1 << 5) + # of matching url 431 // Exact origin match gives an addition of 32 (1 << 5) + # of matching url
440 // dirs. 432 // dirs.
441 // Partial match gives an addition of 16 (1 << 4) + # matching url dirs 433 // 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 434 // That way, a partial match cannot trump an exact match even if
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 return score; 471 return score;
480 } 472 }
481 473
482 void PasswordFormManager::SubmitPassed() { 474 void PasswordFormManager::SubmitPassed() {
483 submit_result_ = kSubmitResultPassed; 475 submit_result_ = kSubmitResultPassed;
484 } 476 }
485 477
486 void PasswordFormManager::SubmitFailed() { 478 void PasswordFormManager::SubmitFailed() {
487 submit_result_ = kSubmitResultFailed; 479 submit_result_ = kSubmitResultFailed;
488 } 480 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_form_manager.h ('k') | chrome/browser/password_manager/password_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698