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

Side by Side Diff: chrome/browser/ui/webui/options/password_manager_handler.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: Responding to review comments. 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/ui/webui/options/password_manager_handler.h" 5 #include "chrome/browser/ui/webui/options/password_manager_handler.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/stl_util-inl.h"
9 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 10 #include "base/values.h"
12 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
15 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
16 #include "grit/chromium_strings.h" 15 #include "grit/chromium_strings.h"
17 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
18 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
19 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
20 19
21 PasswordManagerHandler::PasswordManagerHandler() 20 PasswordManagerHandler::PasswordManagerHandler()
22 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)), 21 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)),
23 ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) { 22 ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) {
24 } 23 }
25 24
26 PasswordManagerHandler::~PasswordManagerHandler() { 25 PasswordManagerHandler::~PasswordManagerHandler() {
27 // TODO(scr): ScopedVector.
28 STLDeleteElements(&password_list_);
29 STLDeleteElements(&password_exception_list_);
30 GetPasswordStore()->RemoveObserver(this); 26 GetPasswordStore()->RemoveObserver(this);
31 } 27 }
32 28
33 void PasswordManagerHandler::GetLocalizedValues( 29 void PasswordManagerHandler::GetLocalizedValues(
34 DictionaryValue* localized_strings) { 30 DictionaryValue* localized_strings) {
35 DCHECK(localized_strings); 31 DCHECK(localized_strings);
36 32
37 RegisterTitle(localized_strings, "passwordsPage", 33 RegisterTitle(localized_strings, "passwordsPage",
38 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); 34 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE);
39 localized_strings->SetString("savedPasswordsTitle", 35 localized_strings->SetString("savedPasswordsTitle",
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void PasswordManagerHandler::OnLoginsChanged() { 79 void PasswordManagerHandler::OnLoginsChanged() {
84 UpdatePasswordLists(NULL); 80 UpdatePasswordLists(NULL);
85 } 81 }
86 82
87 PasswordStore* PasswordManagerHandler::GetPasswordStore() { 83 PasswordStore* PasswordManagerHandler::GetPasswordStore() {
88 return web_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); 84 return web_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS);
89 } 85 }
90 86
91 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { 87 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) {
92 // Reset the current lists. 88 // Reset the current lists.
93 STLDeleteElements(&password_list_); 89 password_list_.reset();
94 STLDeleteElements(&password_exception_list_); 90 password_exception_list_.reset();
95 91
96 languages_ = 92 languages_ =
97 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); 93 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
98 populater_.Populate(); 94 populater_.Populate();
99 exception_populater_.Populate(); 95 exception_populater_.Populate();
100 } 96 }
101 97
102 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { 98 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) {
103 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); 99 std::string string_value = UTF16ToUTF8(ExtractStringValue(args));
104 int index; 100 int index;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 ListValue entries; 146 ListValue entries;
151 for (size_t i = 0; i < password_exception_list_.size(); ++i) { 147 for (size_t i = 0; i < password_exception_list_.size(); ++i) {
152 entries.Append(new StringValue( 148 entries.Append(new StringValue(
153 net::FormatUrl(password_exception_list_[i]->origin, languages_))); 149 net::FormatUrl(password_exception_list_[i]->origin, languages_)));
154 } 150 }
155 151
156 web_ui_->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", 152 web_ui_->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList",
157 entries); 153 entries);
158 } 154 }
159 155
156 PasswordManagerHandler::ListPopulater::~ListPopulater() {
James Hawkins 2011/03/21 01:45:06 Source ordering: ~ListPopulater() implementation s
Sheridan Rawlins 2011/03/21 05:20:17 Done.
157 }
158
160 PasswordManagerHandler::ListPopulater::ListPopulater( 159 PasswordManagerHandler::ListPopulater::ListPopulater(
161 PasswordManagerHandler* page) : page_(page), 160 PasswordManagerHandler* page) : page_(page),
162 pending_login_query_(0) { 161 pending_login_query_(0) {
James Hawkins 2011/03/21 01:45:06 |pending_login_query_| should be a PasswordStore::
Sheridan Rawlins 2011/03/21 05:20:17 Done.
163 } 162 }
164 163
165 PasswordManagerHandler::ListPopulater::~ListPopulater() {
166 PasswordStore* store = page_->GetPasswordStore();
167 if (store)
168 store->CancelLoginsQuery(pending_login_query_);
169 }
170
171 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( 164 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater(
172 PasswordManagerHandler* page) : ListPopulater(page) { 165 PasswordManagerHandler* page) : ListPopulater(page) {
173 } 166 }
174 167
175 void PasswordManagerHandler::PasswordListPopulater::Populate() { 168 void PasswordManagerHandler::PasswordListPopulater::Populate() {
176 DCHECK(!pending_login_query_);
177 PasswordStore* store = page_->GetPasswordStore(); 169 PasswordStore* store = page_->GetPasswordStore();
178 if (store != NULL) 170 if (store != NULL) {
171 if (pending_login_query_)
James Hawkins 2011/03/21 01:45:06 Isn't PasswordStore::Handle opaque? We're assumin
Sheridan Rawlins 2011/03/21 05:20:17 Done.
172 store->CancelRequest(pending_login_query_);
173
179 pending_login_query_ = store->GetAutofillableLogins(this); 174 pending_login_query_ = store->GetAutofillableLogins(this);
180 else 175 } else {
181 LOG(ERROR) << "No password store! Cannot display passwords."; 176 LOG(ERROR) << "No password store! Cannot display passwords.";
177 }
182 } 178 }
183 179
184 void PasswordManagerHandler::PasswordListPopulater:: 180 void PasswordManagerHandler::PasswordListPopulater::
185 OnPasswordStoreRequestDone(int handle, 181 OnPasswordStoreRequestDone(
186 const std::vector<webkit_glue::PasswordForm*>& result) { 182 PasswordStore::Handle handle,
183 const std::vector<webkit_glue::PasswordForm*>& result) {
187 DCHECK_EQ(pending_login_query_, handle); 184 DCHECK_EQ(pending_login_query_, handle);
188 pending_login_query_ = 0; 185 pending_login_query_ = 0;
189 page_->password_list_ = result; 186 page_->password_list_.reset();
187 page_->password_list_.insert(page_->password_list_.end(),
188 result.begin(), result.end());
190 page_->SetPasswordList(); 189 page_->SetPasswordList();
191 } 190 }
192 191
193 PasswordManagerHandler::PasswordExceptionListPopulater:: 192 PasswordManagerHandler::PasswordExceptionListPopulater::
194 PasswordExceptionListPopulater(PasswordManagerHandler* page) 193 PasswordExceptionListPopulater(PasswordManagerHandler* page)
195 : ListPopulater(page) { 194 : ListPopulater(page) {
196 } 195 }
197 196
198 void PasswordManagerHandler::PasswordExceptionListPopulater::Populate() { 197 void PasswordManagerHandler::PasswordExceptionListPopulater::Populate() {
199 DCHECK(!pending_login_query_);
200 PasswordStore* store = page_->GetPasswordStore(); 198 PasswordStore* store = page_->GetPasswordStore();
201 if (store != NULL) 199 if (store != NULL) {
200 if (pending_login_query_)
201 store->CancelRequest(pending_login_query_);
202
202 pending_login_query_ = store->GetBlacklistLogins(this); 203 pending_login_query_ = store->GetBlacklistLogins(this);
203 else 204 } else {
204 LOG(ERROR) << "No password store! Cannot display exceptions."; 205 LOG(ERROR) << "No password store! Cannot display exceptions.";
206 }
205 } 207 }
206 208
207 void PasswordManagerHandler::PasswordExceptionListPopulater:: 209 void PasswordManagerHandler::PasswordExceptionListPopulater::
208 OnPasswordStoreRequestDone(int handle, 210 OnPasswordStoreRequestDone(
209 const std::vector<webkit_glue::PasswordForm*>& result) { 211 PasswordStore::Handle handle,
212 const std::vector<webkit_glue::PasswordForm*>& result) {
210 DCHECK_EQ(pending_login_query_, handle); 213 DCHECK_EQ(pending_login_query_, handle);
211 pending_login_query_ = 0; 214 pending_login_query_ = 0;
212 page_->password_exception_list_ = result; 215 page_->password_exception_list_.reset();
216 page_->password_exception_list_.insert(page_->password_exception_list_.end(),
217 result.begin(), result.end());
213 page_->SetPasswordExceptionList(); 218 page_->SetPasswordExceptionList();
214 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698