Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/browser/password_manager/password_store.h

Issue 8680040: Group forms-related files in webkit/glue in a forms/ subdirectory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + another build fix Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_PASSWORD_MANAGER_PASSWORD_STORE_H_ 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/callback_old.h" 12 #include "base/callback_old.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "content/browser/cancelable_request.h" 17 #include "content/browser/cancelable_request.h"
18 18
19 class PasswordStore; 19 class PasswordStore;
20 class PasswordStoreConsumer; 20 class PasswordStoreConsumer;
21 class Task; 21 class Task;
22 22
23 namespace browser_sync { 23 namespace browser_sync {
24 class PasswordDataTypeController; 24 class PasswordDataTypeController;
25 class PasswordModelAssociator; 25 class PasswordModelAssociator;
26 class PasswordModelWorker; 26 class PasswordModelWorker;
27 }; 27 }
28 28
29 namespace webkit_glue { 29 namespace webkit {
30 namespace forms {
30 struct PasswordForm; 31 struct PasswordForm;
31 }; 32 }
33 }
32 34
33 namespace passwords_helper { 35 namespace passwords_helper {
34 void AddLogin(PasswordStore* store, const webkit_glue::PasswordForm& form); 36 void AddLogin(PasswordStore* store, const webkit::forms::PasswordForm& form);
35 void RemoveLogin(PasswordStore* store, const webkit_glue::PasswordForm& form); 37 void RemoveLogin(PasswordStore* store, const webkit::forms::PasswordForm& form);
36 void UpdateLogin(PasswordStore* store, const webkit_glue::PasswordForm& form); 38 void UpdateLogin(PasswordStore* store, const webkit::forms::PasswordForm& form);
37 }; 39 }
38 40
39 // Interface for storing form passwords in a platform-specific secure way. 41 // Interface for storing form passwords in a platform-specific secure way.
40 // The login request/manipulation API is not threadsafe and must be used 42 // The login request/manipulation API is not threadsafe and must be used
41 // from the UI thread. 43 // from the UI thread.
42 class PasswordStore 44 class PasswordStore
43 : public base::RefCountedThreadSafe<PasswordStore>, 45 : public base::RefCountedThreadSafe<PasswordStore>,
44 public CancelableRequestProvider { 46 public CancelableRequestProvider {
45 public: 47 public:
46 typedef Callback2<Handle, 48 typedef Callback2<Handle,
47 const std::vector<webkit_glue::PasswordForm*>&>::Type 49 const std::vector<webkit::forms::PasswordForm*>&>::Type
48 GetLoginsCallback; 50 GetLoginsCallback;
49 51
50 // PasswordForm vector elements are meant to be owned by the 52 // PasswordForm vector elements are meant to be owned by the
51 // PasswordStoreConsumer. However, if the request is canceled after the 53 // PasswordStoreConsumer. However, if the request is canceled after the
52 // allocation, then the request must take care of the deletion. 54 // allocation, then the request must take care of the deletion.
53 // TODO(scr) If we can convert vector<PasswordForm*> to 55 // TODO(scr) If we can convert vector<PasswordForm*> to
54 // ScopedVector<PasswordForm>, then we can move the following class to merely 56 // ScopedVector<PasswordForm>, then we can move the following class to merely
55 // a typedef. At the moment, a subclass of CancelableRequest1 is required to 57 // a typedef. At the moment, a subclass of CancelableRequest1 is required to
56 // provide a destructor, which cleans up after canceled requests by deleting 58 // provide a destructor, which cleans up after canceled requests by deleting
57 // vector elements. 59 // vector elements.
58 class GetLoginsRequest : public CancelableRequest1< 60 class GetLoginsRequest : public CancelableRequest1<
59 GetLoginsCallback, std::vector<webkit_glue::PasswordForm*> > { 61 GetLoginsCallback, std::vector<webkit::forms::PasswordForm*> > {
60 public: 62 public:
61 explicit GetLoginsRequest(GetLoginsCallback* callback); 63 explicit GetLoginsRequest(GetLoginsCallback* callback);
62 virtual ~GetLoginsRequest(); 64 virtual ~GetLoginsRequest();
63 65
64 private: 66 private:
65 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest); 67 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest);
66 }; 68 };
67 69
68 // An interface used to notify clients (observers) of this object that data in 70 // An interface used to notify clients (observers) of this object that data in
69 // the password store has changed. Register the observer via 71 // the password store has changed. Register the observer via
70 // PasswordStore::SetObserver. 72 // PasswordStore::SetObserver.
71 class Observer { 73 class Observer {
72 public: 74 public:
73 // Notifies the observer that password data changed in some way. 75 // Notifies the observer that password data changed in some way.
74 virtual void OnLoginsChanged() = 0; 76 virtual void OnLoginsChanged() = 0;
75 77
76 protected: 78 protected:
77 virtual ~Observer() {} 79 virtual ~Observer() {}
78 }; 80 };
79 81
80 PasswordStore(); 82 PasswordStore();
81 83
82 // Reimplement this to add custom initialization. Always call this too. 84 // Reimplement this to add custom initialization. Always call this too.
83 virtual bool Init(); 85 virtual bool Init();
84 86
85 // Invoked from the profiles destructor to shutdown the PasswordStore. 87 // Invoked from the profiles destructor to shutdown the PasswordStore.
86 virtual void Shutdown(); 88 virtual void Shutdown();
87 89
88 // Adds the given PasswordForm to the secure password store asynchronously. 90 // Adds the given PasswordForm to the secure password store asynchronously.
89 virtual void AddLogin(const webkit_glue::PasswordForm& form); 91 virtual void AddLogin(const webkit::forms::PasswordForm& form);
90 92
91 // Updates the matching PasswordForm in the secure password store (async). 93 // Updates the matching PasswordForm in the secure password store (async).
92 void UpdateLogin(const webkit_glue::PasswordForm& form); 94 void UpdateLogin(const webkit::forms::PasswordForm& form);
93 95
94 // Removes the matching PasswordForm from the secure password store (async). 96 // Removes the matching PasswordForm from the secure password store (async).
95 void RemoveLogin(const webkit_glue::PasswordForm& form); 97 void RemoveLogin(const webkit::forms::PasswordForm& form);
96 98
97 // Removes all logins created in the given date range. 99 // Removes all logins created in the given date range.
98 void RemoveLoginsCreatedBetween(const base::Time& delete_begin, 100 void RemoveLoginsCreatedBetween(const base::Time& delete_begin,
99 const base::Time& delete_end); 101 const base::Time& delete_end);
100 102
101 // Searches for a matching PasswordForm and returns a handle so the async 103 // Searches for a matching PasswordForm and returns a handle so the async
102 // request can be tracked. Implement the PasswordStoreConsumer interface to be 104 // request can be tracked. Implement the PasswordStoreConsumer interface to be
103 // notified on completion. 105 // notified on completion.
104 virtual Handle GetLogins(const webkit_glue::PasswordForm& form, 106 virtual Handle GetLogins(const webkit::forms::PasswordForm& form,
105 PasswordStoreConsumer* consumer); 107 PasswordStoreConsumer* consumer);
106 108
107 // Gets the complete list of PasswordForms that are not blacklist entries--and 109 // Gets the complete list of PasswordForms that are not blacklist entries--and
108 // are thus auto-fillable--and returns a handle so the async request can be 110 // are thus auto-fillable--and returns a handle so the async request can be
109 // tracked. Implement the PasswordStoreConsumer interface to be notified on 111 // tracked. Implement the PasswordStoreConsumer interface to be notified on
110 // completion. 112 // completion.
111 Handle GetAutofillableLogins(PasswordStoreConsumer* consumer); 113 Handle GetAutofillableLogins(PasswordStoreConsumer* consumer);
112 114
113 // Gets the complete list of PasswordForms that are blacklist entries, and 115 // Gets the complete list of PasswordForms that are blacklist entries, and
114 // returns a handle so the async request can be tracked. Implement the 116 // returns a handle so the async request can be tracked. Implement the
115 // PasswordStoreConsumer interface to be notified on completion. 117 // PasswordStoreConsumer interface to be notified on completion.
116 Handle GetBlacklistLogins(PasswordStoreConsumer* consumer); 118 Handle GetBlacklistLogins(PasswordStoreConsumer* consumer);
117 119
118 // Reports usage metrics for the database. 120 // Reports usage metrics for the database.
119 void ReportMetrics(); 121 void ReportMetrics();
120 122
121 // Adds an observer to be notified when the password store data changes. 123 // Adds an observer to be notified when the password store data changes.
122 void AddObserver(Observer* observer); 124 void AddObserver(Observer* observer);
123 125
124 // Removes |observer| from the observer list. 126 // Removes |observer| from the observer list.
125 void RemoveObserver(Observer* observer); 127 void RemoveObserver(Observer* observer);
126 128
127 protected: 129 protected:
128 friend class base::RefCountedThreadSafe<PasswordStore>; 130 friend class base::RefCountedThreadSafe<PasswordStore>;
129 friend class browser_sync::PasswordDataTypeController; 131 friend class browser_sync::PasswordDataTypeController;
130 friend class browser_sync::PasswordModelAssociator; 132 friend class browser_sync::PasswordModelAssociator;
131 friend class browser_sync::PasswordModelWorker; 133 friend class browser_sync::PasswordModelWorker;
132 friend void passwords_helper::AddLogin(PasswordStore*, 134 friend void passwords_helper::AddLogin(PasswordStore*,
133 const webkit_glue::PasswordForm&); 135 const webkit::forms::PasswordForm&);
134 friend void passwords_helper::RemoveLogin(PasswordStore*, 136 friend void passwords_helper::RemoveLogin(PasswordStore*,
135 const webkit_glue::PasswordForm&); 137 const webkit::forms::PasswordForm&);
136 friend void passwords_helper::UpdateLogin(PasswordStore*, 138 friend void passwords_helper::UpdateLogin(PasswordStore*,
137 const webkit_glue::PasswordForm&); 139 const webkit::forms::PasswordForm&);
138 140
139 virtual ~PasswordStore(); 141 virtual ~PasswordStore();
140 142
141 // Provided to allow subclasses to extend GetLoginsRequest if additional info 143 // Provided to allow subclasses to extend GetLoginsRequest if additional info
142 // is needed between a call and its Impl. 144 // is needed between a call and its Impl.
143 virtual GetLoginsRequest* NewGetLoginsRequest(GetLoginsCallback* callback); 145 virtual GetLoginsRequest* NewGetLoginsRequest(GetLoginsCallback* callback);
144 146
145 // Schedule the given |task| to be run in the PasswordStore's own thread. 147 // Schedule the given |task| to be run in the PasswordStore's own thread.
146 // TODO(mdm): Remove the Task* version of this when it is no longer needed. 148 // TODO(mdm): Remove the Task* version of this when it is no longer needed.
147 virtual void ScheduleTask(Task* task); 149 virtual void ScheduleTask(Task* task);
148 virtual void ScheduleTask(const base::Closure& task); 150 virtual void ScheduleTask(const base::Closure& task);
149 151
150 // These will be run in PasswordStore's own thread. 152 // These will be run in PasswordStore's own thread.
151 // Synchronous implementation that reports usage metrics. 153 // Synchronous implementation that reports usage metrics.
152 virtual void ReportMetricsImpl() = 0; 154 virtual void ReportMetricsImpl() = 0;
153 // Synchronous implementation to add the given login. 155 // Synchronous implementation to add the given login.
154 virtual void AddLoginImpl(const webkit_glue::PasswordForm& form) = 0; 156 virtual void AddLoginImpl(const webkit::forms::PasswordForm& form) = 0;
155 // Synchronous implementation to update the given login. 157 // Synchronous implementation to update the given login.
156 virtual void UpdateLoginImpl(const webkit_glue::PasswordForm& form) = 0; 158 virtual void UpdateLoginImpl(const webkit::forms::PasswordForm& form) = 0;
157 // Synchronous implementation to remove the given login. 159 // Synchronous implementation to remove the given login.
158 virtual void RemoveLoginImpl(const webkit_glue::PasswordForm& form) = 0; 160 virtual void RemoveLoginImpl(const webkit::forms::PasswordForm& form) = 0;
159 // Synchronous implementation to remove the given logins. 161 // Synchronous implementation to remove the given logins.
160 virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin, 162 virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin,
161 const base::Time& delete_end) = 0; 163 const base::Time& delete_end) = 0;
162 // Should find all PasswordForms with the same signon_realm. The results 164 // Should find all PasswordForms with the same signon_realm. The results
163 // will then be scored by the PasswordFormManager. Once they are found 165 // will then be scored by the PasswordFormManager. Once they are found
164 // (or not), the consumer should be notified. 166 // (or not), the consumer should be notified.
165 virtual void GetLoginsImpl(GetLoginsRequest* request, 167 virtual void GetLoginsImpl(GetLoginsRequest* request,
166 const webkit_glue::PasswordForm& form) = 0; 168 const webkit::forms::PasswordForm& form) = 0;
167 // Finds all non-blacklist PasswordForms, and notifies the consumer. 169 // Finds all non-blacklist PasswordForms, and notifies the consumer.
168 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) = 0; 170 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) = 0;
169 // Finds all blacklist PasswordForms, and notifies the consumer. 171 // Finds all blacklist PasswordForms, and notifies the consumer.
170 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0; 172 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0;
171 173
172 // Finds all non-blacklist PasswordForms, and fills the vector. 174 // Finds all non-blacklist PasswordForms, and fills the vector.
173 virtual bool FillAutofillableLogins( 175 virtual bool FillAutofillableLogins(
174 std::vector<webkit_glue::PasswordForm*>* forms) = 0; 176 std::vector<webkit::forms::PasswordForm*>* forms) = 0;
175 // Finds all blacklist PasswordForms, and fills the vector. 177 // Finds all blacklist PasswordForms, and fills the vector.
176 virtual bool FillBlacklistLogins( 178 virtual bool FillBlacklistLogins(
177 std::vector<webkit_glue::PasswordForm*>* forms) = 0; 179 std::vector<webkit::forms::PasswordForm*>* forms) = 0;
178 180
179 // Dispatches the result to the PasswordStoreConsumer on the original caller's 181 // Dispatches the result to the PasswordStoreConsumer on the original caller's
180 // thread so the callback can be executed there. This should be the UI 182 // thread so the callback can be executed there. This should be the UI
181 // thread. 183 // thread.
182 virtual void ForwardLoginsResult(GetLoginsRequest* request); 184 virtual void ForwardLoginsResult(GetLoginsRequest* request);
183 185
184 // Schedule the given |func| to be run in the PasswordStore's own thread with 186 // Schedule the given |func| to be run in the PasswordStore's own thread with
185 // responses delivered to |consumer| on the current thread. 187 // responses delivered to |consumer| on the current thread.
186 template<typename BackendFunc> 188 template<typename BackendFunc>
187 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer); 189 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer);
(...skipping 23 matching lines...) Expand all
211 // may have been changed. 213 // may have been changed.
212 void NotifyLoginsChanged(); 214 void NotifyLoginsChanged();
213 215
214 // The observers. 216 // The observers.
215 ObserverList<Observer> observers_; 217 ObserverList<Observer> observers_;
216 218
217 DISALLOW_COPY_AND_ASSIGN(PasswordStore); 219 DISALLOW_COPY_AND_ASSIGN(PasswordStore);
218 }; 220 };
219 221
220 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ 222 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_manager_unittest.cc ('k') | chrome/browser/password_manager/password_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698