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_NATIVE_BACKEND_KWALLET_X_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/password_manager/password_store_factory.h"
16 #include "chrome/browser/password_manager/password_store_x.h"
17 #include "chrome/browser/profiles/profile.h"
34 // NativeBackend implementation using KWallet.
35 class NativeBackendKWallet
: public PasswordStoreX::NativeBackend
{
37 explicit NativeBackendKWallet(LocalProfileId id
);
39 ~NativeBackendKWallet() override
;
43 // Implements NativeBackend interface.
44 password_manager::PasswordStoreChangeList
AddLogin(
45 const autofill::PasswordForm
& form
) override
;
46 bool UpdateLogin(const autofill::PasswordForm
& form
,
47 password_manager::PasswordStoreChangeList
* changes
) override
;
48 bool RemoveLogin(const autofill::PasswordForm
& form
,
49 password_manager::PasswordStoreChangeList
* changes
) override
;
50 bool RemoveLoginsCreatedBetween(
51 base::Time delete_begin
,
52 base::Time delete_end
,
53 password_manager::PasswordStoreChangeList
* changes
) override
;
54 bool RemoveLoginsSyncedBetween(
55 base::Time delete_begin
,
56 base::Time delete_end
,
57 password_manager::PasswordStoreChangeList
* changes
) override
;
58 bool GetLogins(const autofill::PasswordForm
& form
,
59 ScopedVector
<autofill::PasswordForm
>* forms
) override
;
60 bool GetAutofillableLogins(
61 ScopedVector
<autofill::PasswordForm
>* forms
) override
;
62 bool GetBlacklistLogins(ScopedVector
<autofill::PasswordForm
>* forms
) override
;
65 // Invalid handle returned by WalletHandle().
66 static const int kInvalidKWalletHandle
= -1;
68 // Internally used by Init(), but also for testing to provide a mock bus.
69 bool InitWithBus(scoped_refptr
<dbus::Bus
> optional_bus
);
71 // Deserializes a list of PasswordForms from the wallet.
72 static ScopedVector
<autofill::PasswordForm
> DeserializeValue(
73 const std::string
& signon_realm
,
74 const base::Pickle
& pickle
);
78 INIT_SUCCESS
, // Init succeeded.
79 TEMPORARY_FAIL
, // Init failed, but might succeed after StartKWalletd().
80 PERMANENT_FAIL
// Init failed, and is not likely to work later either.
83 enum TimestampToCompare
{
88 enum class BlacklistOptions
{ AUTOFILLABLE
, BLACKLISTED
};
92 InitResult
InitWallet();
93 void InitOnDBThread(scoped_refptr
<dbus::Bus
> optional_bus
,
94 base::WaitableEvent
* event
,
97 // Overwrites |forms| with all credentials matching |signon_realm|. Returns
99 bool GetLoginsList(const std::string
& signon_realm
,
101 ScopedVector
<autofill::PasswordForm
>* forms
)
104 // Overwrites |forms| with all credentials matching |options|. Returns true on
106 bool GetLoginsList(BlacklistOptions options
,
108 ScopedVector
<autofill::PasswordForm
>* forms
)
111 // Overwrites |forms| with all stored credentials. Returns true on success.
112 bool GetAllLogins(int wallet_handle
,
113 ScopedVector
<autofill::PasswordForm
>* forms
)
116 // Writes a list of PasswordForms to the wallet with the given signon_realm.
117 // Overwrites any existing list for this signon_realm. Removes the entry if
118 // |forms| is empty. Returns true on success.
119 bool SetLoginsList(const std::vector
<autofill::PasswordForm
*>& forms
,
120 const std::string
& signon_realm
,
123 // Removes password created/synced in the time interval. Returns |true| if the
124 // operation succeeded. |changes| will contain the changes applied.
125 bool RemoveLoginsBetween(base::Time delete_begin
,
126 base::Time delete_end
,
127 TimestampToCompare date_to_compare
,
128 password_manager::PasswordStoreChangeList
* changes
);
130 // Opens the wallet and ensures that the "Chrome Form Data" folder exists.
131 // Returns kInvalidWalletHandle on error.
134 // Generates a profile-specific folder name based on profile_id_.
135 std::string
GetProfileSpecificFolderName() const;
137 // The local profile id, used to generate the folder name.
138 const LocalProfileId profile_id_
;
140 // The KWallet folder name, possibly based on the local profile id.
141 std::string folder_name_
;
143 // DBus handle for communication with klauncher and kwalletd.
144 scoped_refptr
<dbus::Bus
> session_bus_
;
145 // Object proxy for kwalletd. We do not own this.
146 dbus::ObjectProxy
* kwallet_proxy_
;
148 // The name of the wallet we've opened. Set during Init().
149 std::string wallet_name_
;
150 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs.
151 const std::string app_name_
;
153 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet
);
156 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_