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

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_state.h

Issue 993513006: Introduce ManagePasswordsState class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
(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 SetClient(password_manager::PasswordManagerClient* client) {
vabr (Chromium) 2015/03/10 10:39:57 nit: The style guide seems to indicate set_client
vasilii 2015/03/10 11:34:48 Done.
36 client_ = client;
37 }
38
39 // The methods below reset the object.
vabr (Chromium) 2015/03/10 10:39:57 At this point of reading through the class definit
vasilii 2015/03/10 11:34:48 Done.
40
41 // Move to PENDING_PASSWORD_STATE.
42 void OnPendingPassword(
43 scoped_ptr<password_manager::PasswordFormManager> form_manager);
44
45 // Move to CREDENTIAL_REQUEST_STATE.
46 void OnRequestCredentials(
47 ScopedVector<autofill::PasswordForm> local_credentials,
48 ScopedVector<autofill::PasswordForm> federated_credentials,
49 const GURL& origin);
50
51 // Move to AUTO_SIGNIN_STATE. |local_forms| can't be empty.
52 void OnAutoSignin(ScopedVector<autofill::PasswordForm> local_forms);
53
54 // Move to CONFIRMATION_STATE.
55 void OnAutomaticPasswordSave(
56 scoped_ptr<password_manager::PasswordFormManager> form_manager);
57
58 // Move to MANAGE_STATE or INACTIVE_STATE for PSL matched passwords.
59 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map);
60
61 // Move to BLACKLIST_STATE.
62 void OnBlacklistBlockedAutofill(
63 const autofill::PasswordFormMap& password_form_map);
64
65 // Move to INACTIVE_STATE.
66 void OnInactive();
67
68 // Moves the object to |state| without resetting the internal data. Allowed:
69 // * -> BLACKLIST_STATE
70 // CONFIRMATION_STATE -> MANAGE_STATE
71 // BLACKLIST_STATE -> MANAGE_STATE
72 // PENDING_PASSWORD_STATE -> MANAGE_STATE
73 // CREDENTIAL_REQUEST_STATE -> MANAGE_STATE
74 void TransitionToState(password_manager::ui::State state);
75
76 // Updates the internal state applying |changes|.
77 void ProcessLoginsChanged(
78 const password_manager::PasswordStoreChangeList& changes);
79
80 password_manager::ui::State state() const { return state_; }
81 const GURL& origin() const { return origin_; }
82 password_manager::PasswordFormManager* form_manager() const {
83 return form_manager_.get();
84 }
85 const CredentialsCallback& credentials_callback() {
86 return credentials_callback_;
87 }
88 void set_credentials_callback(const CredentialsCallback& callback) {
89 credentials_callback_ = callback;
90 }
91
92 // Current local forms. ManagePasswordsState is responsible for the forms.
93 const std::vector<const autofill::PasswordForm*>& GetCurrentForms() const {
94 return form_manager_ ? current_forms_weak_ : local_credentials_forms_.get();
95 }
96
97 // Current federated forms.
98 const std::vector<const autofill::PasswordForm*>&
99 federated_credentials_forms() const {
100 return federated_credentials_forms_.get();
101 }
102
103 private:
104 // Removes all the PasswordForms stored in this object.
105 void ClearData();
106
107 // Add |form| to the internal state.
108 void AddForm(const autofill::PasswordForm& form);
109 // Updates |form| in the internal state.
110 void UpdateForm(const autofill::PasswordForm& form);
111 // Removes |form| from the internal state.
112 void DeleteForm(const autofill::PasswordForm& form);
113
114 void SetState(password_manager::ui::State state);
115
116 // The origin of the current page. It's used to determine which PasswordStore
117 // changes are applicable to the internal state.
118 GURL origin_;
119
120 // Contains the password that was submitted.
121 scoped_ptr<password_manager::PasswordFormManager> form_manager_;
122
123 // Weak references to the passwords for the current status. The hard pointers
124 // are scattered between |form_manager_| and |local_credentials_forms_|. If
125 // |form_manager_| is nullptr then all the forms are stored in
126 // |local_credentials_forms_|. |current_forms_weak_| remains empty.
127 std::vector<const autofill::PasswordForm*> current_forms_weak_;
128
129 // If |form_manager_| is nullptr then |local_credentials_forms_| contains all
130 // the current forms. Otherwise, it's a container for the new forms coming
131 // from the PasswordStore.
132 ScopedVector<const autofill::PasswordForm> local_credentials_forms_;
133
134 // Federated credentials for the CREDENTIAL_REQUEST_STATE.
135 ScopedVector<const autofill::PasswordForm> federated_credentials_forms_;
136
137 // A callback to be invoked when user selects a credential.
138 CredentialsCallback credentials_callback_;
139
140 // The current state of the password manager UI.
141 password_manager::ui::State state_;
142
143 // The client used for logging.
144 password_manager::PasswordManagerClient* client_;
145
146 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsState);
147 };
148
149 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698