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
) override
;
49 bool RemoveLoginsCreatedBetween(
50 base::Time delete_begin
,
51 base::Time delete_end
,
52 password_manager::PasswordStoreChangeList
* changes
) override
;
53 bool RemoveLoginsSyncedBetween(
54 base::Time delete_begin
,
55 base::Time delete_end
,
56 password_manager::PasswordStoreChangeList
* changes
) override
;
57 bool GetLogins(const autofill::PasswordForm
& form
,
58 ScopedVector
<autofill::PasswordForm
>* forms
) override
;
59 bool GetAutofillableLogins(
60 ScopedVector
<autofill::PasswordForm
>* forms
) override
;
61 bool GetBlacklistLogins(ScopedVector
<autofill::PasswordForm
>* forms
) override
;
64 // Invalid handle returned by WalletHandle().
65 static const int kInvalidKWalletHandle
= -1;
67 // Internally used by Init(), but also for testing to provide a mock bus.
68 bool InitWithBus(scoped_refptr
<dbus::Bus
> optional_bus
);
70 // Deserializes a list of PasswordForms from the wallet.
71 static ScopedVector
<autofill::PasswordForm
> DeserializeValue(
72 const std::string
& signon_realm
,
73 const base::Pickle
& pickle
);
77 INIT_SUCCESS
, // Init succeeded.
78 TEMPORARY_FAIL
, // Init failed, but might succeed after StartKWalletd().
79 PERMANENT_FAIL
// Init failed, and is not likely to work later either.
82 enum TimestampToCompare
{
87 enum class BlacklistOptions
{ AUTOFILLABLE
, BLACKLISTED
};
91 InitResult
InitWallet();
92 void InitOnDBThread(scoped_refptr
<dbus::Bus
> optional_bus
,
93 base::WaitableEvent
* event
,
96 // Overwrites |forms| with all credentials matching |signon_realm|. Returns
98 bool GetLoginsList(const std::string
& signon_realm
,
100 ScopedVector
<autofill::PasswordForm
>* forms
)
103 // Overwrites |forms| with all credentials matching |options|. Returns true on
105 bool GetLoginsList(BlacklistOptions options
,
107 ScopedVector
<autofill::PasswordForm
>* forms
)
110 // Overwrites |forms| with all stored credentials. Returns true on success.
111 bool GetAllLogins(int wallet_handle
,
112 ScopedVector
<autofill::PasswordForm
>* forms
)
115 // Writes a list of PasswordForms to the wallet with the given signon_realm.
116 // Overwrites any existing list for this signon_realm. Removes the entry if
117 // |forms| is empty. Returns true on success.
118 bool SetLoginsList(const std::vector
<autofill::PasswordForm
*>& forms
,
119 const std::string
& signon_realm
,
122 // Removes password created/synced in the time interval. Returns |true| if the
123 // operation succeeded. |changes| will contain the changes applied.
124 bool RemoveLoginsBetween(base::Time delete_begin
,
125 base::Time delete_end
,
126 TimestampToCompare date_to_compare
,
127 password_manager::PasswordStoreChangeList
* changes
);
129 // Opens the wallet and ensures that the "Chrome Form Data" folder exists.
130 // Returns kInvalidWalletHandle on error.
133 // Generates a profile-specific folder name based on profile_id_.
134 std::string
GetProfileSpecificFolderName() const;
136 // The local profile id, used to generate the folder name.
137 const LocalProfileId profile_id_
;
139 // The KWallet folder name, possibly based on the local profile id.
140 std::string folder_name_
;
142 // DBus handle for communication with klauncher and kwalletd.
143 scoped_refptr
<dbus::Bus
> session_bus_
;
144 // Object proxy for kwalletd. We do not own this.
145 dbus::ObjectProxy
* kwallet_proxy_
;
147 // The name of the wallet we've opened. Set during Init().
148 std::string wallet_name_
;
149 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs.
150 const std::string app_name_
;
152 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet
);
155 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_