BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / passwords / password_manager_presenter.h
blobfcb3b696d131c5ea1798f43500d0453500c3b71e
1 // Copyright 2013 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_PASSWORD_MANAGER_PRESENTER_H_
6 #define CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_vector.h"
12 #include "base/prefs/pref_member.h"
13 #include "components/password_manager/core/browser/password_store.h"
14 #include "components/password_manager/core/browser/password_store_consumer.h"
16 namespace autofill {
17 struct PasswordForm;
20 class PasswordUIView;
22 class Profile;
24 // Contains the common logic used by a PasswordUIView to
25 // interact with PasswordStore. It provides completion callbacks for
26 // PasswordStore operations and updates the view on PasswordStore changes.
27 class PasswordManagerPresenter
28 : public password_manager::PasswordStore::Observer {
29 public:
30 // |password_view| the UI view that owns this presenter, must not be NULL.
31 explicit PasswordManagerPresenter(PasswordUIView* password_view);
32 ~PasswordManagerPresenter() override;
34 // PasswordStore::Observer implementation.
35 void OnLoginsChanged(
36 const password_manager::PasswordStoreChangeList& changes) override;
38 // Repopulates the password and exception entries.
39 void UpdatePasswordLists();
41 void Initialize();
43 // Gets the password entry at |index|.
44 const autofill::PasswordForm* GetPassword(size_t index);
46 // Gets the password exception entry at |index|.
47 const autofill::PasswordForm* GetPasswordException(size_t index);
49 // Removes the saved password entry at |index|.
50 // |index| the entry index to be removed.
51 void RemoveSavedPassword(size_t index);
53 // Removes the saved password exception entry at |index|.
54 // |index| the entry index to be removed.
55 void RemovePasswordException(size_t index);
57 // Requests the plain text password for entry at |index| to be revealed.
58 // |index| The index of the entry.
59 void RequestShowPassword(size_t index);
61 private:
62 friend class PasswordManagerPresenterTest;
64 // Returns the password store associated with the currently active profile.
65 password_manager::PasswordStore* GetPasswordStore();
67 // Sets the password and exception list of the UI view.
68 void SetPasswordList();
69 void SetPasswordExceptionList();
71 // A short class to mediate requests to the password store.
72 class ListPopulater : public password_manager::PasswordStoreConsumer {
73 public:
74 explicit ListPopulater(PasswordManagerPresenter* page);
75 ~ListPopulater() override;
77 // Send a query to the password store to populate a list.
78 virtual void Populate() = 0;
80 protected:
81 PasswordManagerPresenter* page_;
84 // A short class to mediate requests to the password store for passwordlist.
85 class PasswordListPopulater : public ListPopulater {
86 public:
87 explicit PasswordListPopulater(PasswordManagerPresenter* page);
89 // Send a query to the password store to populate a password list.
90 void Populate() override;
92 // Send the password store's reply back to the handler.
93 void OnGetPasswordStoreResults(
94 ScopedVector<autofill::PasswordForm> results) override;
97 // A short class to mediate requests to the password store for exceptions.
98 class PasswordExceptionListPopulater : public ListPopulater {
99 public:
100 explicit PasswordExceptionListPopulater(PasswordManagerPresenter* page);
102 // Send a query to the password store to populate a passwordException list.
103 void Populate() override;
105 // Send the password store's reply back to the handler.
106 void OnGetPasswordStoreResults(
107 ScopedVector<autofill::PasswordForm> results) override;
110 // Password store consumer for populating the password list and exceptions.
111 PasswordListPopulater populater_;
112 PasswordExceptionListPopulater exception_populater_;
114 ScopedVector<autofill::PasswordForm> password_list_;
115 ScopedVector<autofill::PasswordForm> password_exception_list_;
117 // Whether to show stored passwords or not.
118 BooleanPrefMember show_passwords_;
120 // Indicates whether or not the password manager should require the user to
121 // reauthenticate before revealing plaintext passwords.
122 const bool require_reauthentication_;
124 // The last time the user was successfully authenticated.
125 // Used to determine whether or not to reveal plaintext passwords.
126 base::TimeTicks last_authentication_time_;
128 // UI view that owns this presenter.
129 PasswordUIView* password_view_;
131 // User pref for storing accept languages.
132 std::string languages_;
134 DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenter);
137 #endif // CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_