Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / passwords / manage_passwords_state.h
blob349ea30248e3f3c53c674f510d7d15029b8bda1d
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.
5 #ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_
6 #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_
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"
17 namespace password_manager {
18 struct CredentialInfo;
19 class PasswordFormManager;
20 class PasswordManagerClient;
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&)>;
31 ManagePasswordsState();
32 ~ManagePasswordsState();
34 // The embedder of this class has to set the client for logging.
35 void set_client(password_manager::PasswordManagerClient* client) {
36 client_ = client;
39 // The methods below discard the current state/data of the object and move it
40 // to the specified state.
42 // Move to PENDING_PASSWORD_STATE.
43 void OnPendingPassword(
44 scoped_ptr<password_manager::PasswordFormManager> form_manager);
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);
52 // Move to AUTO_SIGNIN_STATE. |local_forms| can't be empty.
53 void OnAutoSignin(ScopedVector<autofill::PasswordForm> local_forms);
55 // Move to CONFIRMATION_STATE.
56 void OnAutomaticPasswordSave(
57 scoped_ptr<password_manager::PasswordFormManager> form_manager);
59 // Move to MANAGE_STATE or INACTIVE_STATE for PSL matched passwords.
60 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map);
62 // Move to BLACKLIST_STATE.
63 void OnBlacklistBlockedAutofill(
64 const autofill::PasswordFormMap& password_form_map);
66 // Move to INACTIVE_STATE.
67 void OnInactive();
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);
74 // Updates the internal state applying |changes|.
75 void ProcessLoginsChanged(
76 const password_manager::PasswordStoreChangeList& changes);
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();
83 const CredentialsCallback& credentials_callback() {
84 return credentials_callback_;
86 void set_credentials_callback(const CredentialsCallback& callback) {
87 credentials_callback_ = callback;
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();
95 // Current federated forms.
96 const std::vector<const autofill::PasswordForm*>&
97 federated_credentials_forms() const {
98 return federated_credentials_forms_.get();
101 private:
102 // Removes all the PasswordForms stored in this object.
103 void ClearData();
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);
112 void SetState(password_manager::ui::State state);
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_;
118 // Contains the password that was submitted.
119 scoped_ptr<password_manager::PasswordFormManager> form_manager_;
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_;
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_;
132 // Federated credentials for the CREDENTIAL_REQUEST_STATE.
133 ScopedVector<const autofill::PasswordForm> federated_credentials_forms_;
135 // A callback to be invoked when user selects a credential.
136 CredentialsCallback credentials_callback_;
138 // The current state of the password manager UI.
139 password_manager::ui::State state_;
141 // The client used for logging.
142 password_manager::PasswordManagerClient* client_;
144 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsState);
147 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_