Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / password_manager / password_store_x.h
blob96ff38470b011476e44bd907b3231cbe3d9f106e
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_X_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_X_H_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/time/time.h"
13 #include "components/password_manager/core/browser/password_store_default.h"
15 class PrefService;
17 namespace user_prefs {
18 class PrefRegistrySyncable;
21 namespace password_manager {
22 class LoginDatabase;
25 // PasswordStoreX is used on Linux and other non-Windows, non-Mac OS X
26 // operating systems. It uses a "native backend" to actually store the password
27 // data when such a backend is available, and otherwise falls back to using the
28 // login database like PasswordStoreDefault. It also handles automatically
29 // migrating password data to a native backend from the login database.
31 // There are currently native backends for GNOME Keyring and KWallet.
32 class PasswordStoreX : public password_manager::PasswordStoreDefault {
33 public:
34 // NativeBackends more or less implement the PaswordStore interface, but
35 // with return values rather than implicit consumer notification.
36 class NativeBackend {
37 public:
38 virtual ~NativeBackend() {}
40 virtual bool Init() = 0;
42 virtual password_manager::PasswordStoreChangeList AddLogin(
43 const autofill::PasswordForm& form) = 0;
44 virtual bool UpdateLogin(
45 const autofill::PasswordForm& form,
46 password_manager::PasswordStoreChangeList* changes) = 0;
47 virtual bool RemoveLogin(const autofill::PasswordForm& form) = 0;
49 // Removes all logins created/synced from |delete_begin| onwards (inclusive)
50 // and before |delete_end|. You may use a null Time value to do an unbounded
51 // delete in either direction.
52 virtual bool RemoveLoginsCreatedBetween(
53 base::Time delete_begin,
54 base::Time delete_end,
55 password_manager::PasswordStoreChangeList* changes) = 0;
56 virtual bool RemoveLoginsSyncedBetween(
57 base::Time delete_begin,
58 base::Time delete_end,
59 password_manager::PasswordStoreChangeList* changes) = 0;
61 // The three methods below overwrite |forms| with all stored credentials
62 // matching |form|, all stored non-blacklisted credentials, and all stored
63 // blacklisted credentials, respectively. On success, they return true.
64 virtual bool GetLogins(const autofill::PasswordForm& form,
65 ScopedVector<autofill::PasswordForm>* forms)
66 WARN_UNUSED_RESULT = 0;
67 virtual bool GetAutofillableLogins(
68 ScopedVector<autofill::PasswordForm>* forms) WARN_UNUSED_RESULT = 0;
69 virtual bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms)
70 WARN_UNUSED_RESULT = 0;
73 // Takes ownership of |login_db| and |backend|. |backend| may be NULL in which
74 // case this PasswordStoreX will act the same as PasswordStoreDefault.
75 PasswordStoreX(scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
76 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner,
77 scoped_ptr<password_manager::LoginDatabase> login_db,
78 NativeBackend* backend);
80 private:
81 friend class PasswordStoreXTest;
83 ~PasswordStoreX() override;
85 // Implements PasswordStore interface.
86 password_manager::PasswordStoreChangeList AddLoginImpl(
87 const autofill::PasswordForm& form) override;
88 password_manager::PasswordStoreChangeList UpdateLoginImpl(
89 const autofill::PasswordForm& form) override;
90 password_manager::PasswordStoreChangeList RemoveLoginImpl(
91 const autofill::PasswordForm& form) override;
92 password_manager::PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl(
93 base::Time delete_begin,
94 base::Time delete_end) override;
95 password_manager::PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl(
96 base::Time delete_begin,
97 base::Time delete_end) override;
98 ScopedVector<autofill::PasswordForm> FillMatchingLogins(
99 const autofill::PasswordForm& form,
100 AuthorizationPromptPolicy prompt_policy) override;
101 bool FillAutofillableLogins(
102 ScopedVector<autofill::PasswordForm>* forms) override;
103 bool FillBlacklistLogins(
104 ScopedVector<autofill::PasswordForm>* forms) override;
106 // Check to see whether migration is necessary, and perform it if so.
107 void CheckMigration();
109 // Return true if we should try using the native backend.
110 bool use_native_backend() { return !!backend_.get(); }
112 // Return true if we can fall back on the default store, warning the first
113 // time we call it when falling back is necessary. See |allow_fallback_|.
114 bool allow_default_store();
116 // Synchronously migrates all the passwords stored in the login database to
117 // the native backend. If successful, the login database will be left with no
118 // stored passwords, and the number of passwords migrated will be returned.
119 // (This might be 0 if migration was not necessary.) Returns < 0 on failure.
120 ssize_t MigrateLogins();
122 // The native backend in use, or NULL if none.
123 scoped_ptr<NativeBackend> backend_;
124 // Whether we have already attempted migration to the native store.
125 bool migration_checked_;
126 // Whether we should allow falling back to the default store. If there is
127 // nothing to migrate, then the first attempt to use the native store will
128 // be the first time we try to use it and we should allow falling back. If
129 // we have migrated successfully, then we do not allow falling back.
130 bool allow_fallback_;
132 DISALLOW_COPY_AND_ASSIGN(PasswordStoreX);
135 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_X_H_