| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.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 "chrome/browser/common/cancelable_request.h" | 15 #include "chrome/browser/common/cancelable_request.h" |
| 16 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" | 16 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" |
| 17 | 17 |
| 18 class PasswordStore; | 18 class PasswordStore; |
| 19 class PasswordStoreConsumer; | 19 class PasswordStoreConsumer; |
| 20 class Task; | 20 class Task; |
| 21 | 21 |
| 22 namespace browser_sync { | 22 namespace browser_sync { |
| 23 class PasswordDataTypeController; | 23 class PasswordDataTypeController; |
| 24 class PasswordModelAssociator; | 24 class PasswordModelAssociator; |
| 25 class PasswordModelWorker; | 25 class PasswordModelWorker; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace webkit { | 28 namespace content { |
| 29 namespace forms { | |
| 30 struct PasswordForm; | 29 struct PasswordForm; |
| 31 } | 30 } |
| 32 } | |
| 33 | 31 |
| 34 namespace passwords_helper { | 32 namespace passwords_helper { |
| 35 void AddLogin(PasswordStore* store, const webkit::forms::PasswordForm& form); | 33 void AddLogin(PasswordStore* store, const content::PasswordForm& form); |
| 36 void RemoveLogin(PasswordStore* store, const webkit::forms::PasswordForm& form); | 34 void RemoveLogin(PasswordStore* store, const content::PasswordForm& form); |
| 37 void UpdateLogin(PasswordStore* store, const webkit::forms::PasswordForm& form); | 35 void UpdateLogin(PasswordStore* store, const content::PasswordForm& form); |
| 38 } | 36 } |
| 39 | 37 |
| 40 // Interface for storing form passwords in a platform-specific secure way. | 38 // Interface for storing form passwords in a platform-specific secure way. |
| 41 // The login request/manipulation API is not threadsafe and must be used | 39 // The login request/manipulation API is not threadsafe and must be used |
| 42 // from the UI thread. | 40 // from the UI thread. |
| 43 class PasswordStore | 41 class PasswordStore |
| 44 : public RefcountedProfileKeyedService, | 42 : public RefcountedProfileKeyedService, |
| 45 public CancelableRequestProvider { | 43 public CancelableRequestProvider { |
| 46 public: | 44 public: |
| 47 typedef base::Callback< | 45 typedef base::Callback< |
| 48 void(Handle, const std::vector<webkit::forms::PasswordForm*>&)> | 46 void(Handle, const std::vector<content::PasswordForm*>&)> |
| 49 GetLoginsCallback; | 47 GetLoginsCallback; |
| 50 | 48 |
| 51 // PasswordForm vector elements are meant to be owned by the | 49 // PasswordForm vector elements are meant to be owned by the |
| 52 // PasswordStoreConsumer. However, if the request is canceled after the | 50 // PasswordStoreConsumer. However, if the request is canceled after the |
| 53 // allocation, then the request must take care of the deletion. | 51 // allocation, then the request must take care of the deletion. |
| 54 class GetLoginsRequest | 52 class GetLoginsRequest |
| 55 : public CancelableRequest1<GetLoginsCallback, | 53 : public CancelableRequest1<GetLoginsCallback, |
| 56 std::vector<webkit::forms::PasswordForm*> > { | 54 std::vector<content::PasswordForm*> > { |
| 57 public: | 55 public: |
| 58 explicit GetLoginsRequest(const GetLoginsCallback& callback); | 56 explicit GetLoginsRequest(const GetLoginsCallback& callback); |
| 59 | 57 |
| 60 void set_ignore_logins_cutoff(const base::Time& cutoff) { | 58 void set_ignore_logins_cutoff(const base::Time& cutoff) { |
| 61 ignore_logins_cutoff_ = cutoff; | 59 ignore_logins_cutoff_ = cutoff; |
| 62 } | 60 } |
| 63 | 61 |
| 64 // Removes any logins in the result list that were saved before the cutoff. | 62 // Removes any logins in the result list that were saved before the cutoff. |
| 65 void ApplyIgnoreLoginsCutoff(); | 63 void ApplyIgnoreLoginsCutoff(); |
| 66 | 64 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 85 protected: | 83 protected: |
| 86 virtual ~Observer() {} | 84 virtual ~Observer() {} |
| 87 }; | 85 }; |
| 88 | 86 |
| 89 PasswordStore(); | 87 PasswordStore(); |
| 90 | 88 |
| 91 // Reimplement this to add custom initialization. Always call this too. | 89 // Reimplement this to add custom initialization. Always call this too. |
| 92 virtual bool Init(); | 90 virtual bool Init(); |
| 93 | 91 |
| 94 // Adds the given PasswordForm to the secure password store asynchronously. | 92 // Adds the given PasswordForm to the secure password store asynchronously. |
| 95 virtual void AddLogin(const webkit::forms::PasswordForm& form); | 93 virtual void AddLogin(const content::PasswordForm& form); |
| 96 | 94 |
| 97 // Updates the matching PasswordForm in the secure password store (async). | 95 // Updates the matching PasswordForm in the secure password store (async). |
| 98 void UpdateLogin(const webkit::forms::PasswordForm& form); | 96 void UpdateLogin(const content::PasswordForm& form); |
| 99 | 97 |
| 100 // Removes the matching PasswordForm from the secure password store (async). | 98 // Removes the matching PasswordForm from the secure password store (async). |
| 101 void RemoveLogin(const webkit::forms::PasswordForm& form); | 99 void RemoveLogin(const content::PasswordForm& form); |
| 102 | 100 |
| 103 // Removes all logins created in the given date range. | 101 // Removes all logins created in the given date range. |
| 104 void RemoveLoginsCreatedBetween(const base::Time& delete_begin, | 102 void RemoveLoginsCreatedBetween(const base::Time& delete_begin, |
| 105 const base::Time& delete_end); | 103 const base::Time& delete_end); |
| 106 | 104 |
| 107 // Searches for a matching PasswordForm and returns a handle so the async | 105 // Searches for a matching PasswordForm and returns a handle so the async |
| 108 // request can be tracked. Implement the PasswordStoreConsumer interface to be | 106 // request can be tracked. Implement the PasswordStoreConsumer interface to be |
| 109 // notified on completion. | 107 // notified on completion. |
| 110 virtual Handle GetLogins(const webkit::forms::PasswordForm& form, | 108 virtual Handle GetLogins(const content::PasswordForm& form, |
| 111 PasswordStoreConsumer* consumer); | 109 PasswordStoreConsumer* consumer); |
| 112 | 110 |
| 113 // Gets the complete list of PasswordForms that are not blacklist entries--and | 111 // Gets the complete list of PasswordForms that are not blacklist entries--and |
| 114 // are thus auto-fillable--and returns a handle so the async request can be | 112 // are thus auto-fillable--and returns a handle so the async request can be |
| 115 // tracked. Implement the PasswordStoreConsumer interface to be notified on | 113 // tracked. Implement the PasswordStoreConsumer interface to be notified on |
| 116 // completion. | 114 // completion. |
| 117 Handle GetAutofillableLogins(PasswordStoreConsumer* consumer); | 115 Handle GetAutofillableLogins(PasswordStoreConsumer* consumer); |
| 118 | 116 |
| 119 // Gets the complete list of PasswordForms that are blacklist entries, and | 117 // Gets the complete list of PasswordForms that are blacklist entries, and |
| 120 // returns a handle so the async request can be tracked. Implement the | 118 // returns a handle so the async request can be tracked. Implement the |
| 121 // PasswordStoreConsumer interface to be notified on completion. | 119 // PasswordStoreConsumer interface to be notified on completion. |
| 122 Handle GetBlacklistLogins(PasswordStoreConsumer* consumer); | 120 Handle GetBlacklistLogins(PasswordStoreConsumer* consumer); |
| 123 | 121 |
| 124 // Reports usage metrics for the database. | 122 // Reports usage metrics for the database. |
| 125 void ReportMetrics(); | 123 void ReportMetrics(); |
| 126 | 124 |
| 127 // Adds an observer to be notified when the password store data changes. | 125 // Adds an observer to be notified when the password store data changes. |
| 128 void AddObserver(Observer* observer); | 126 void AddObserver(Observer* observer); |
| 129 | 127 |
| 130 // Removes |observer| from the observer list. | 128 // Removes |observer| from the observer list. |
| 131 void RemoveObserver(Observer* observer); | 129 void RemoveObserver(Observer* observer); |
| 132 | 130 |
| 133 protected: | 131 protected: |
| 134 friend class base::RefCountedThreadSafe<PasswordStore>; | 132 friend class base::RefCountedThreadSafe<PasswordStore>; |
| 135 friend class browser_sync::PasswordDataTypeController; | 133 friend class browser_sync::PasswordDataTypeController; |
| 136 friend class browser_sync::PasswordModelAssociator; | 134 friend class browser_sync::PasswordModelAssociator; |
| 137 friend class browser_sync::PasswordModelWorker; | 135 friend class browser_sync::PasswordModelWorker; |
| 138 friend void passwords_helper::AddLogin(PasswordStore*, | 136 friend void passwords_helper::AddLogin(PasswordStore*, |
| 139 const webkit::forms::PasswordForm&); | 137 const content::PasswordForm&); |
| 140 friend void passwords_helper::RemoveLogin(PasswordStore*, | 138 friend void passwords_helper::RemoveLogin(PasswordStore*, |
| 141 const webkit::forms::PasswordForm&); | 139 const content::PasswordForm&); |
| 142 friend void passwords_helper::UpdateLogin(PasswordStore*, | 140 friend void passwords_helper::UpdateLogin(PasswordStore*, |
| 143 const webkit::forms::PasswordForm&); | 141 const content::PasswordForm&); |
| 144 | 142 |
| 145 virtual ~PasswordStore(); | 143 virtual ~PasswordStore(); |
| 146 | 144 |
| 147 // Provided to allow subclasses to extend GetLoginsRequest if additional info | 145 // Provided to allow subclasses to extend GetLoginsRequest if additional info |
| 148 // is needed between a call and its Impl. | 146 // is needed between a call and its Impl. |
| 149 virtual GetLoginsRequest* NewGetLoginsRequest( | 147 virtual GetLoginsRequest* NewGetLoginsRequest( |
| 150 const GetLoginsCallback& callback); | 148 const GetLoginsCallback& callback); |
| 151 | 149 |
| 152 // Schedule the given |task| to be run in the PasswordStore's own thread. | 150 // Schedule the given |task| to be run in the PasswordStore's own thread. |
| 153 virtual bool ScheduleTask(const base::Closure& task); | 151 virtual bool ScheduleTask(const base::Closure& task); |
| 154 | 152 |
| 155 // These will be run in PasswordStore's own thread. | 153 // These will be run in PasswordStore's own thread. |
| 156 // Synchronous implementation that reports usage metrics. | 154 // Synchronous implementation that reports usage metrics. |
| 157 virtual void ReportMetricsImpl() = 0; | 155 virtual void ReportMetricsImpl() = 0; |
| 158 // Synchronous implementation to add the given login. | 156 // Synchronous implementation to add the given login. |
| 159 virtual void AddLoginImpl(const webkit::forms::PasswordForm& form) = 0; | 157 virtual void AddLoginImpl(const content::PasswordForm& form) = 0; |
| 160 // Synchronous implementation to update the given login. | 158 // Synchronous implementation to update the given login. |
| 161 virtual void UpdateLoginImpl(const webkit::forms::PasswordForm& form) = 0; | 159 virtual void UpdateLoginImpl(const content::PasswordForm& form) = 0; |
| 162 // Synchronous implementation to remove the given login. | 160 // Synchronous implementation to remove the given login. |
| 163 virtual void RemoveLoginImpl(const webkit::forms::PasswordForm& form) = 0; | 161 virtual void RemoveLoginImpl(const content::PasswordForm& form) = 0; |
| 164 // Synchronous implementation to remove the given logins. | 162 // Synchronous implementation to remove the given logins. |
| 165 virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin, | 163 virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin, |
| 166 const base::Time& delete_end) = 0; | 164 const base::Time& delete_end) = 0; |
| 167 // Should find all PasswordForms with the same signon_realm. The results | 165 // Should find all PasswordForms with the same signon_realm. The results |
| 168 // will then be scored by the PasswordFormManager. Once they are found | 166 // will then be scored by the PasswordFormManager. Once they are found |
| 169 // (or not), the consumer should be notified. | 167 // (or not), the consumer should be notified. |
| 170 virtual void GetLoginsImpl(GetLoginsRequest* request, | 168 virtual void GetLoginsImpl(GetLoginsRequest* request, |
| 171 const webkit::forms::PasswordForm& form) = 0; | 169 const content::PasswordForm& form) = 0; |
| 172 // Finds all non-blacklist PasswordForms, and notifies the consumer. | 170 // Finds all non-blacklist PasswordForms, and notifies the consumer. |
| 173 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) = 0; | 171 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) = 0; |
| 174 // Finds all blacklist PasswordForms, and notifies the consumer. | 172 // Finds all blacklist PasswordForms, and notifies the consumer. |
| 175 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0; | 173 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0; |
| 176 | 174 |
| 177 // Finds all non-blacklist PasswordForms, and fills the vector. | 175 // Finds all non-blacklist PasswordForms, and fills the vector. |
| 178 virtual bool FillAutofillableLogins( | 176 virtual bool FillAutofillableLogins( |
| 179 std::vector<webkit::forms::PasswordForm*>* forms) = 0; | 177 std::vector<content::PasswordForm*>* forms) = 0; |
| 180 // Finds all blacklist PasswordForms, and fills the vector. | 178 // Finds all blacklist PasswordForms, and fills the vector. |
| 181 virtual bool FillBlacklistLogins( | 179 virtual bool FillBlacklistLogins( |
| 182 std::vector<webkit::forms::PasswordForm*>* forms) = 0; | 180 std::vector<content::PasswordForm*>* forms) = 0; |
| 183 | 181 |
| 184 // Dispatches the result to the PasswordStoreConsumer on the original caller's | 182 // Dispatches the result to the PasswordStoreConsumer on the original caller's |
| 185 // thread so the callback can be executed there. This should be the UI thread. | 183 // thread so the callback can be executed there. This should be the UI thread. |
| 186 virtual void ForwardLoginsResult(GetLoginsRequest* request); | 184 virtual void ForwardLoginsResult(GetLoginsRequest* request); |
| 187 | 185 |
| 188 private: | 186 private: |
| 189 // Schedule the given |func| to be run in the PasswordStore's own thread with | 187 // Schedule the given |func| to be run in the PasswordStore's own thread with |
| 190 // responses delivered to |consumer| on the current thread. | 188 // responses delivered to |consumer| on the current thread. |
| 191 template<typename BackendFunc> | 189 template<typename BackendFunc> |
| 192 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer); | 190 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer); |
| 193 | 191 |
| 194 // Schedule the given |func| to be run in the PasswordStore's own thread with | 192 // Schedule the given |func| to be run in the PasswordStore's own thread with |
| 195 // form |form| and responses delivered to |consumer| on the current thread. | 193 // form |form| and responses delivered to |consumer| on the current thread. |
| 196 // See GetLogins() for more information on |ignore_logins_cutoff|. | 194 // See GetLogins() for more information on |ignore_logins_cutoff|. |
| 197 template<typename BackendFunc> | 195 template<typename BackendFunc> |
| 198 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer, | 196 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer, |
| 199 const webkit::forms::PasswordForm& form, | 197 const content::PasswordForm& form, |
| 200 const base::Time& ignore_logins_cutoff); | 198 const base::Time& ignore_logins_cutoff); |
| 201 | 199 |
| 202 // Wrapper method called on the destination thread (DB for non-mac) that | 200 // Wrapper method called on the destination thread (DB for non-mac) that |
| 203 // invokes |task| and then calls back into the source thread to notify | 201 // invokes |task| and then calls back into the source thread to notify |
| 204 // observers that the password store may have been modified via | 202 // observers that the password store may have been modified via |
| 205 // NotifyLoginsChanged(). Note that there is no guarantee that the called | 203 // NotifyLoginsChanged(). Note that there is no guarantee that the called |
| 206 // method will actually modify the password store data. | 204 // method will actually modify the password store data. |
| 207 void WrapModificationTask(base::Closure task); | 205 void WrapModificationTask(base::Closure task); |
| 208 | 206 |
| 209 // Post a message to the UI thread to run NotifyLoginsChanged(). Called by | 207 // Post a message to the UI thread to run NotifyLoginsChanged(). Called by |
| 210 // WrapModificationTask() above, and split out as a separate method so that | 208 // WrapModificationTask() above, and split out as a separate method so that |
| 211 // password sync can call it as well after synchronously updating the password | 209 // password sync can call it as well after synchronously updating the password |
| 212 // store. | 210 // store. |
| 213 void PostNotifyLoginsChanged(); | 211 void PostNotifyLoginsChanged(); |
| 214 | 212 |
| 215 // Called by WrapModificationTask() once the underlying data-modifying | 213 // Called by WrapModificationTask() once the underlying data-modifying |
| 216 // operation has been performed. Notifies observers that password store data | 214 // operation has been performed. Notifies observers that password store data |
| 217 // may have been changed. | 215 // may have been changed. |
| 218 void NotifyLoginsChanged(); | 216 void NotifyLoginsChanged(); |
| 219 | 217 |
| 220 // The observers. | 218 // The observers. |
| 221 ObserverList<Observer> observers_; | 219 ObserverList<Observer> observers_; |
| 222 | 220 |
| 223 DISALLOW_COPY_AND_ASSIGN(PasswordStore); | 221 DISALLOW_COPY_AND_ASSIGN(PasswordStore); |
| 224 }; | 222 }; |
| 225 | 223 |
| 226 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ | 224 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ |
| OLD | NEW |