OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_ | 5 #ifndef CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_ |
6 #define CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_ | 6 #define CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "components/password_manager/core/browser/password_store.h" | 17 #include "components/password_manager/core/browser/password_store.h" |
18 #include "components/password_manager/core/browser/password_store_consumer.h" | 18 #include "components/password_manager/core/browser/password_store_consumer.h" |
19 #include "components/prefs/pref_member.h" | 19 #include "components/prefs/pref_member.h" |
| 20 #include "ui/shell_dialogs/select_file_dialog.h" |
20 | 21 |
21 namespace autofill { | 22 namespace autofill { |
22 struct PasswordForm; | 23 struct PasswordForm; |
23 } | 24 } |
24 | 25 |
25 // Multimap from sort key to password forms. | 26 // Multimap from sort key to password forms. |
26 using DuplicatesMap = | 27 using DuplicatesMap = |
27 std::multimap<std::string, scoped_ptr<autofill::PasswordForm>>; | 28 std::multimap<std::string, scoped_ptr<autofill::PasswordForm>>; |
28 | |
29 class PasswordUIView; | 29 class PasswordUIView; |
30 | 30 |
31 class Profile; | 31 class Profile; |
32 | 32 |
33 // Contains the common logic used by a PasswordUIView to | 33 // Contains the common logic used by a PasswordUIView to |
34 // interact with PasswordStore. It provides completion callbacks for | 34 // interact with PasswordStore. It provides completion callbacks for |
35 // PasswordStore operations and updates the view on PasswordStore changes. | 35 // PasswordStore operations and updates the view on PasswordStore changes. |
36 class PasswordManagerPresenter | 36 class PasswordManagerPresenter |
37 : public password_manager::PasswordStore::Observer { | 37 : public password_manager::PasswordStore::Observer { |
38 public: | 38 public: |
39 // |password_view| the UI view that owns this presenter, must not be NULL. | 39 // |password_view| the UI view that owns this presenter, must not be NULL. |
40 explicit PasswordManagerPresenter(PasswordUIView* password_view); | 40 explicit PasswordManagerPresenter(PasswordUIView* password_view); |
41 ~PasswordManagerPresenter() override; | 41 ~PasswordManagerPresenter() override; |
42 | 42 |
43 // PasswordStore::Observer implementation. | 43 // PasswordStore::Observer implementation. |
44 void OnLoginsChanged( | 44 void OnLoginsChanged( |
45 const password_manager::PasswordStoreChangeList& changes) override; | 45 const password_manager::PasswordStoreChangeList& changes) override; |
46 | 46 |
47 // Repopulates the password and exception entries. | 47 // Repopulates the password and exception entries. |
48 void UpdatePasswordLists(); | 48 void UpdatePasswordLists(); |
49 | 49 |
50 void Initialize(); | 50 void Initialize(); |
51 | 51 |
52 // Gets the password entry at |index|. | 52 // Gets the password entry at |index|. |
53 const autofill::PasswordForm* GetPassword(size_t index); | 53 const autofill::PasswordForm* GetPassword(size_t index); |
54 | 54 |
| 55 // Gets all password entries. |
| 56 std::vector<scoped_ptr<autofill::PasswordForm>> GetAllPasswords(); |
| 57 |
55 // Gets the password exception entry at |index|. | 58 // Gets the password exception entry at |index|. |
56 const autofill::PasswordForm* GetPasswordException(size_t index); | 59 const autofill::PasswordForm* GetPasswordException(size_t index); |
57 | 60 |
58 // Removes the saved password entry at |index|. | 61 // Removes the saved password entry at |index|. |
59 // |index| the entry index to be removed. | 62 // |index| the entry index to be removed. |
60 void RemoveSavedPassword(size_t index); | 63 void RemoveSavedPassword(size_t index); |
61 | 64 |
62 // Removes the saved password exception entry at |index|. | 65 // Removes the saved password exception entry at |index|. |
63 // |index| the entry index to be removed. | 66 // |index| the entry index to be removed. |
64 void RemovePasswordException(size_t index); | 67 void RemovePasswordException(size_t index); |
65 | 68 |
66 // Requests the plain text password for entry at |index| to be revealed. | 69 // Requests the plain text password for entry at |index| to be revealed. |
67 // |index| The index of the entry. | 70 // |index| The index of the entry. |
68 void RequestShowPassword(size_t index); | 71 void RequestShowPassword(size_t index); |
69 | 72 |
| 73 // Returns true if the user is authenticated. |
| 74 virtual bool IsUserAuthenticated(); |
| 75 |
70 private: | 76 private: |
71 friend class PasswordManagerPresenterTest; | 77 friend class PasswordManagerPresenterTest; |
72 | 78 |
73 // Returns the password store associated with the currently active profile. | 79 // Returns true if the user needs to be authenticated before a plaintext |
74 password_manager::PasswordStore* GetPasswordStore(); | 80 // password is revealed or exported. |
| 81 bool IsAuthenticationRequired(); |
75 | 82 |
76 // Sets the password and exception list of the UI view. | 83 // Sets the password and exception list of the UI view. |
77 void SetPasswordList(); | 84 void SetPasswordList(); |
78 void SetPasswordExceptionList(); | 85 void SetPasswordExceptionList(); |
79 | 86 |
80 // Sort entries of |list| based on sort key. The key is the concatenation of | 87 // Sort entries of |list| based on sort key. The key is the concatenation of |
81 // origin, entry type (non-Android credential, Android w/ affiliated web realm | 88 // origin, entry type (non-Android credential, Android w/ affiliated web realm |
82 // or Android w/o affiliated web realm). If |username_and_password_in_key|, | 89 // or Android w/o affiliated web realm). If |username_and_password_in_key|, |
83 // username and password are also included in sort key. If there are several | 90 // username and password are also included in sort key. If there are several |
84 // forms with the same key, all such forms but the first one are | 91 // forms with the same key, all such forms but the first one are |
85 // stored in |duplicates| instead of |list|. | 92 // stored in |duplicates| instead of |list|. |
86 void SortEntriesAndHideDuplicates( | 93 void SortEntriesAndHideDuplicates( |
87 std::vector<scoped_ptr<autofill::PasswordForm>>* list, | 94 std::vector<scoped_ptr<autofill::PasswordForm>>* list, |
88 DuplicatesMap* duplicates, | 95 DuplicatesMap* duplicates, |
89 bool username_and_password_in_key); | 96 bool username_and_password_in_key); |
90 | 97 |
| 98 // Returns the password store associated with the currently active profile. |
| 99 password_manager::PasswordStore* GetPasswordStore(); |
| 100 |
91 // A short class to mediate requests to the password store. | 101 // A short class to mediate requests to the password store. |
92 class ListPopulater : public password_manager::PasswordStoreConsumer { | 102 class ListPopulater : public password_manager::PasswordStoreConsumer { |
93 public: | 103 public: |
94 explicit ListPopulater(PasswordManagerPresenter* page); | 104 explicit ListPopulater(PasswordManagerPresenter* page); |
95 ~ListPopulater() override; | 105 ~ListPopulater() override; |
96 | 106 |
97 // Send a query to the password store to populate a list. | 107 // Send a query to the password store to populate a list. |
98 virtual void Populate() = 0; | 108 virtual void Populate() = 0; |
99 | 109 |
100 protected: | 110 protected: |
(...skipping 28 matching lines...) Expand all Loading... |
129 | 139 |
130 // Password store consumer for populating the password list and exceptions. | 140 // Password store consumer for populating the password list and exceptions. |
131 PasswordListPopulater populater_; | 141 PasswordListPopulater populater_; |
132 PasswordExceptionListPopulater exception_populater_; | 142 PasswordExceptionListPopulater exception_populater_; |
133 | 143 |
134 std::vector<scoped_ptr<autofill::PasswordForm>> password_list_; | 144 std::vector<scoped_ptr<autofill::PasswordForm>> password_list_; |
135 std::vector<scoped_ptr<autofill::PasswordForm>> password_exception_list_; | 145 std::vector<scoped_ptr<autofill::PasswordForm>> password_exception_list_; |
136 DuplicatesMap password_duplicates_; | 146 DuplicatesMap password_duplicates_; |
137 DuplicatesMap password_exception_duplicates_; | 147 DuplicatesMap password_exception_duplicates_; |
138 | 148 |
| 149 // Whether to show stored passwords or not. |
| 150 BooleanPrefMember show_passwords_; |
| 151 |
139 // The last time the user was successfully authenticated. | 152 // The last time the user was successfully authenticated. |
140 // Used to determine whether or not to reveal plaintext passwords. | 153 // Used to determine whether or not to reveal plaintext passwords. |
141 base::TimeTicks last_authentication_time_; | 154 base::TimeTicks last_authentication_time_; |
142 | 155 |
143 // UI view that owns this presenter. | 156 // UI view that owns this presenter. |
144 PasswordUIView* password_view_; | 157 PasswordUIView* password_view_; |
145 | 158 |
146 DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenter); | 159 DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenter); |
147 }; | 160 }; |
148 | 161 |
149 #endif // CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_ | 162 #endif // CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_ |
OLD | NEW |