| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/passwords/manage_passwords_state.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_state.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 form_manager_ = std::move(form_manager); | 92 form_manager_ = std::move(form_manager); |
| 93 local_credentials_forms_ = DeepCopyMapToVector(form_manager_->best_matches()); | 93 local_credentials_forms_ = DeepCopyMapToVector(form_manager_->best_matches()); |
| 94 AppendDeepCopyVector(form_manager_->form_fetcher()->GetFederatedMatches(), | 94 AppendDeepCopyVector(form_manager_->form_fetcher()->GetFederatedMatches(), |
| 95 &local_credentials_forms_); | 95 &local_credentials_forms_); |
| 96 origin_ = form_manager_->observed_form().origin; | 96 origin_ = form_manager_->observed_form().origin; |
| 97 SetState(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE); | 97 SetState(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void ManagePasswordsState::OnRequestCredentials( | 100 void ManagePasswordsState::OnRequestCredentials( |
| 101 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials, | 101 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials, |
| 102 std::vector<std::unique_ptr<autofill::PasswordForm>> federation_providers, | |
| 103 const GURL& origin) { | 102 const GURL& origin) { |
| 104 ClearData(); | 103 ClearData(); |
| 105 local_credentials_forms_ = std::move(local_credentials); | 104 local_credentials_forms_ = std::move(local_credentials); |
| 106 federation_providers_forms_ = std::move(federation_providers); | |
| 107 origin_ = origin; | 105 origin_ = origin; |
| 108 SetState(password_manager::ui::CREDENTIAL_REQUEST_STATE); | 106 SetState(password_manager::ui::CREDENTIAL_REQUEST_STATE); |
| 109 } | 107 } |
| 110 | 108 |
| 111 void ManagePasswordsState::OnAutoSignin( | 109 void ManagePasswordsState::OnAutoSignin( |
| 112 std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms, | 110 std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms, |
| 113 const GURL& origin) { | 111 const GURL& origin) { |
| 114 DCHECK(!local_forms.empty()); | 112 DCHECK(!local_forms.empty()); |
| 115 ClearData(); | 113 ClearData(); |
| 116 local_credentials_forms_ = std::move(local_forms); | 114 local_credentials_forms_ = std::move(local_forms); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 178 |
| 181 void ManagePasswordsState::TransitionToState( | 179 void ManagePasswordsState::TransitionToState( |
| 182 password_manager::ui::State state) { | 180 password_manager::ui::State state) { |
| 183 DCHECK_NE(password_manager::ui::INACTIVE_STATE, state_); | 181 DCHECK_NE(password_manager::ui::INACTIVE_STATE, state_); |
| 184 DCHECK_EQ(password_manager::ui::MANAGE_STATE, state); | 182 DCHECK_EQ(password_manager::ui::MANAGE_STATE, state); |
| 185 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 183 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
| 186 if (!credentials_callback_.is_null()) { | 184 if (!credentials_callback_.is_null()) { |
| 187 credentials_callback_.Run(nullptr); | 185 credentials_callback_.Run(nullptr); |
| 188 credentials_callback_.Reset(); | 186 credentials_callback_.Reset(); |
| 189 } | 187 } |
| 190 federation_providers_forms_.clear(); | |
| 191 } | 188 } |
| 192 SetState(state); | 189 SetState(state); |
| 193 } | 190 } |
| 194 | 191 |
| 195 void ManagePasswordsState::ProcessLoginsChanged( | 192 void ManagePasswordsState::ProcessLoginsChanged( |
| 196 const password_manager::PasswordStoreChangeList& changes) { | 193 const password_manager::PasswordStoreChangeList& changes) { |
| 197 if (state() == password_manager::ui::INACTIVE_STATE) | 194 if (state() == password_manager::ui::INACTIVE_STATE) |
| 198 return; | 195 return; |
| 199 | 196 |
| 200 for (const password_manager::PasswordStoreChange& change : changes) { | 197 for (const password_manager::PasswordStoreChange& change : changes) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 217 DCHECK_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, state()); | 214 DCHECK_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, state()); |
| 218 DCHECK(!credentials_callback().is_null()); | 215 DCHECK(!credentials_callback().is_null()); |
| 219 | 216 |
| 220 credentials_callback().Run(form); | 217 credentials_callback().Run(form); |
| 221 set_credentials_callback(ManagePasswordsState::CredentialsCallback()); | 218 set_credentials_callback(ManagePasswordsState::CredentialsCallback()); |
| 222 } | 219 } |
| 223 | 220 |
| 224 void ManagePasswordsState::ClearData() { | 221 void ManagePasswordsState::ClearData() { |
| 225 form_manager_.reset(); | 222 form_manager_.reset(); |
| 226 local_credentials_forms_.clear(); | 223 local_credentials_forms_.clear(); |
| 227 federation_providers_forms_.clear(); | |
| 228 credentials_callback_.Reset(); | 224 credentials_callback_.Reset(); |
| 229 } | 225 } |
| 230 | 226 |
| 231 void ManagePasswordsState::AddForm(const autofill::PasswordForm& form) { | 227 void ManagePasswordsState::AddForm(const autofill::PasswordForm& form) { |
| 232 if (form.origin != origin_) | 228 if (form.origin != origin_) |
| 233 return; | 229 return; |
| 234 if (UpdateForm(form)) | 230 if (UpdateForm(form)) |
| 235 return; | 231 return; |
| 236 local_credentials_forms_.push_back( | 232 local_credentials_forms_.push_back( |
| 237 base::MakeUnique<autofill::PasswordForm>(form)); | 233 base::MakeUnique<autofill::PasswordForm>(form)); |
| 238 } | 234 } |
| 239 | 235 |
| 240 bool ManagePasswordsState::UpdateForm(const autofill::PasswordForm& form) { | 236 bool ManagePasswordsState::UpdateForm(const autofill::PasswordForm& form) { |
| 241 bool updated_locals = UpdateFormInVector(form, &local_credentials_forms_); | 237 return UpdateFormInVector(form, &local_credentials_forms_); |
| 242 return (UpdateFormInVector(form, &federation_providers_forms_) || | |
| 243 updated_locals); | |
| 244 } | 238 } |
| 245 | 239 |
| 246 void ManagePasswordsState::DeleteForm(const autofill::PasswordForm& form) { | 240 void ManagePasswordsState::DeleteForm(const autofill::PasswordForm& form) { |
| 247 RemoveFormFromVector(form, &local_credentials_forms_); | 241 RemoveFormFromVector(form, &local_credentials_forms_); |
| 248 RemoveFormFromVector(form, &federation_providers_forms_); | |
| 249 } | 242 } |
| 250 | 243 |
| 251 void ManagePasswordsState::SetState(password_manager::ui::State state) { | 244 void ManagePasswordsState::SetState(password_manager::ui::State state) { |
| 252 DCHECK(client_); | 245 DCHECK(client_); |
| 253 if (client_->GetLogManager()->IsLoggingActive()) { | 246 if (client_->GetLogManager()->IsLoggingActive()) { |
| 254 password_manager::BrowserSavePasswordProgressLogger logger( | 247 password_manager::BrowserSavePasswordProgressLogger logger( |
| 255 client_->GetLogManager()); | 248 client_->GetLogManager()); |
| 256 logger.LogNumber( | 249 logger.LogNumber( |
| 257 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, | 250 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, |
| 258 state); | 251 state); |
| 259 } | 252 } |
| 260 state_ = state; | 253 state_ = state; |
| 261 } | 254 } |
| OLD | NEW |