Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / passwords / password_manager_presenter.h
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.
4
5 #ifndef CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_
6 #define CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_
7
8 #include <string>
9 #include <vector>
10
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"
15
16 namespace autofill {
17 struct PasswordForm;
18 }
19
20 class PasswordUIView;
21
22 class Profile;
23
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 {
28  public:
29   // |password_view| the UI view that owns this presenter, must not be NULL.
30   explicit PasswordManagerPresenter(PasswordUIView* password_view);
31   virtual ~PasswordManagerPresenter();
32
33   // PasswordStore::Observer implementation.
34   virtual void OnLoginsChanged(const PasswordStoreChangeList& changes) OVERRIDE;
35
36   // Repopulates the password and exception entries.
37   void UpdatePasswordLists();
38
39   void Initialize();
40
41   // Gets the password entry at |index|.
42   const autofill::PasswordForm& GetPassword(size_t index);
43
44   // Gets the password exception entry at |index|.
45   const autofill::PasswordForm& GetPasswordException(size_t index);
46
47   // Removes the saved password entry at |index|.
48   // |index| the entry index to be removed.
49   void RemoveSavedPassword(size_t index);
50
51   // Removes the saved password exception entry at |index|.
52   // |index| the entry index to be removed.
53   void RemovePasswordException(size_t index);
54
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);
58
59  private:
60   friend class PasswordManagerPresenterTest;
61
62   // Returns the password store associated with the currently active profile.
63   PasswordStore* GetPasswordStore();
64
65   // Returns true if the user needs to be authenticated before a plaintext
66   // password is revealed.
67   bool IsAuthenticationRequired();
68
69   // Sets the password and exception list of the UI view.
70   void SetPasswordList();
71   void SetPasswordExceptionList();
72
73   // A short class to mediate requests to the password store.
74   class ListPopulater : public PasswordStoreConsumer {
75    public:
76     explicit ListPopulater(PasswordManagerPresenter* page);
77     virtual ~ListPopulater();
78
79     // Send a query to the password store to populate a list.
80     virtual void Populate() = 0;
81
82    protected:
83     PasswordManagerPresenter* page_;
84   };
85
86   // A short class to mediate requests to the password store for passwordlist.
87   class PasswordListPopulater : public ListPopulater {
88    public:
89     explicit PasswordListPopulater(PasswordManagerPresenter* page);
90
91     // Send a query to the password store to populate a password list.
92     virtual void Populate() OVERRIDE;
93
94     // Send the password store's reply back to the handler.
95     virtual void OnGetPasswordStoreResults(
96         const std::vector<autofill::PasswordForm*>& results) OVERRIDE;
97   };
98
99   // A short class to mediate requests to the password store for exceptions.
100   class PasswordExceptionListPopulater : public ListPopulater {
101    public:
102     explicit PasswordExceptionListPopulater(PasswordManagerPresenter* page);
103
104     // Send a query to the password store to populate a passwordException list.
105     virtual void Populate() OVERRIDE;
106
107     // Send the password store's reply back to the handler.
108     virtual void OnGetPasswordStoreResults(
109         const std::vector<autofill::PasswordForm*>& results) OVERRIDE;
110   };
111
112   // Password store consumer for populating the password list and exceptions.
113   PasswordListPopulater populater_;
114   PasswordExceptionListPopulater exception_populater_;
115
116   ScopedVector<autofill::PasswordForm> password_list_;
117   ScopedVector<autofill::PasswordForm> password_exception_list_;
118
119   // Whether to show stored passwords or not.
120   BooleanPrefMember show_passwords_;
121
122   // Indicates whether or not the password manager should require the user to
123   // reauthenticate before revealing plaintext passwords.
124   bool require_reauthentication_;
125
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_;
129
130   // UI view that owns this presenter.
131   PasswordUIView* password_view_;
132
133   DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenter);
134 };
135
136 #endif  // CHROME_BROWSER_UI_PASSWORDS_PASSWORD_MANAGER_PRESENTER_H_