Support SizeClassIdiom on iOS7.
[chromium-blink-merge.git] / chrome / browser / ui / passwords / password_manager_presenter.h
blob2997830ea64f9dfcbe2ecec860f7288019fd8d2d
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 // Returns true if the user needs to be authenticated before a plaintext
68 // password is revealed.
69 bool IsAuthenticationRequired();
71 // Sets the password and exception list of the UI view.
72 void SetPasswordList();
73 void SetPasswordExceptionList();
75 // A short class to mediate requests to the password store.
76 class ListPopulater : public password_manager::PasswordStoreConsumer {
77 public:
78 explicit ListPopulater(PasswordManagerPresenter* page);
79 ~ListPopulater() override;
81 // Send a query to the password store to populate a list.
82 virtual void Populate() = 0;
84 protected:
85 PasswordManagerPresenter* page_;
88 // A short class to mediate requests to the password store for passwordlist.
89 class PasswordListPopulater : public ListPopulater {
90 public:
91 explicit PasswordListPopulater(PasswordManagerPresenter* page);
93 // Send a query to the password store to populate a password list.
94 void Populate() override;
96 // Send the password store's reply back to the handler.
97 void OnGetPasswordStoreResults(
98 ScopedVector<autofill::PasswordForm> results) override;
101 // A short class to mediate requests to the password store for exceptions.
102 class PasswordExceptionListPopulater : public ListPopulater {
103 public:
104 explicit PasswordExceptionListPopulater(PasswordManagerPresenter* page);
106 // Send a query to the password store to populate a passwordException list.
107 void Populate() override;
109 // Send the password store's reply back to the handler.
110 void OnGetPasswordStoreResults(
111 ScopedVector<autofill::PasswordForm> results) override;
114 // Password store consumer for populating the password list and exceptions.
115 PasswordListPopulater populater_;
116 PasswordExceptionListPopulater exception_populater_;
118 ScopedVector<autofill::PasswordForm> password_list_;
119 ScopedVector<autofill::PasswordForm> password_exception_list_;
121 // Whether to show stored passwords or not.
122 BooleanPrefMember show_passwords_;
124 // Indicates whether or not the password manager should require the user to
125 // reauthenticate before revealing plaintext passwords.
126 bool require_reauthentication_;
128 // The last time the user was successfully authenticated.
129 // Used to determine whether or not to reveal plaintext passwords.
130 base::TimeTicks last_authentication_time_;
132 // UI view that owns this presenter.
133 PasswordUIView* password_view_;
135 // User pref for storing accept languages.
136 std::string languages_;
138 DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenter);
141 #endif // CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_