Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ |
| 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/gtest_prod_util.h" | |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 12 #include "base/observer_list_threadsafe.h" | 13 #include "base/observer_list_threadsafe.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "components/password_manager/core/browser/password_store_change.h" | 16 #include "components/password_manager/core/browser/password_store_change.h" |
| 16 #include "components/password_manager/core/browser/password_store_sync.h" | 17 #include "components/password_manager/core/browser/password_store_sync.h" |
| 17 #include "sync/api/syncable_service.h" | 18 #include "sync/api/syncable_service.h" |
| 18 | 19 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 virtual bool Init(const syncer::SyncableService::StartSyncFlare& flare); | 68 virtual bool Init(const syncer::SyncableService::StartSyncFlare& flare); |
| 68 | 69 |
| 69 // Sets the affiliation-based match |helper| that will be used by subsequent | 70 // Sets the affiliation-based match |helper| that will be used by subsequent |
| 70 // GetLogins() calls to return credentials stored not only for the requested | 71 // GetLogins() calls to return credentials stored not only for the requested |
| 71 // sign-on realm, but also for affiliated Android applications. If |helper| is | 72 // sign-on realm, but also for affiliated Android applications. If |helper| is |
| 72 // null, clears the the currently set helper if any. Unless a helper is set, | 73 // null, clears the the currently set helper if any. Unless a helper is set, |
| 73 // affiliation-based matching is disabled. The passed |helper| must already be | 74 // affiliation-based matching is disabled. The passed |helper| must already be |
| 74 // initialized if it is non-null. | 75 // initialized if it is non-null. |
| 75 void SetAffiliatedMatchHelper(scoped_ptr<AffiliatedMatchHelper> helper); | 76 void SetAffiliatedMatchHelper(scoped_ptr<AffiliatedMatchHelper> helper); |
| 76 | 77 |
| 78 // Toggles whether or not to propagate password changes in Android credentials | |
| 79 // to the affiliated Web credentials. | |
| 80 void enable_propagating_password_changes_to_web_credentials(bool enabled) { | |
| 81 is_propagating_password_changes_to_web_credentials_enabled_ = enabled; | |
| 82 } | |
| 83 | |
| 77 // Returns whether or not an affiliation-based match helper is set. | 84 // Returns whether or not an affiliation-based match helper is set. |
| 78 bool HasAffiliatedMatchHelper() const; | 85 bool HasAffiliatedMatchHelper() const; |
| 79 | 86 |
| 80 // Adds the given PasswordForm to the secure password store asynchronously. | 87 // Adds the given PasswordForm to the secure password store asynchronously. |
| 81 virtual void AddLogin(const autofill::PasswordForm& form); | 88 virtual void AddLogin(const autofill::PasswordForm& form); |
| 82 | 89 |
| 83 // Updates the matching PasswordForm in the secure password store (async). | 90 // Updates the matching PasswordForm in the secure password store (async). |
| 84 virtual void UpdateLogin(const autofill::PasswordForm& form); | 91 virtual void UpdateLogin(const autofill::PasswordForm& form); |
| 85 | 92 |
| 86 // Removes the matching PasswordForm from the secure password store (async). | 93 // Removes the matching PasswordForm from the secure password store (async). |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 // Get the TaskRunner to use for PasswordStore background tasks. | 181 // Get the TaskRunner to use for PasswordStore background tasks. |
| 175 // By default, a SingleThreadTaskRunner on the DB thread is used, but | 182 // By default, a SingleThreadTaskRunner on the DB thread is used, but |
| 176 // subclasses can override. | 183 // subclasses can override. |
| 177 virtual scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner(); | 184 virtual scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner(); |
| 178 | 185 |
| 179 // Methods below will be run in PasswordStore's own thread. | 186 // Methods below will be run in PasswordStore's own thread. |
| 180 // Synchronous implementation that reports usage metrics. | 187 // Synchronous implementation that reports usage metrics. |
| 181 virtual void ReportMetricsImpl(const std::string& sync_username, | 188 virtual void ReportMetricsImpl(const std::string& sync_username, |
| 182 bool custom_passphrase_sync_enabled) = 0; | 189 bool custom_passphrase_sync_enabled) = 0; |
| 183 | 190 |
| 184 // Bring PasswordStoreSync methods to the scope of PasswordStore. Otherwise, | |
| 185 // base::Bind can't be used with them because it fails to cast PasswordStore | |
| 186 // to PasswordStoreSync. | |
| 187 PasswordStoreChangeList AddLoginImpl( | |
| 188 const autofill::PasswordForm& form) override = 0; | |
| 189 PasswordStoreChangeList UpdateLoginImpl( | |
| 190 const autofill::PasswordForm& form) override = 0; | |
| 191 PasswordStoreChangeList RemoveLoginImpl( | |
| 192 const autofill::PasswordForm& form) override = 0; | |
| 193 | |
| 194 // Synchronous implementation to remove the given logins. | 191 // Synchronous implementation to remove the given logins. |
| 195 virtual PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl( | 192 virtual PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl( |
| 196 base::Time delete_begin, | 193 base::Time delete_begin, |
| 197 base::Time delete_end) = 0; | 194 base::Time delete_end) = 0; |
| 198 | 195 |
| 199 // Synchronous implementation to remove the given logins. | 196 // Synchronous implementation to remove the given logins. |
| 200 virtual PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl( | 197 virtual PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl( |
| 201 base::Time delete_begin, | 198 base::Time delete_begin, |
| 202 base::Time delete_end) = 0; | 199 base::Time delete_end) = 0; |
| 203 | 200 |
| 204 // Finds all PasswordForms with a signon_realm that is equal to, or is a | 201 // Finds all PasswordForms with a signon_realm that is equal to, or is a |
| 205 // PSL-match to that of |form|, and takes care of notifying the consumer with | 202 // PSL-match to that of |form|, and takes care of notifying the consumer with |
| 206 // the results when done. | 203 // the results when done. |
| 207 // Note: subclasses should implement FillMatchingLogins() instead. This needs | 204 // Note: subclasses should implement FillMatchingLogins() instead. This needs |
| 208 // to be virtual only because asynchronous behavior in PasswordStoreWin. | 205 // to be virtual only because asynchronous behavior in PasswordStoreWin. |
| 209 // TODO(engedy): Make this non-virtual once https://crbug.com/78830 is fixed. | 206 // TODO(engedy): Make this non-virtual once https://crbug.com/78830 is fixed. |
| 210 virtual void GetLoginsImpl(const autofill::PasswordForm& form, | 207 virtual void GetLoginsImpl(const autofill::PasswordForm& form, |
| 211 AuthorizationPromptPolicy prompt_policy, | 208 AuthorizationPromptPolicy prompt_policy, |
| 212 scoped_ptr<GetLoginsRequest> request); | 209 scoped_ptr<GetLoginsRequest> request); |
| 213 | 210 |
| 211 // Synchronous implementation provided by subclasses to add the given login. | |
| 212 virtual PasswordStoreChangeList AddLoginImpl( | |
| 213 const autofill::PasswordForm& form) = 0; | |
| 214 | |
| 215 // Synchronous implementation provided by subclasses to update the given | |
| 216 // login. | |
| 217 virtual PasswordStoreChangeList UpdateLoginImpl( | |
| 218 const autofill::PasswordForm& form) = 0; | |
| 219 | |
| 220 // Synchronous implementation provided by subclasses to remove the given | |
| 221 // login. | |
| 222 virtual PasswordStoreChangeList RemoveLoginImpl( | |
| 223 const autofill::PasswordForm& form) = 0; | |
| 224 | |
| 214 // Finds and returns all PasswordForms with the same signon_realm as |form|, | 225 // Finds and returns all PasswordForms with the same signon_realm as |form|, |
| 215 // or with a signon_realm that is a PSL-match to that of |form|. | 226 // or with a signon_realm that is a PSL-match to that of |form|. |
| 216 virtual ScopedVector<autofill::PasswordForm> FillMatchingLogins( | 227 virtual ScopedVector<autofill::PasswordForm> FillMatchingLogins( |
| 217 const autofill::PasswordForm& form, | 228 const autofill::PasswordForm& form, |
| 218 AuthorizationPromptPolicy prompt_policy) = 0; | 229 AuthorizationPromptPolicy prompt_policy) = 0; |
| 219 | 230 |
| 220 // Finds all non-blacklist PasswordForms, and notifies the consumer. | 231 // Finds all non-blacklist PasswordForms, and notifies the consumer. |
| 221 virtual void GetAutofillableLoginsImpl( | 232 virtual void GetAutofillableLoginsImpl( |
| 222 scoped_ptr<GetLoginsRequest> request) = 0; | 233 scoped_ptr<GetLoginsRequest> request) = 0; |
| 223 | 234 |
| 224 // Finds all blacklist PasswordForms, and notifies the consumer. | 235 // Finds all blacklist PasswordForms, and notifies the consumer. |
| 225 virtual void GetBlacklistLoginsImpl(scoped_ptr<GetLoginsRequest> request) = 0; | 236 virtual void GetBlacklistLoginsImpl(scoped_ptr<GetLoginsRequest> request) = 0; |
| 226 | 237 |
| 227 // Log UMA stats for number of bulk deletions. | 238 // Log UMA stats for number of bulk deletions. |
| 228 void LogStatsForBulkDeletion(int num_deletions); | 239 void LogStatsForBulkDeletion(int num_deletions); |
| 229 | 240 |
| 230 // Log UMA stats for password deletions happening on clear browsing data | 241 // Log UMA stats for password deletions happening on clear browsing data |
| 231 // since first sync during rollback. | 242 // since first sync during rollback. |
| 232 void LogStatsForBulkDeletionDuringRollback(int num_deletions); | 243 void LogStatsForBulkDeletionDuringRollback(int num_deletions); |
| 233 | 244 |
| 234 // PasswordStoreSync: | 245 // PasswordStoreSync: |
| 246 PasswordStoreChangeList AddLoginSync( | |
| 247 const autofill::PasswordForm& form) override; | |
| 248 PasswordStoreChangeList UpdateLoginSync( | |
| 249 const autofill::PasswordForm& form) override; | |
| 250 PasswordStoreChangeList RemoveLoginSync( | |
| 251 const autofill::PasswordForm& form) override; | |
| 252 | |
| 235 // Called by WrapModificationTask() once the underlying data-modifying | 253 // Called by WrapModificationTask() once the underlying data-modifying |
| 236 // operation has been performed. Notifies observers that password store data | 254 // operation has been performed. Notifies observers that password store data |
| 237 // may have been changed. | 255 // may have been changed. |
| 238 void NotifyLoginsChanged(const PasswordStoreChangeList& changes) override; | 256 void NotifyLoginsChanged(const PasswordStoreChangeList& changes) override; |
| 239 | 257 |
| 240 // TaskRunner for tasks that run on the main thread (usually the UI thread). | 258 // TaskRunner for tasks that run on the main thread (usually the UI thread). |
| 241 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; | 259 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; |
| 242 | 260 |
| 243 // TaskRunner for the DB thread. By default, this is the task runner used for | 261 // TaskRunner for the DB thread. By default, this is the task runner used for |
| 244 // background tasks -- see |GetBackgroundTaskRunner|. | 262 // background tasks -- see |GetBackgroundTaskRunner|. |
| 245 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner_; | 263 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner_; |
| 246 | 264 |
| 247 private: | 265 private: |
| 266 FRIEND_TEST_ALL_PREFIXES(PasswordStoreTest, GetLoginImpl); | |
| 267 FRIEND_TEST_ALL_PREFIXES(PasswordStoreTest, | |
| 268 UpdatePasswordsStoredForAffiliatedWebsites); | |
| 269 | |
| 248 // Schedule the given |func| to be run in the PasswordStore's own thread with | 270 // Schedule the given |func| to be run in the PasswordStore's own thread with |
| 249 // responses delivered to |consumer| on the current thread. | 271 // responses delivered to |consumer| on the current thread. |
| 250 void Schedule(void (PasswordStore::*func)(scoped_ptr<GetLoginsRequest>), | 272 void Schedule(void (PasswordStore::*func)(scoped_ptr<GetLoginsRequest>), |
| 251 PasswordStoreConsumer* consumer); | 273 PasswordStoreConsumer* consumer); |
| 252 | 274 |
| 253 // Wrapper method called on the destination thread (DB for non-mac) that | 275 // Wrapper method called on the destination thread (DB for non-mac) that |
| 254 // invokes |task| and then calls back into the source thread to notify | 276 // invokes |task| and then calls back into the source thread to notify |
| 255 // observers that the password store may have been modified via | 277 // observers that the password store may have been modified via |
| 256 // NotifyLoginsChanged(). Note that there is no guarantee that the called | 278 // NotifyLoginsChanged(). Note that there is no guarantee that the called |
| 257 // method will actually modify the password store data. | 279 // method will actually modify the password store data. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 279 scoped_ptr<GetLoginsRequest> request, | 301 scoped_ptr<GetLoginsRequest> request, |
| 280 const std::vector<std::string>& additional_android_realms); | 302 const std::vector<std::string>& additional_android_realms); |
| 281 | 303 |
| 282 // Schedules GetLoginsWithAffiliationsImpl() to be run on the DB thread. | 304 // Schedules GetLoginsWithAffiliationsImpl() to be run on the DB thread. |
| 283 void ScheduleGetLoginsWithAffiliations( | 305 void ScheduleGetLoginsWithAffiliations( |
| 284 const autofill::PasswordForm& form, | 306 const autofill::PasswordForm& form, |
| 285 AuthorizationPromptPolicy prompt_policy, | 307 AuthorizationPromptPolicy prompt_policy, |
| 286 scoped_ptr<GetLoginsRequest> request, | 308 scoped_ptr<GetLoginsRequest> request, |
| 287 const std::vector<std::string>& additional_android_realms); | 309 const std::vector<std::string>& additional_android_realms); |
| 288 | 310 |
| 311 // Retrieves the currently stored form, if any, with the same primary key as | |
| 312 // |form|, that is, with the same signon_realm, origin, username_element, | |
| 313 // username_value and password_element attributes. | |
| 314 scoped_ptr<autofill::PasswordForm> GetLoginImpl( | |
|
vasilii
2015/04/21 09:20:18
For these functions mention the thread they are ex
engedy
2015/04/21 09:42:25
Done.
| |
| 315 const autofill::PasswordForm& primary_key); | |
| 316 | |
| 317 // Called when a password is added or updated for an Android application, and | |
| 318 // triggers finding web sites affiliated with the Android application and | |
| 319 // propagating the new password to credentials for those web sites, if any. | |
| 320 void FindAndUpdateAffiliatedWebLogins( | |
| 321 const autofill::PasswordForm& added_or_updated_android_form); | |
| 322 | |
| 323 // Posts FindAndUpdateAffiliatedWebLogins() to the main thread. | |
| 324 void ScheduleFindAndUpdateAffiliatedWebLogins( | |
| 325 const autofill::PasswordForm& added_or_updated_android_form); | |
| 326 | |
| 327 // Called when a password is added or updated for an Android application, and | |
| 328 // propagates these changes to credentials stored for |affiliated_web_realms| | |
| 329 // under the same username, if there are any. | |
| 330 void UpdateAffiliatedWebLoginsImpl( | |
| 331 const autofill::PasswordForm& updated_android_form, | |
| 332 const std::vector<std::string>& affiliated_web_realms); | |
| 333 | |
| 334 // Schedules UpdateAffiliatedWebLoginsImpl() to run on the DB thread. | |
| 335 void ScheduleUpdateAffiliatedWebLoginsImpl( | |
| 336 const autofill::PasswordForm& updated_android_form, | |
| 337 const std::vector<std::string>& affiliated_web_realms); | |
| 338 | |
| 289 // Creates PasswordSyncableService instance on the background thread. | 339 // Creates PasswordSyncableService instance on the background thread. |
| 290 void InitSyncableService( | 340 void InitSyncableService( |
| 291 const syncer::SyncableService::StartSyncFlare& flare); | 341 const syncer::SyncableService::StartSyncFlare& flare); |
| 292 | 342 |
| 293 // Deletes PasswordSyncableService instance on the background thread. | 343 // Deletes PasswordSyncableService instance on the background thread. |
| 294 void DestroySyncableService(); | 344 void DestroySyncableService(); |
| 295 | 345 |
| 296 // The observers. | 346 // The observers. |
| 297 scoped_refptr<ObserverListThreadSafe<Observer>> observers_; | 347 scoped_refptr<ObserverListThreadSafe<Observer>> observers_; |
| 298 | 348 |
| 299 scoped_ptr<PasswordSyncableService> syncable_service_; | 349 scoped_ptr<PasswordSyncableService> syncable_service_; |
| 300 scoped_ptr<AffiliatedMatchHelper> affiliated_match_helper_; | 350 scoped_ptr<AffiliatedMatchHelper> affiliated_match_helper_; |
| 351 bool is_propagating_password_changes_to_web_credentials_enabled_; | |
| 301 | 352 |
| 302 bool shutdown_called_; | 353 bool shutdown_called_; |
| 303 | 354 |
| 304 DISALLOW_COPY_AND_ASSIGN(PasswordStore); | 355 DISALLOW_COPY_AND_ASSIGN(PasswordStore); |
| 305 }; | 356 }; |
| 306 | 357 |
| 307 } // namespace password_manager | 358 } // namespace password_manager |
| 308 | 359 |
| 309 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ | 360 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ |
| OLD | NEW |