Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <set> | |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 11 #include "base/callback.h" | |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "content/browser/cancelable_request.h" | |
| 15 #include "webkit/glue/password_form.h" | 16 #include "webkit/glue/password_form.h" |
| 16 | 17 |
| 17 class Profile; | |
| 18 class Task; | 18 class Task; |
| 19 | 19 |
| 20 namespace browser_sync { | 20 namespace browser_sync { |
| 21 class PasswordDataTypeController; | 21 class PasswordDataTypeController; |
| 22 class PasswordModelAssociator; | 22 class PasswordModelAssociator; |
| 23 class PasswordModelWorker; | 23 class PasswordModelWorker; |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 class PasswordStoreConsumer { | 26 class PasswordStoreConsumer { |
| 27 public: | 27 public: |
| 28 virtual ~PasswordStoreConsumer() {} | 28 virtual ~PasswordStoreConsumer() {} |
| 29 // Call this when the request is finished. If there are no results, call it | 29 // Call this when the request is finished. If there are no results, call it |
| 30 // anyway with an empty vector. | 30 // anyway with an empty vector. |
| 31 virtual void OnPasswordStoreRequestDone( | 31 virtual void OnPasswordStoreRequestDone( |
| 32 int handle, const std::vector<webkit_glue::PasswordForm*>& result) = 0; | 32 CancelableRequestProvider::Handle handle, |
| 33 const std::vector<webkit_glue::PasswordForm*>& result) = 0; | |
| 34 | |
| 35 CancelableRequestConsumerBase* cancelable_consumer() { | |
|
stuartmorgan
2011/03/16 23:25:20
Comment?
Sheridan Rawlins
2011/03/20 08:13:11
Done.
| |
| 36 return &cancelable_consumer_; | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 CancelableRequestConsumer cancelable_consumer_; | |
| 33 }; | 41 }; |
| 34 | 42 |
| 35 // Interface for storing form passwords in a platform-specific secure way. | 43 // Interface for storing form passwords in a platform-specific secure way. |
| 36 // The login request/manipulation API is not threadsafe and must be used | 44 // The login request/manipulation API is not threadsafe and must be used |
| 37 // from the UI thread. | 45 // from the UI thread. |
| 38 class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> { | 46 class PasswordStore |
| 47 : public base::RefCountedThreadSafe<PasswordStore>, | |
| 48 public CancelableRequestProvider { | |
| 39 public: | 49 public: |
| 50 typedef Callback2<Handle, | |
| 51 const std::vector<webkit_glue::PasswordForm*>&>::Type | |
| 52 GetLoginsCallback; | |
| 53 | |
| 54 // Destructor cleans up after canceled requests by deleting vector elements. | |
|
stuartmorgan
2011/03/16 23:25:20
This doesn't seem like a description of the class.
Sheridan Rawlins
2011/03/20 08:13:11
Done.
| |
| 55 class GetLoginsRequest | |
|
James Hawkins
2011/03/16 22:39:35
This should probably be defined in the implementat
brettw
2011/03/17 21:40:34
Why do you do this at all instead of just having a
Sheridan Rawlins
2011/03/18 15:45:48
If I can change the type of |value| to a ScopedVec
Sheridan Rawlins
2011/03/20 08:13:11
Done.
| |
| 56 : public CancelableRequest1<GetLoginsCallback, | |
| 57 std::vector<webkit_glue::PasswordForm*> > { | |
| 58 public: | |
| 59 explicit GetLoginsRequest(GetLoginsCallback* callback) | |
| 60 : CancelableRequest1<GetLoginsCallback, | |
| 61 std::vector<webkit_glue::PasswordForm*> >(callback) {} | |
|
stuartmorgan
2011/03/16 23:25:20
Fix indentation. Also, I believe having the empty
Sheridan Rawlins
2011/03/18 15:45:48
Good point. Again, if I change to typedef, this w
Sheridan Rawlins
2011/03/20 08:13:11
Done.
Sheridan Rawlins
2011/03/21 05:20:17
I noticed the following addition was merged in rec
| |
| 62 virtual ~GetLoginsRequest(); | |
| 63 | |
| 64 private: | |
| 65 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest); | |
| 66 }; | |
| 67 | |
| 40 PasswordStore(); | 68 PasswordStore(); |
| 41 | 69 |
| 42 // Reimplement this to add custom initialization. Always call this too. | 70 // Reimplement this to add custom initialization. Always call this too. |
| 43 virtual bool Init(); | 71 virtual bool Init(); |
| 44 | 72 |
| 45 // Adds the given PasswordForm to the secure password store asynchronously. | 73 // Adds the given PasswordForm to the secure password store asynchronously. |
| 46 virtual void AddLogin(const webkit_glue::PasswordForm& form); | 74 virtual void AddLogin(const webkit_glue::PasswordForm& form); |
| 47 | 75 |
| 48 // Updates the matching PasswordForm in the secure password store (async). | 76 // Updates the matching PasswordForm in the secure password store (async). |
| 49 void UpdateLogin(const webkit_glue::PasswordForm& form); | 77 void UpdateLogin(const webkit_glue::PasswordForm& form); |
| 50 | 78 |
| 51 // Removes the matching PasswordForm from the secure password store (async). | 79 // Removes the matching PasswordForm from the secure password store (async). |
| 52 void RemoveLogin(const webkit_glue::PasswordForm& form); | 80 void RemoveLogin(const webkit_glue::PasswordForm& form); |
| 53 | 81 |
| 54 // Removes all logins created in the given date range. | 82 // Removes all logins created in the given date range. |
| 55 void RemoveLoginsCreatedBetween(const base::Time& delete_begin, | 83 void RemoveLoginsCreatedBetween(const base::Time& delete_begin, |
| 56 const base::Time& delete_end); | 84 const base::Time& delete_end); |
| 57 | 85 |
| 58 // Searches for a matching PasswordForm and returns a handle so the async | 86 // Searches for a matching PasswordForm and returns a handle so the async |
| 59 // request can be tracked. Implement the PasswordStoreConsumer interface to | 87 // request can be tracked. Implement the Consumer interface to be |
| 60 // be notified on completion. | 88 // notified on completion. |
| 61 virtual int GetLogins(const webkit_glue::PasswordForm& form, | 89 virtual Handle GetLogins(const webkit_glue::PasswordForm& form, |
| 62 PasswordStoreConsumer* consumer); | 90 PasswordStoreConsumer* consumer); |
| 63 | 91 |
| 64 // Gets the complete list of PasswordForms that are not blacklist entries--and | 92 // Gets the complete list of PasswordForms that are not blacklist entries--and |
| 65 // are thus auto-fillable--and returns a handle so the async request can be | 93 // are thus auto-fillable--and returns a handle so the async request can be |
| 66 // tracked. Implement the PasswordStoreConsumer interface to be notified | 94 // tracked. Implement the PasswordStoreConsumer interface to be notified on |
| 67 // on completion. | 95 // completion. |
| 68 int GetAutofillableLogins(PasswordStoreConsumer* consumer); | 96 Handle GetAutofillableLogins(PasswordStoreConsumer* consumer); |
| 69 | 97 |
| 70 // Gets the complete list of PasswordForms that are blacklist entries, and | 98 // Gets the complete list of PasswordForms that are blacklist entries, and |
| 71 // returns a handle so the async request can be tracked. Implement the | 99 // returns a handle so the async request can be tracked. Implement the |
| 72 // PasswordStoreConsumer interface to be notified on completion. | 100 // PasswordStoreConsumer interface to be notified on completion. |
| 73 int GetBlacklistLogins(PasswordStoreConsumer* consumer); | 101 Handle GetBlacklistLogins(PasswordStoreConsumer* consumer); |
| 74 | |
| 75 // Cancels a previous Get*Logins query (async) | |
| 76 void CancelLoginsQuery(int handle); | |
| 77 | 102 |
| 78 // Reports usage metrics for the database. | 103 // Reports usage metrics for the database. |
| 79 virtual void ReportMetrics(); | 104 virtual void ReportMetrics(); |
| 80 | 105 |
| 81 protected: | 106 protected: |
| 82 friend class base::RefCountedThreadSafe<PasswordStore>; | 107 friend class base::RefCountedThreadSafe<PasswordStore>; |
| 83 friend class browser_sync::PasswordDataTypeController; | 108 friend class browser_sync::PasswordDataTypeController; |
| 84 friend class browser_sync::PasswordModelAssociator; | 109 friend class browser_sync::PasswordModelAssociator; |
| 85 friend class browser_sync::PasswordModelWorker; | 110 friend class browser_sync::PasswordModelWorker; |
| 86 friend class LivePasswordsSyncTest; | 111 friend class LivePasswordsSyncTest; |
| 87 | 112 |
| 88 virtual ~PasswordStore(); | 113 virtual ~PasswordStore(); |
| 89 | 114 |
| 90 // Simple container class that represents a login lookup request. | |
| 91 class GetLoginsRequest { | |
| 92 public: | |
| 93 GetLoginsRequest(PasswordStoreConsumer* c, | |
| 94 int handle); | |
| 95 | |
| 96 // The consumer to notify when this request is complete. | |
| 97 PasswordStoreConsumer* consumer; | |
| 98 // A unique handle for the request | |
| 99 int handle; | |
| 100 // The message loop that the request was made from. We send the result | |
| 101 // back to the consumer in this same message loop. | |
| 102 MessageLoop* message_loop; | |
| 103 | |
| 104 private: | |
| 105 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest); | |
| 106 }; | |
| 107 | |
| 108 // Schedule the given task to be run in the PasswordStore's own thread. | 115 // Schedule the given task to be run in the PasswordStore's own thread. |
| 109 virtual void ScheduleTask(Task* task); | 116 virtual void ScheduleTask(Task* task); |
| 110 | 117 |
| 118 template<typename BackendFunc> | |
| 119 Handle Schedule( | |
|
James Hawkins
2011/03/16 22:39:35
Don't add code to headers.
Sheridan Rawlins
2011/03/18 15:45:48
I referenced the HistoryService files when creatin
Sheridan Rawlins
2011/03/20 08:13:11
Done.
| |
| 120 BackendFunc func, // Function to call on PasswordStore's thread. | |
|
stuartmorgan
2011/03/16 23:25:20
I've never seen this style; please use the normal
Sheridan Rawlins
2011/03/18 15:45:48
I believe this also is referenced from HistoryServ
| |
| 121 PasswordStoreConsumer* consumer) { | |
| 122 scoped_refptr<GetLoginsRequest> request(new GetLoginsRequest( | |
|
stuartmorgan
2011/03/16 23:25:20
Why is the implementation inline?
Sheridan Rawlins
2011/03/18 15:45:48
Because of templating. If this is defined in the
Sheridan Rawlins
2011/03/20 08:13:11
Done.
| |
| 123 NewCallback(consumer, | |
| 124 &PasswordStoreConsumer::OnPasswordStoreRequestDone))); | |
| 125 AddRequest(request, consumer->cancelable_consumer()); | |
| 126 ScheduleTask(NewRunnableMethod(this, func, request)); | |
| 127 return request->handle(); | |
| 128 } | |
| 129 | |
| 130 template<typename BackendFunc, typename ArgA> | |
| 131 Handle Schedule( | |
|
stuartmorgan
2011/03/16 23:25:20
Same concerns here.
Sheridan Rawlins
2011/03/18 15:45:48
Ditto above. Will look into this.
Sheridan Rawlins
2011/03/20 08:13:11
Done.
| |
| 132 BackendFunc func, // Function to call on PasswordStore's thread. | |
| 133 PasswordStoreConsumer* consumer, | |
| 134 const ArgA& a) { | |
| 135 scoped_refptr<GetLoginsRequest> request(new GetLoginsRequest( | |
| 136 NewCallback(consumer, | |
| 137 &PasswordStoreConsumer::OnPasswordStoreRequestDone))); | |
| 138 AddRequest(request, consumer->cancelable_consumer()); | |
| 139 ScheduleTask(NewRunnableMethod(this, func, request, a)); | |
| 140 return request->handle(); | |
| 141 } | |
| 142 | |
| 111 // These will be run in PasswordStore's own thread. | 143 // These will be run in PasswordStore's own thread. |
| 112 // Synchronous implementation that reports usage metrics. | 144 // Synchronous implementation that reports usage metrics. |
| 113 virtual void ReportMetricsImpl() = 0; | 145 virtual void ReportMetricsImpl() = 0; |
| 114 // Synchronous implementation to add the given login. | 146 // Synchronous implementation to add the given login. |
| 115 virtual void AddLoginImpl(const webkit_glue::PasswordForm& form) = 0; | 147 virtual void AddLoginImpl(const webkit_glue::PasswordForm& form) = 0; |
| 116 // Synchronous implementation to update the given login. | 148 // Synchronous implementation to update the given login. |
| 117 virtual void UpdateLoginImpl(const webkit_glue::PasswordForm& form) = 0; | 149 virtual void UpdateLoginImpl(const webkit_glue::PasswordForm& form) = 0; |
| 118 // Synchronous implementation to remove the given login. | 150 // Synchronous implementation to remove the given login. |
| 119 virtual void RemoveLoginImpl(const webkit_glue::PasswordForm& form) = 0; | 151 virtual void RemoveLoginImpl(const webkit_glue::PasswordForm& form) = 0; |
| 120 // Synchronous implementation to remove the given logins. | 152 // Synchronous implementation to remove the given logins. |
| 121 virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin, | 153 virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin, |
| 122 const base::Time& delete_end) = 0; | 154 const base::Time& delete_end) = 0; |
| 123 // Should find all PasswordForms with the same signon_realm. The results | 155 // Should find all PasswordForms with the same signon_realm. The results |
| 124 // will then be scored by the PasswordFormManager. Once they are found | 156 // will then be scored by the PasswordFormManager. Once they are found |
| 125 // (or not), the consumer should be notified. | 157 // (or not), the consumer should be notified. |
| 126 virtual void GetLoginsImpl(GetLoginsRequest* request, | 158 virtual void GetLoginsImpl(GetLoginsRequest* request, |
| 127 const webkit_glue::PasswordForm& form) = 0; | 159 const webkit_glue::PasswordForm& form) = 0; |
| 128 // Finds all non-blacklist PasswordForms, and notifies the consumer. | 160 // Finds all non-blacklist PasswordForms, and notifies the consumer. |
| 129 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) = 0; | 161 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) = 0; |
| 130 // Finds all blacklist PasswordForms, and notifies the consumer. | 162 // Finds all blacklist PasswordForms, and notifies the consumer. |
| 131 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0; | 163 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0; |
| 132 | 164 |
| 133 // Finds all non-blacklist PasswordForms, and fills the vector. | 165 // Finds all non-blacklist PasswordForms, and fills the vector. |
| 134 virtual bool FillAutofillableLogins( | 166 virtual bool FillAutofillableLogins( |
| 135 std::vector<webkit_glue::PasswordForm*>* forms) = 0; | 167 std::vector<webkit_glue::PasswordForm*>* forms) = 0; |
| 136 // Finds all blacklist PasswordForms, and fills the vector. | 168 // Finds all blacklist PasswordForms, and fills the vector. |
| 137 virtual bool FillBlacklistLogins( | 169 virtual bool FillBlacklistLogins( |
| 138 std::vector<webkit_glue::PasswordForm*>* forms) = 0; | 170 std::vector<webkit_glue::PasswordForm*>* forms) = 0; |
| 139 | 171 |
| 140 // Notifies the consumer that a Get*Logins() request is complete. | 172 virtual void ForwardLoginsResult(GetLoginsRequest* request); |
|
stuartmorgan
2011/03/16 23:25:20
Comment
Sheridan Rawlins
2011/03/20 08:13:11
Done.
| |
| 141 virtual void NotifyConsumer( | |
| 142 GetLoginsRequest* request, | |
| 143 const std::vector<webkit_glue::PasswordForm*>& forms); | |
| 144 | 173 |
| 145 private: | 174 private: |
| 146 // Called by NotifyConsumer, but runs in the consumer's thread. Will not | |
| 147 // call the consumer if the request was canceled. This extra layer is here so | |
| 148 // that PasswordStoreConsumer doesn't have to be reference counted (we assume | |
| 149 // consumers will cancel their requests before they are destroyed). | |
| 150 void NotifyConsumerImpl(PasswordStoreConsumer* consumer, int handle, | |
| 151 const std::vector<webkit_glue::PasswordForm*>& forms); | |
| 152 | |
| 153 // Returns a new request handle tracked in pending_requests_. | |
| 154 int GetNewRequestHandle(); | |
| 155 | |
| 156 // Next handle to return from Get*Logins() to allow callers to track | |
| 157 // their request. | |
| 158 int handle_; | |
| 159 | |
| 160 // List of pending request handles. Handles are removed from the set when | |
| 161 // they finish or are canceled. | |
| 162 std::set<int> pending_requests_; | |
| 163 | 175 |
| 164 DISALLOW_COPY_AND_ASSIGN(PasswordStore); | 176 DISALLOW_COPY_AND_ASSIGN(PasswordStore); |
| 165 }; | 177 }; |
| 166 | 178 |
| 167 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ | 179 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ |
| OLD | NEW |