OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_PROXY_MAC_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_PROXY_MAC_H_ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_PROXY_MAC_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_PROXY_MAC_H_ |
7 | 7 |
| 8 #include "base/prefs/pref_member.h" |
| 9 #include "base/synchronization/waitable_event.h" |
8 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
9 #include "components/password_manager/core/browser/password_store.h" | 11 #include "components/password_manager/core/browser/password_store.h" |
10 | 12 |
11 namespace crypto { | 13 namespace crypto { |
12 class AppleKeychain; | 14 class AppleKeychain; |
13 } | 15 } |
14 | 16 |
15 namespace password_manager { | 17 namespace password_manager { |
16 class LoginDatabase; | 18 class LoginDatabase; |
17 } | 19 } |
18 | 20 |
19 class PasswordStoreMac; | 21 class PasswordStoreMac; |
20 class SimplePasswordStoreMac; | 22 class SimplePasswordStoreMac; |
21 | 23 |
22 // The class is a proxy for either PasswordStoreMac or SimplePasswordStoreMac. | 24 // The class is a proxy for either PasswordStoreMac or SimplePasswordStoreMac. |
23 // It is responsible for performing migration from PasswordStoreMac to | 25 // It is responsible for performing migration from PasswordStoreMac to |
24 // SimplePasswordStoreMac and instantiating a correct backend according to the | 26 // SimplePasswordStoreMac and instantiating a correct backend according to the |
25 // user's state. | 27 // user's state. |
26 class PasswordStoreProxyMac : public password_manager::PasswordStore { | 28 class PasswordStoreProxyMac : public password_manager::PasswordStore { |
27 public: | 29 public: |
| 30 enum MigrationStatus { |
| 31 // Migration wasn't tried yet. |
| 32 NOT_STARTED = 0, |
| 33 |
| 34 // Migration finished successfully. |
| 35 MIGRATED, |
| 36 |
| 37 // Migration failed once. It should be tried again. |
| 38 FAILED_ONCE, |
| 39 |
| 40 // Migration failed twice. It should not be tried again. |
| 41 FAILED_TWICE, |
| 42 |
| 43 NUM_MIGRATION_STATUS, |
| 44 }; |
| 45 |
28 PasswordStoreProxyMac( | 46 PasswordStoreProxyMac( |
29 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 47 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
30 scoped_ptr<crypto::AppleKeychain> keychain, | 48 scoped_ptr<crypto::AppleKeychain> keychain, |
31 scoped_ptr<password_manager::LoginDatabase> login_db); | 49 scoped_ptr<password_manager::LoginDatabase> login_db, |
| 50 PrefService* prefs); |
32 | 51 |
33 bool Init(const syncer::SyncableService::StartSyncFlare& flare) override; | 52 bool Init(const syncer::SyncableService::StartSyncFlare& flare) override; |
34 void Shutdown() override; | 53 void Shutdown() override; |
35 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() | 54 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() |
36 override; | 55 override; |
37 | 56 |
38 #if defined(UNIT_TEST) | 57 #if defined(UNIT_TEST) |
39 password_manager::LoginDatabase* login_metadata_db() { | 58 password_manager::LoginDatabase* login_metadata_db() { |
40 return login_metadata_db_.get(); | 59 return login_metadata_db_.get(); |
41 } | 60 } |
42 #endif | 61 #endif |
43 | 62 |
44 private: | 63 private: |
45 ~PasswordStoreProxyMac() override; | 64 ~PasswordStoreProxyMac() override; |
46 | 65 |
47 password_manager::PasswordStore* GetBackend() const; | 66 password_manager::PasswordStore* GetBackend() const; |
48 | 67 |
49 // Opens LoginDatabase on the background |thread_|. | 68 // Opens LoginDatabase on the background |thread_|. |
50 void InitOnBackgroundThread(); | 69 void InitOnBackgroundThread(MigrationStatus status); |
| 70 |
| 71 // Writes status to the prefs. |
| 72 void UpdateStatusPref(MigrationStatus status); |
| 73 |
| 74 // Reports |status| via UMA. |
| 75 static void ReportStatusPref(MigrationStatus status); |
51 | 76 |
52 // PasswordStore: | 77 // PasswordStore: |
53 void ReportMetricsImpl(const std::string& sync_username, | 78 void ReportMetricsImpl(const std::string& sync_username, |
54 bool custom_passphrase_sync_enabled) override; | 79 bool custom_passphrase_sync_enabled) override; |
55 password_manager::PasswordStoreChangeList AddLoginImpl( | 80 password_manager::PasswordStoreChangeList AddLoginImpl( |
56 const autofill::PasswordForm& form) override; | 81 const autofill::PasswordForm& form) override; |
57 password_manager::PasswordStoreChangeList UpdateLoginImpl( | 82 password_manager::PasswordStoreChangeList UpdateLoginImpl( |
58 const autofill::PasswordForm& form) override; | 83 const autofill::PasswordForm& form) override; |
59 password_manager::PasswordStoreChangeList RemoveLoginImpl( | 84 password_manager::PasswordStoreChangeList RemoveLoginImpl( |
60 const autofill::PasswordForm& form) override; | 85 const autofill::PasswordForm& form) override; |
(...skipping 19 matching lines...) Expand all Loading... |
80 scoped_refptr<PasswordStoreMac> password_store_mac_; | 105 scoped_refptr<PasswordStoreMac> password_store_mac_; |
81 scoped_refptr<SimplePasswordStoreMac> password_store_simple_; | 106 scoped_refptr<SimplePasswordStoreMac> password_store_simple_; |
82 | 107 |
83 // The login metadata SQL database. If opening the DB on |thread_| fails, | 108 // The login metadata SQL database. If opening the DB on |thread_| fails, |
84 // |login_metadata_db_| will be reset to NULL for the lifetime of |this|. | 109 // |login_metadata_db_| will be reset to NULL for the lifetime of |this|. |
85 scoped_ptr<password_manager::LoginDatabase> login_metadata_db_; | 110 scoped_ptr<password_manager::LoginDatabase> login_metadata_db_; |
86 | 111 |
87 // Thread that the synchronous methods are run on. | 112 // Thread that the synchronous methods are run on. |
88 scoped_ptr<base::Thread> thread_; | 113 scoped_ptr<base::Thread> thread_; |
89 | 114 |
| 115 // Current migration status for the profile. |
| 116 IntegerPrefMember migration_status_; |
| 117 |
| 118 // Signals the main thread that the migration is finished or won't be done. |
| 119 base::WaitableEvent migration_completion_; |
| 120 |
90 DISALLOW_COPY_AND_ASSIGN(PasswordStoreProxyMac); | 121 DISALLOW_COPY_AND_ASSIGN(PasswordStoreProxyMac); |
91 }; | 122 }; |
92 | 123 |
93 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_PROXY_MAC_H_ | 124 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_PROXY_MAC_H_ |
OLD | NEW |