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_
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"
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 : public PasswordStore::Observer {
29 // |password_view| the UI view that owns this presenter, must not be NULL.
30 explicit PasswordManagerPresenter(PasswordUIView* password_view);
31 virtual ~PasswordManagerPresenter();
33 // PasswordStore::Observer implementation.
34 virtual void OnLoginsChanged(const PasswordStoreChangeList& changes) OVERRIDE;
36 // Repopulates the password and exception entries.
37 void UpdatePasswordLists();
41 // Gets the password entry at |index|.
42 const autofill::PasswordForm& GetPassword(size_t index);
44 // Gets the password exception entry at |index|.
45 const autofill::PasswordForm& GetPasswordException(size_t index);
47 // Removes the saved password entry at |index|.
48 // |index| the entry index to be removed.
49 void RemoveSavedPassword(size_t index);
51 // Removes the saved password exception entry at |index|.
52 // |index| the entry index to be removed.
53 void RemovePasswordException(size_t index);
55 // Requests the plain text password for entry at |index| to be revealed.
56 // |index| The index of the entry.
57 void RequestShowPassword(size_t index);
60 friend class PasswordManagerPresenterTest;
62 // Returns the password store associated with the currently active profile.
63 PasswordStore* GetPasswordStore();
65 // Returns true if the user needs to be authenticated before a plaintext
66 // password is revealed.
67 bool IsAuthenticationRequired();
69 // Sets the password and exception list of the UI view.
70 void SetPasswordList();
71 void SetPasswordExceptionList();
73 // A short class to mediate requests to the password store.
74 class ListPopulater : public PasswordStoreConsumer {
76 explicit ListPopulater(PasswordManagerPresenter* page);
77 virtual ~ListPopulater();
79 // Send a query to the password store to populate a list.
80 virtual void Populate() = 0;
83 PasswordManagerPresenter* page_;
86 // A short class to mediate requests to the password store for passwordlist.
87 class PasswordListPopulater : public ListPopulater {
89 explicit PasswordListPopulater(PasswordManagerPresenter* page);
91 // Send a query to the password store to populate a password list.
92 virtual void Populate() OVERRIDE;
94 // Send the password store's reply back to the handler.
95 virtual void OnGetPasswordStoreResults(
96 const std::vector<autofill::PasswordForm*>& results) OVERRIDE;
99 // A short class to mediate requests to the password store for exceptions.
100 class PasswordExceptionListPopulater : public ListPopulater {
102 explicit PasswordExceptionListPopulater(PasswordManagerPresenter* page);
104 // Send a query to the password store to populate a passwordException list.
105 virtual void Populate() OVERRIDE;
107 // Send the password store's reply back to the handler.
108 virtual void OnGetPasswordStoreResults(
109 const std::vector<autofill::PasswordForm*>& results) OVERRIDE;
112 // Password store consumer for populating the password list and exceptions.
113 PasswordListPopulater populater_;
114 PasswordExceptionListPopulater exception_populater_;
116 ScopedVector<autofill::PasswordForm> password_list_;
117 ScopedVector<autofill::PasswordForm> password_exception_list_;
119 // Whether to show stored passwords or not.
120 BooleanPrefMember show_passwords_;
122 // Indicates whether or not the password manager should require the user to
123 // reauthenticate before revealing plaintext passwords.
124 bool require_reauthentication_;
126 // The last time the user was successfully authenticated.
127 // Used to determine whether or not to reveal plaintext passwords.
128 base::TimeTicks last_authentication_time_;
130 // UI view that owns this presenter.
131 PasswordUIView* password_view_;
133 DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenter);
136 #endif // CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_