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 "chrome/browser/password_manager/password_store.h"
14 #include "chrome/browser/password_manager/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() 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_
;
84 CancelableRequestProvider::Handle pending_login_query_
;
87 // A short class to mediate requests to the password store for passwordlist.
88 class PasswordListPopulater
: public ListPopulater
{
90 explicit PasswordListPopulater(PasswordManagerPresenter
* page
);
92 // Send a query to the password store to populate a password list.
93 virtual void Populate() OVERRIDE
;
95 // Send the password store's reply back to the handler.
96 virtual void OnPasswordStoreRequestDone(
97 CancelableRequestProvider::Handle handle
,
98 const std::vector
<autofill::PasswordForm
*>& result
) OVERRIDE
;
99 virtual void OnGetPasswordStoreResults(
100 const std::vector
<autofill::PasswordForm
*>& results
) OVERRIDE
;
103 // A short class to mediate requests to the password store for exceptions.
104 class PasswordExceptionListPopulater
: public ListPopulater
{
106 explicit PasswordExceptionListPopulater(PasswordManagerPresenter
* page
);
108 // Send a query to the password store to populate a passwordException list.
109 virtual void Populate() OVERRIDE
;
111 // Send the password store's reply back to the handler.
112 virtual void OnPasswordStoreRequestDone(
113 CancelableRequestProvider::Handle handle
,
114 const std::vector
<autofill::PasswordForm
*>& result
) OVERRIDE
;
115 virtual void OnGetPasswordStoreResults(
116 const std::vector
<autofill::PasswordForm
*>& results
) OVERRIDE
;
119 // Password store consumer for populating the password list and exceptions.
120 PasswordListPopulater populater_
;
121 PasswordExceptionListPopulater exception_populater_
;
123 ScopedVector
<autofill::PasswordForm
> password_list_
;
124 ScopedVector
<autofill::PasswordForm
> password_exception_list_
;
126 // Whether to show stored passwords or not.
127 BooleanPrefMember show_passwords_
;
129 // Indicates whether or not the password manager should require the user to
130 // reauthenticate before revealing plaintext passwords.
131 bool require_reauthentication_
;
133 // The last time the user was successfully authenticated.
134 // Used to determine whether or not to reveal plaintext passwords.
135 base::TimeTicks last_authentication_time_
;
137 // UI view that owns this presenter.
138 PasswordUIView
* password_view_
;
140 DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenter
);
143 #endif // CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_