Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 delete password_exception_list_[index]; | 106 delete password_exception_list_[index]; |
| 108 password_exception_list_.erase(password_exception_list_.begin() + index); | 107 password_exception_list_.erase(password_exception_list_.begin() + index); |
| 109 SetPasswordExceptionList(); | 108 SetPasswordExceptionList(); |
| 110 } | 109 } |
| 111 | 110 |
| 112 void PasswordManagerHandler::RemoveAllSavedPasswords( | 111 void PasswordManagerHandler::RemoveAllSavedPasswords( |
| 113 const ListValue* args) { | 112 const ListValue* args) { |
| 114 PasswordStore* store = GetPasswordStore(); | 113 PasswordStore* store = GetPasswordStore(); |
| 115 for (size_t i = 0; i < password_list_.size(); ++i) | 114 for (size_t i = 0; i < password_list_.size(); ++i) |
| 116 store->RemoveLogin(*password_list_[i]); | 115 store->RemoveLogin(*password_list_[i]); |
| 117 STLDeleteElements(&password_list_); | 116 password_list_.reset(); |
| 118 SetPasswordList(); | 117 SetPasswordList(); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void PasswordManagerHandler::RemoveAllPasswordExceptions( | 120 void PasswordManagerHandler::RemoveAllPasswordExceptions( |
| 122 const ListValue* args) { | 121 const ListValue* args) { |
| 123 PasswordStore* store = GetPasswordStore(); | 122 PasswordStore* store = GetPasswordStore(); |
| 124 for (size_t i = 0; i < password_exception_list_.size(); ++i) | 123 for (size_t i = 0; i < password_exception_list_.size(); ++i) |
| 125 store->RemoveLogin(*password_exception_list_[i]); | 124 store->RemoveLogin(*password_exception_list_[i]); |
| 126 STLDeleteElements(&password_exception_list_); | 125 password_exception_list_.reset(); |
| 127 SetPasswordExceptionList(); | 126 SetPasswordExceptionList(); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void PasswordManagerHandler::SetPasswordList() { | 129 void PasswordManagerHandler::SetPasswordList() { |
| 131 ListValue entries; | 130 ListValue entries; |
| 132 for (size_t i = 0; i < password_list_.size(); ++i) { | 131 for (size_t i = 0; i < password_list_.size(); ++i) { |
| 133 ListValue* entry = new ListValue(); | 132 ListValue* entry = new ListValue(); |
| 134 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, | 133 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, |
| 135 languages_))); | 134 languages_))); |
| 136 entry->Append(new StringValue(password_list_[i]->username_value)); | 135 entry->Append(new StringValue(password_list_[i]->username_value)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 151 | 150 |
| 152 web_ui_->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 151 web_ui_->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", |
| 153 entries); | 152 entries); |
| 154 } | 153 } |
| 155 | 154 |
| 156 PasswordManagerHandler::ListPopulater::ListPopulater( | 155 PasswordManagerHandler::ListPopulater::ListPopulater( |
| 157 PasswordManagerHandler* page) : page_(page), | 156 PasswordManagerHandler* page) : page_(page), |
| 158 pending_login_query_(0) { | 157 pending_login_query_(0) { |
| 159 } | 158 } |
| 160 | 159 |
| 161 PasswordManagerHandler::ListPopulater::~ListPopulater() { | |
| 162 PasswordStore* store = page_->GetPasswordStore(); | |
| 163 if (store) | |
| 164 store->CancelLoginsQuery(pending_login_query_); | |
| 165 } | |
| 166 | |
| 167 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( | 160 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( |
| 168 PasswordManagerHandler* page) : ListPopulater(page) { | 161 PasswordManagerHandler* page) : ListPopulater(page) { |
| 169 } | 162 } |
| 170 | 163 |
| 171 void PasswordManagerHandler::PasswordListPopulater::Populate() { | 164 void PasswordManagerHandler::PasswordListPopulater::Populate() { |
| 172 DCHECK(!pending_login_query_); | |
| 173 PasswordStore* store = page_->GetPasswordStore(); | 165 PasswordStore* store = page_->GetPasswordStore(); |
| 174 if (store != NULL) | 166 if (store != NULL) { |
| 167 if (pending_login_query_) | |
| 168 store->CancelRequest(pending_login_query_); | |
|
stuartmorgan
2011/03/16 23:25:20
Why the change from DCHECK to handling gracefully?
Sheridan Rawlins
2011/03/18 15:45:48
My thought was that Populate should just "make it
| |
| 169 | |
| 175 pending_login_query_ = store->GetAutofillableLogins(this); | 170 pending_login_query_ = store->GetAutofillableLogins(this); |
| 176 else | 171 } else { |
| 177 LOG(ERROR) << "No password store! Cannot display passwords."; | 172 LOG(ERROR) << "No password store! Cannot display passwords."; |
| 173 } | |
| 178 } | 174 } |
| 179 | 175 |
| 180 void PasswordManagerHandler::PasswordListPopulater:: | 176 void PasswordManagerHandler::PasswordListPopulater:: |
| 181 OnPasswordStoreRequestDone(int handle, | 177 OnPasswordStoreRequestDone( |
| 182 const std::vector<webkit_glue::PasswordForm*>& result) { | 178 PasswordStore::Handle handle, |
| 179 const std::vector<webkit_glue::PasswordForm*>& result) { | |
| 183 DCHECK_EQ(pending_login_query_, handle); | 180 DCHECK_EQ(pending_login_query_, handle); |
| 184 pending_login_query_ = 0; | 181 pending_login_query_ = 0; |
| 185 page_->password_list_ = result; | 182 page_->password_list_.reset(result); |
| 186 page_->SetPasswordList(); | 183 page_->SetPasswordList(); |
| 187 } | 184 } |
| 188 | 185 |
| 189 PasswordManagerHandler::PasswordExceptionListPopulater:: | 186 PasswordManagerHandler::PasswordExceptionListPopulater:: |
| 190 PasswordExceptionListPopulater(PasswordManagerHandler* page) | 187 PasswordExceptionListPopulater(PasswordManagerHandler* page) |
| 191 : ListPopulater(page) { | 188 : ListPopulater(page) { |
| 192 } | 189 } |
| 193 | 190 |
| 194 void PasswordManagerHandler::PasswordExceptionListPopulater::Populate() { | 191 void PasswordManagerHandler::PasswordExceptionListPopulater::Populate() { |
| 195 DCHECK(!pending_login_query_); | |
| 196 PasswordStore* store = page_->GetPasswordStore(); | 192 PasswordStore* store = page_->GetPasswordStore(); |
| 197 if (store != NULL) | 193 if (store != NULL) { |
| 194 if (pending_login_query_) | |
| 195 store->CancelRequest(pending_login_query_); | |
| 196 | |
| 198 pending_login_query_ = store->GetBlacklistLogins(this); | 197 pending_login_query_ = store->GetBlacklistLogins(this); |
| 199 else | 198 } else { |
| 200 LOG(ERROR) << "No password store! Cannot display exceptions."; | 199 LOG(ERROR) << "No password store! Cannot display exceptions."; |
| 200 } | |
| 201 } | 201 } |
| 202 | 202 |
| 203 void PasswordManagerHandler::PasswordExceptionListPopulater:: | 203 void PasswordManagerHandler::PasswordExceptionListPopulater:: |
| 204 OnPasswordStoreRequestDone(int handle, | 204 OnPasswordStoreRequestDone( |
| 205 const std::vector<webkit_glue::PasswordForm*>& result) { | 205 PasswordStore::Handle handle, |
| 206 const std::vector<webkit_glue::PasswordForm*>& result) { | |
| 206 DCHECK_EQ(pending_login_query_, handle); | 207 DCHECK_EQ(pending_login_query_, handle); |
| 207 pending_login_query_ = 0; | 208 pending_login_query_ = 0; |
| 208 page_->password_exception_list_ = result; | 209 page_->password_exception_list_.reset(result); |
| 209 page_->SetPasswordExceptionList(); | 210 page_->SetPasswordExceptionList(); |
| 210 } | 211 } |
| OLD | NEW |