Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / password_manager / native_backend_kwallet_x.h
blob3b0524e462e5e5a1eb251a8df14c751865c6c794
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_
8 #include <string>
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"
19 namespace autofill {
20 struct PasswordForm;
23 namespace base {
24 class Pickle;
25 class PickleIterator;
26 class WaitableEvent;
29 namespace dbus {
30 class Bus;
31 class ObjectProxy;
34 // NativeBackend implementation using KWallet.
35 class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
36 public:
37 explicit NativeBackendKWallet(LocalProfileId id);
39 ~NativeBackendKWallet() override;
41 bool Init() 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;
64 protected:
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);
76 private:
77 enum InitResult {
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 {
84 CREATION_TIMESTAMP,
85 SYNC_TIMESTAMP,
88 enum class BlacklistOptions { AUTOFILLABLE, BLACKLISTED };
90 // Initialization.
91 bool StartKWalletd();
92 InitResult InitWallet();
93 void InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus,
94 base::WaitableEvent* event,
95 bool* success);
97 // Overwrites |forms| with all credentials matching |signon_realm|. Returns
98 // true on success.
99 bool GetLoginsList(const std::string& signon_realm,
100 int wallet_handle,
101 ScopedVector<autofill::PasswordForm>* forms)
102 WARN_UNUSED_RESULT;
104 // Overwrites |forms| with all credentials matching |options|. Returns true on
105 // success.
106 bool GetLoginsList(BlacklistOptions options,
107 int wallet_handle,
108 ScopedVector<autofill::PasswordForm>* forms)
109 WARN_UNUSED_RESULT;
111 // Overwrites |forms| with all stored credentials. Returns true on success.
112 bool GetAllLogins(int wallet_handle,
113 ScopedVector<autofill::PasswordForm>* forms)
114 WARN_UNUSED_RESULT;
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,
121 int wallet_handle);
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.
132 int WalletHandle();
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_