Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / password_manager / password_store_proxy_mac.h
blob38bf5393e5508bfb14056ed235c8e9f32b4fa366
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_PROXY_MAC_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_PROXY_MAC_H_
8 #include <vector>
10 #include "base/prefs/pref_member.h"
11 #include "base/threading/thread.h"
12 #include "components/password_manager/core/browser/keychain_migration_status_mac.h"
13 #include "components/password_manager/core/browser/password_store.h"
14 #include "components/password_manager/core/common/password_manager_pref_names.h"
16 namespace crypto {
17 class AppleKeychain;
20 namespace password_manager {
21 class LoginDatabase;
24 class PasswordStoreMac;
25 class SimplePasswordStoreMac;
27 // The class is a proxy for either PasswordStoreMac or SimplePasswordStoreMac.
28 // It is responsible for performing migration from PasswordStoreMac to
29 // SimplePasswordStoreMac and instantiating a correct backend according to the
30 // user's state.
31 class PasswordStoreProxyMac : public password_manager::PasswordStore {
32 public:
33 PasswordStoreProxyMac(
34 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
35 scoped_ptr<crypto::AppleKeychain> keychain,
36 scoped_ptr<password_manager::LoginDatabase> login_db,
37 PrefService* prefs);
39 bool Init(const syncer::SyncableService::StartSyncFlare& flare) override;
40 void Shutdown() override;
41 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner()
42 override;
44 #if defined(UNIT_TEST)
45 password_manager::LoginDatabase* login_metadata_db() {
46 return login_metadata_db_.get();
49 scoped_refptr<PasswordStoreMac> password_store_mac() {
50 return password_store_mac_;
52 #endif
54 private:
55 ~PasswordStoreProxyMac() override;
57 password_manager::PasswordStore* GetBackend() const;
59 // Opens LoginDatabase on the background |thread_|.
60 void InitOnBackgroundThread(password_manager::MigrationStatus status);
62 // Writes status to the prefs.
63 void UpdateStatusPref(password_manager::MigrationStatus status);
65 // Executes |pending_ui_tasks_| on the UI thread.
66 void FlushPendingTasks();
68 // PasswordStore:
69 void ReportMetricsImpl(const std::string& sync_username,
70 bool custom_passphrase_sync_enabled) override;
71 password_manager::PasswordStoreChangeList AddLoginImpl(
72 const autofill::PasswordForm& form) override;
73 password_manager::PasswordStoreChangeList UpdateLoginImpl(
74 const autofill::PasswordForm& form) override;
75 password_manager::PasswordStoreChangeList RemoveLoginImpl(
76 const autofill::PasswordForm& form) override;
77 password_manager::PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl(
78 base::Time delete_begin,
79 base::Time delete_end) override;
80 password_manager::PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl(
81 base::Time delete_begin,
82 base::Time delete_end) override;
83 ScopedVector<autofill::PasswordForm> FillMatchingLogins(
84 const autofill::PasswordForm& form,
85 AuthorizationPromptPolicy prompt_policy) override;
86 bool FillAutofillableLogins(
87 ScopedVector<autofill::PasswordForm>* forms) override;
88 bool FillBlacklistLogins(
89 ScopedVector<autofill::PasswordForm>* forms) override;
90 void AddSiteStatsImpl(
91 const password_manager::InteractionsStats& stats) override;
92 void RemoveSiteStatsImpl(const GURL& origin_domain) override;
93 scoped_ptr<password_manager::InteractionsStats> GetSiteStatsImpl(
94 const GURL& origin_domain) override;
96 scoped_refptr<PasswordStoreMac> password_store_mac_;
97 scoped_refptr<SimplePasswordStoreMac> password_store_simple_;
99 // The login metadata SQL database. If opening the DB on |thread_| fails,
100 // |login_metadata_db_| will be reset to NULL for the lifetime of |this|.
101 // The ownership may be transferred to |password_store_simple_|.
102 scoped_ptr<password_manager::LoginDatabase> login_metadata_db_;
104 // Thread that the synchronous methods are run on.
105 scoped_ptr<base::Thread> thread_;
107 // Current migration status for the profile.
108 IntegerPrefMember migration_status_;
110 // List of tasks filled by InitOnBackgroundThread. They can't be just posted
111 // to the UI thread because the message loop can shut down before executing
112 // them. If this is the case then Shutdown() flushes the tasks after stopping
113 // the background thread.
114 // After InitOnBackgroundThread is run once, the queue may not be modified on
115 // the background thread any more.
116 std::vector<base::Closure> pending_ui_tasks_;
118 DISALLOW_COPY_AND_ASSIGN(PasswordStoreProxyMac);
121 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_PROXY_MAC_H_