Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / password_manager / native_backend_kwallet_x.h
blobe4e0b1bbce7f10781c680586db4e4de757d3da7e
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) 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;
63 protected:
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);
75 private:
76 enum InitResult {
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 {
83 CREATION_TIMESTAMP,
84 SYNC_TIMESTAMP,
87 enum class BlacklistOptions { AUTOFILLABLE, BLACKLISTED };
89 // Initialization.
90 bool StartKWalletd();
91 InitResult InitWallet();
92 void InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus,
93 base::WaitableEvent* event,
94 bool* success);
96 // Overwrites |forms| with all credentials matching |signon_realm|. Returns
97 // true on success.
98 bool GetLoginsList(const std::string& signon_realm,
99 int wallet_handle,
100 ScopedVector<autofill::PasswordForm>* forms)
101 WARN_UNUSED_RESULT;
103 // Overwrites |forms| with all credentials matching |options|. Returns true on
104 // success.
105 bool GetLoginsList(BlacklistOptions options,
106 int wallet_handle,
107 ScopedVector<autofill::PasswordForm>* forms)
108 WARN_UNUSED_RESULT;
110 // Overwrites |forms| with all stored credentials. Returns true on success.
111 bool GetAllLogins(int wallet_handle,
112 ScopedVector<autofill::PasswordForm>* forms)
113 WARN_UNUSED_RESULT;
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,
120 int wallet_handle);
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.
131 int WalletHandle();
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_