OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "chrome/browser/password_manager/password_store_factory.h" | 15 #include "chrome/browser/password_manager/password_store_factory.h" |
15 #include "chrome/browser/password_manager/password_store_x.h" | 16 #include "chrome/browser/password_manager/password_store_x.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 | 18 |
18 class Pickle; | 19 class Pickle; |
19 class PickleIterator; | 20 class PickleIterator; |
20 | 21 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override; | 62 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override; |
62 | 63 |
63 protected: | 64 protected: |
64 // Invalid handle returned by WalletHandle(). | 65 // Invalid handle returned by WalletHandle(). |
65 static const int kInvalidKWalletHandle = -1; | 66 static const int kInvalidKWalletHandle = -1; |
66 | 67 |
67 // Internally used by Init(), but also for testing to provide a mock bus. | 68 // Internally used by Init(), but also for testing to provide a mock bus. |
68 bool InitWithBus(scoped_refptr<dbus::Bus> optional_bus); | 69 bool InitWithBus(scoped_refptr<dbus::Bus> optional_bus); |
69 | 70 |
70 // Deserializes a list of PasswordForms from the wallet. | 71 // Deserializes a list of PasswordForms from the wallet. |
71 static void DeserializeValue(const std::string& signon_realm, | 72 static ScopedVector<autofill::PasswordForm> DeserializeValue( |
72 const Pickle& pickle, | 73 const std::string& signon_realm, |
73 ScopedVector<autofill::PasswordForm>* forms); | 74 const Pickle& pickle); |
74 | 75 |
75 private: | 76 private: |
76 enum InitResult { | 77 enum InitResult { |
77 INIT_SUCCESS, // Init succeeded. | 78 INIT_SUCCESS, // Init succeeded. |
78 TEMPORARY_FAIL, // Init failed, but might succeed after StartKWalletd(). | 79 TEMPORARY_FAIL, // Init failed, but might succeed after StartKWalletd(). |
79 PERMANENT_FAIL // Init failed, and is not likely to work later either. | 80 PERMANENT_FAIL // Init failed, and is not likely to work later either. |
80 }; | 81 }; |
81 | 82 |
82 enum TimestampToCompare { | 83 enum TimestampToCompare { |
83 CREATION_TIMESTAMP, | 84 CREATION_TIMESTAMP, |
84 SYNC_TIMESTAMP, | 85 SYNC_TIMESTAMP, |
85 }; | 86 }; |
86 | 87 |
| 88 enum class BlacklistOptions { AUTOFILLABLE, BLACKLISTED }; |
| 89 |
87 // Initialization. | 90 // Initialization. |
88 bool StartKWalletd(); | 91 bool StartKWalletd(); |
89 InitResult InitWallet(); | 92 InitResult InitWallet(); |
90 void InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus, | 93 void InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus, |
91 base::WaitableEvent* event, | 94 base::WaitableEvent* event, |
92 bool* success); | 95 bool* success); |
93 | 96 |
94 // Reads PasswordForms from the wallet that match the given signon_realm. | 97 // Overwrites |forms| with all credentials matching |signon_realm|. Returns |
| 98 // true on success. |
95 bool GetLoginsList(const std::string& signon_realm, | 99 bool GetLoginsList(const std::string& signon_realm, |
96 int wallet_handle, | 100 int wallet_handle, |
97 ScopedVector<autofill::PasswordForm>* forms); | 101 ScopedVector<autofill::PasswordForm>* forms) |
| 102 WARN_UNUSED_RESULT; |
98 | 103 |
99 // Reads PasswordForms from the wallet with the given autofillability state. | 104 // Overwrites |forms| with all credentials matching |options|. Returns true on |
100 bool GetLoginsList(bool autofillable, | 105 // success. |
| 106 bool GetLoginsList(BlacklistOptions options, |
101 int wallet_handle, | 107 int wallet_handle, |
102 ScopedVector<autofill::PasswordForm>* forms); | 108 ScopedVector<autofill::PasswordForm>* forms) |
| 109 WARN_UNUSED_RESULT; |
103 | 110 |
104 // Helper for some of the above GetLoginsList() methods. | 111 // Overwrites |forms| with all stored credentials. Returns true on success. |
105 bool GetAllLogins(int wallet_handle, | 112 bool GetAllLogins(int wallet_handle, |
106 ScopedVector<autofill::PasswordForm>* forms); | 113 ScopedVector<autofill::PasswordForm>* forms) |
| 114 WARN_UNUSED_RESULT; |
107 | 115 |
108 // Writes a list of PasswordForms to the wallet with the given signon_realm. | 116 // Writes a list of PasswordForms to the wallet with the given signon_realm. |
109 // Overwrites any existing list for this signon_realm. Removes the entry if | 117 // Overwrites any existing list for this signon_realm. Removes the entry if |
110 // |forms| is empty. Returns true on success. | 118 // |forms| is empty. Returns true on success. |
111 bool SetLoginsList(const std::vector<autofill::PasswordForm*>& forms, | 119 bool SetLoginsList(const std::vector<autofill::PasswordForm*>& forms, |
112 const std::string& signon_realm, | 120 const std::string& signon_realm, |
113 int wallet_handle); | 121 int wallet_handle); |
114 | 122 |
115 // Removes password created/synced in the time interval. Returns |true| if the | 123 // Removes password created/synced in the time interval. Returns |true| if the |
116 // operation succeeded. |changes| will contain the changes applied. | 124 // operation succeeded. |changes| will contain the changes applied. |
117 bool RemoveLoginsBetween(base::Time delete_begin, | 125 bool RemoveLoginsBetween(base::Time delete_begin, |
118 base::Time delete_end, | 126 base::Time delete_end, |
119 TimestampToCompare date_to_compare, | 127 TimestampToCompare date_to_compare, |
120 password_manager::PasswordStoreChangeList* changes); | 128 password_manager::PasswordStoreChangeList* changes); |
121 | 129 |
122 // Opens the wallet and ensures that the "Chrome Form Data" folder exists. | 130 // Opens the wallet and ensures that the "Chrome Form Data" folder exists. |
123 // Returns kInvalidWalletHandle on error. | 131 // Returns kInvalidWalletHandle on error. |
124 int WalletHandle(); | 132 int WalletHandle(); |
125 | 133 |
126 // Serializes a list of PasswordForms to be stored in the wallet. | |
127 static void SerializeValue(const std::vector<autofill::PasswordForm*>& forms, | |
128 Pickle* pickle); | |
129 | |
130 // Deserializes a list of PasswordForms from the wallet. | |
131 // |size_32| controls reading the size field within the pickle as 32 bits. | |
132 // We used to use Pickle::WriteSize() to write the number of password forms, | |
133 // but that has a different size on 32- and 64-bit systems. So, now we always | |
134 // write a 64-bit quantity, but we support trying to read it as either size | |
135 // when reading old pickles that fail to deserialize using the native size. | |
136 static bool DeserializeValueSize(const std::string& signon_realm, | |
137 const PickleIterator& iter, | |
138 int version, | |
139 bool size_32, | |
140 bool warn_only, | |
141 ScopedVector<autofill::PasswordForm>* forms); | |
142 | |
143 // In case the fields in the pickle ever change, version them so we can try to | |
144 // read old pickles. (Note: do not eat old pickles past the expiration date.) | |
145 static const int kPickleVersion = 6; | |
146 | |
147 // Generates a profile-specific folder name based on profile_id_. | 134 // Generates a profile-specific folder name based on profile_id_. |
148 std::string GetProfileSpecificFolderName() const; | 135 std::string GetProfileSpecificFolderName() const; |
149 | 136 |
150 // The local profile id, used to generate the folder name. | 137 // The local profile id, used to generate the folder name. |
151 const LocalProfileId profile_id_; | 138 const LocalProfileId profile_id_; |
152 | 139 |
153 // The KWallet folder name, possibly based on the local profile id. | 140 // The KWallet folder name, possibly based on the local profile id. |
154 std::string folder_name_; | 141 std::string folder_name_; |
155 | 142 |
156 // DBus handle for communication with klauncher and kwalletd. | 143 // DBus handle for communication with klauncher and kwalletd. |
157 scoped_refptr<dbus::Bus> session_bus_; | 144 scoped_refptr<dbus::Bus> session_bus_; |
158 // Object proxy for kwalletd. We do not own this. | 145 // Object proxy for kwalletd. We do not own this. |
159 dbus::ObjectProxy* kwallet_proxy_; | 146 dbus::ObjectProxy* kwallet_proxy_; |
160 | 147 |
161 // The name of the wallet we've opened. Set during Init(). | 148 // The name of the wallet we've opened. Set during Init(). |
162 std::string wallet_name_; | 149 std::string wallet_name_; |
163 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs. | 150 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs. |
164 const std::string app_name_; | 151 const std::string app_name_; |
165 | 152 |
166 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet); | 153 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet); |
167 }; | 154 }; |
168 | 155 |
169 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ | 156 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ |
OLD | NEW |