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

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

Issue 9586023: Fix memory failures in PasswordManager tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
« no previous file with comments | « no previous file | chrome/browser/password_manager/password_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/password_form_manager.h" 9 #include "chrome/browser/password_manager/password_form_manager.h"
10 #include "chrome/browser/password_manager/password_manager_delegate.h" 10 #include "chrome/browser/password_manager/password_manager_delegate.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { 77 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) {
78 if (!IsEnabled()) 78 if (!IsEnabled())
79 return; 79 return;
80 80
81 // No password to save? Then don't. 81 // No password to save? Then don't.
82 if (form.password_value.empty()) 82 if (form.password_value.empty())
83 return; 83 return;
84 84
85 PasswordFormManager* manager = NULL; 85 scoped_ptr<PasswordFormManager> manager;
86 for (ScopedVector<PasswordFormManager>::iterator iter = 86 for (ScopedVector<PasswordFormManager>::iterator iter =
87 pending_login_managers_.begin(); 87 pending_login_managers_.begin();
88 iter != pending_login_managers_.end(); ++iter) { 88 iter != pending_login_managers_.end(); ++iter) {
89 if ((*iter)->DoesManage(form)) { 89 if ((*iter)->DoesManage(form)) {
90 manager = *iter; 90 manager.reset(*iter);
dhollowa 2012/03/02 23:49:35 A comment here would be nice. "Transfer ownership
91 pending_login_managers_.weak_erase(iter); 91 pending_login_managers_.weak_erase(iter);
92 break; 92 break;
93 } 93 }
94 } 94 }
95 // If we didn't find a manager, this means a form was submitted without 95 // If we didn't find a manager, this means a form was submitted without
96 // first loading the page containing the form. Don't offer to save 96 // first loading the page containing the form. Don't offer to save
97 // passwords in this case. 97 // passwords in this case.
98 if (!manager) 98 if (!manager.get())
99 return; 99 return;
100 100
101 // If we found a manager but it didn't finish matching yet, the user has 101 // If we found a manager but it didn't finish matching yet, the user has
102 // tried to submit credentials before we had time to even find matching 102 // tried to submit credentials before we had time to even find matching
103 // results for the given form and autofill. If this is the case, we just 103 // results for the given form and autofill. If this is the case, we just
104 // give up. 104 // give up.
105 if (!manager->HasCompletedMatching()) 105 if (!manager->HasCompletedMatching())
106 return; 106 return;
107 107
108 // Also get out of here if the user told us to 'never remember' passwords for 108 // Also get out of here if the user told us to 'never remember' passwords for
109 // this form. 109 // this form.
110 if (manager->IsBlacklisted()) 110 if (manager->IsBlacklisted())
111 return; 111 return;
112 112
113 PasswordForm provisionally_saved_form(form); 113 PasswordForm provisionally_saved_form(form);
114 provisionally_saved_form.ssl_valid = form.origin.SchemeIsSecure() && 114 provisionally_saved_form.ssl_valid = form.origin.SchemeIsSecure() &&
115 !delegate_->DidLastPageLoadEncounterSSLErrors(); 115 !delegate_->DidLastPageLoadEncounterSSLErrors();
116 provisionally_saved_form.preferred = true; 116 provisionally_saved_form.preferred = true;
117 manager->ProvisionallySave(provisionally_saved_form); 117 manager->ProvisionallySave(provisionally_saved_form);
118 provisional_save_manager_.reset(manager); 118 provisional_save_manager_.swap(manager);
119 } 119 }
120 120
121 void PasswordManager::SetObserver(LoginModelObserver* observer) { 121 void PasswordManager::SetObserver(LoginModelObserver* observer) {
122 observer_ = observer; 122 observer_ = observer;
123 } 123 }
124 124
125 void PasswordManager::DidStopLoading() { 125 void PasswordManager::DidStopLoading() {
126 if (!provisional_save_manager_.get()) 126 if (!provisional_save_manager_.get())
127 return; 127 return;
128 128
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 observer_->OnAutofillDataAvailable(preferred_match.username_value, 232 observer_->OnAutofillDataAvailable(preferred_match.username_value,
233 preferred_match.password_value); 233 preferred_match.password_value);
234 } 234 }
235 } 235 }
236 } 236 }
237 237
238 bool PasswordManager::IsEnabled() const { 238 bool PasswordManager::IsEnabled() const {
239 const Profile* profile = delegate_->GetProfileForPasswordManager(); 239 const Profile* profile = delegate_->GetProfileForPasswordManager();
240 return profile && !profile->IsOffTheRecord() && *password_manager_enabled_; 240 return profile && !profile->IsOffTheRecord() && *password_manager_enabled_;
241 } 241 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/password_manager/password_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698