| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_ |
| 6 #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" |
| 12 #include "components/autofill/core/common/password_form.h" |
| 13 #include "components/password_manager/core/browser/password_store_change.h" |
| 14 #include "components/password_manager/core/common/password_manager_ui.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace password_manager { |
| 18 struct CredentialInfo; |
| 19 class PasswordFormManager; |
| 20 class PasswordManagerClient; |
| 21 } |
| 22 |
| 23 |
| 24 // ManagePasswordsState keeps the current state for ManagePasswordsUIController |
| 25 // as well as up-to-date data for this state. |
| 26 class ManagePasswordsState { |
| 27 public: |
| 28 using CredentialsCallback = |
| 29 base::Callback<void(const password_manager::CredentialInfo&)>; |
| 30 |
| 31 ManagePasswordsState(); |
| 32 ~ManagePasswordsState(); |
| 33 |
| 34 // Set the client for logging. |
| 35 void set_client(password_manager::PasswordManagerClient* client) { |
| 36 client_ = client; |
| 37 } |
| 38 |
| 39 // The methods below discard the current state/data of the object and move it |
| 40 // to the specified state. |
| 41 |
| 42 // Move to PENDING_PASSWORD_STATE. |
| 43 void OnPendingPassword( |
| 44 scoped_ptr<password_manager::PasswordFormManager> form_manager); |
| 45 |
| 46 // Move to CREDENTIAL_REQUEST_STATE. |
| 47 void OnRequestCredentials( |
| 48 ScopedVector<autofill::PasswordForm> local_credentials, |
| 49 ScopedVector<autofill::PasswordForm> federated_credentials, |
| 50 const GURL& origin); |
| 51 |
| 52 // Move to AUTO_SIGNIN_STATE. |local_forms| can't be empty. |
| 53 void OnAutoSignin(ScopedVector<autofill::PasswordForm> local_forms); |
| 54 |
| 55 // Move to CONFIRMATION_STATE. |
| 56 void OnAutomaticPasswordSave( |
| 57 scoped_ptr<password_manager::PasswordFormManager> form_manager); |
| 58 |
| 59 // Move to MANAGE_STATE or INACTIVE_STATE for PSL matched passwords. |
| 60 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map); |
| 61 |
| 62 // Move to BLACKLIST_STATE. |
| 63 void OnBlacklistBlockedAutofill( |
| 64 const autofill::PasswordFormMap& password_form_map); |
| 65 |
| 66 // Move to INACTIVE_STATE. |
| 67 void OnInactive(); |
| 68 |
| 69 // Moves the object to |state| without resetting the internal data. Allowed: |
| 70 // * -> BLACKLIST_STATE |
| 71 // * -> MANAGE_STATE |
| 72 void TransitionToState(password_manager::ui::State state); |
| 73 |
| 74 // Updates the internal state applying |changes|. |
| 75 void ProcessLoginsChanged( |
| 76 const password_manager::PasswordStoreChangeList& changes); |
| 77 |
| 78 password_manager::ui::State state() const { return state_; } |
| 79 const GURL& origin() const { return origin_; } |
| 80 password_manager::PasswordFormManager* form_manager() const { |
| 81 return form_manager_.get(); |
| 82 } |
| 83 const CredentialsCallback& credentials_callback() { |
| 84 return credentials_callback_; |
| 85 } |
| 86 void set_credentials_callback(const CredentialsCallback& callback) { |
| 87 credentials_callback_ = callback; |
| 88 } |
| 89 |
| 90 // Current local forms. ManagePasswordsState is responsible for the forms. |
| 91 const std::vector<const autofill::PasswordForm*>& GetCurrentForms() const { |
| 92 return form_manager_ ? current_forms_weak_ : local_credentials_forms_.get(); |
| 93 } |
| 94 |
| 95 // Current federated forms. |
| 96 const std::vector<const autofill::PasswordForm*>& |
| 97 federated_credentials_forms() const { |
| 98 return federated_credentials_forms_.get(); |
| 99 } |
| 100 |
| 101 private: |
| 102 // Removes all the PasswordForms stored in this object. |
| 103 void ClearData(); |
| 104 |
| 105 // Add |form| to the internal state. |
| 106 void AddForm(const autofill::PasswordForm& form); |
| 107 // Updates |form| in the internal state. |
| 108 bool UpdateForm(const autofill::PasswordForm& form); |
| 109 // Removes |form| from the internal state. |
| 110 void DeleteForm(const autofill::PasswordForm& form); |
| 111 |
| 112 void SetState(password_manager::ui::State state); |
| 113 |
| 114 // The origin of the current page. It's used to determine which PasswordStore |
| 115 // changes are applicable to the internal state. |
| 116 GURL origin_; |
| 117 |
| 118 // Contains the password that was submitted. |
| 119 scoped_ptr<password_manager::PasswordFormManager> form_manager_; |
| 120 |
| 121 // Weak references to the passwords for the current status. The hard pointers |
| 122 // are scattered between |form_manager_| and |local_credentials_forms_|. If |
| 123 // |form_manager_| is nullptr then all the forms are stored in |
| 124 // |local_credentials_forms_|. |current_forms_weak_| remains empty. |
| 125 std::vector<const autofill::PasswordForm*> current_forms_weak_; |
| 126 |
| 127 // If |form_manager_| is nullptr then |local_credentials_forms_| contains all |
| 128 // the current forms. Otherwise, it's a container for the new forms coming |
| 129 // from the PasswordStore. |
| 130 ScopedVector<const autofill::PasswordForm> local_credentials_forms_; |
| 131 |
| 132 // Federated credentials for the CREDENTIAL_REQUEST_STATE. |
| 133 ScopedVector<const autofill::PasswordForm> federated_credentials_forms_; |
| 134 |
| 135 // A callback to be invoked when user selects a credential. |
| 136 CredentialsCallback credentials_callback_; |
| 137 |
| 138 // The current state of the password manager UI. |
| 139 password_manager::ui::State state_; |
| 140 |
| 141 // The client used for logging. |
| 142 password_manager::PasswordManagerClient* client_; |
| 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsState); |
| 145 }; |
| 146 |
| 147 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_ |
| OLD | NEW |