| 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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 ScopedVector<autofill::PasswordForm>* forms) override; | 60 ScopedVector<autofill::PasswordForm>* forms) override; |
| 61 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override; | 61 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override; |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 // Invalid handle returned by WalletHandle(). | 64 // Invalid handle returned by WalletHandle(). |
| 65 static const int kInvalidKWalletHandle = -1; | 65 static const int kInvalidKWalletHandle = -1; |
| 66 | 66 |
| 67 // Internally used by Init(), but also for testing to provide a mock bus. | 67 // Internally used by Init(), but also for testing to provide a mock bus. |
| 68 bool InitWithBus(scoped_refptr<dbus::Bus> optional_bus); | 68 bool InitWithBus(scoped_refptr<dbus::Bus> optional_bus); |
| 69 | 69 |
| 70 // Deserializes a list of PasswordForms from the wallet. | 70 // Deserializes a list of PasswordForms from the wallet. Protected for tests. |
| 71 static void DeserializeValue(const std::string& signon_realm, | 71 static ScopedVector<autofill::PasswordForm> DeserializeValue( |
| 72 const Pickle& pickle, | 72 const std::string& signon_realm, |
| 73 ScopedVector<autofill::PasswordForm>* forms); | 73 const Pickle& pickle); |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 enum InitResult { | 76 enum InitResult { |
| 77 INIT_SUCCESS, // Init succeeded. | 77 INIT_SUCCESS, // Init succeeded. |
| 78 TEMPORARY_FAIL, // Init failed, but might succeed after StartKWalletd(). | 78 TEMPORARY_FAIL, // Init failed, but might succeed after StartKWalletd(). |
| 79 PERMANENT_FAIL // Init failed, and is not likely to work later either. | 79 PERMANENT_FAIL // Init failed, and is not likely to work later either. |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 enum TimestampToCompare { | 82 enum TimestampToCompare { |
| 83 CREATION_TIMESTAMP, | 83 CREATION_TIMESTAMP, |
| 84 SYNC_TIMESTAMP, | 84 SYNC_TIMESTAMP, |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 enum class BlacklistOptions { AUTOFILLABLE, BLACKLISTED }; |
| 88 |
| 87 // Initialization. | 89 // Initialization. |
| 88 bool StartKWalletd(); | 90 bool StartKWalletd(); |
| 89 InitResult InitWallet(); | 91 InitResult InitWallet(); |
| 90 void InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus, | 92 void InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus, |
| 91 base::WaitableEvent* event, | 93 base::WaitableEvent* event, |
| 92 bool* success); | 94 bool* success); |
| 93 | 95 |
| 94 // Reads PasswordForms from the wallet that match the given signon_realm. | 96 // Overwrites |forms| with all credentials matching |signon_realm|. On success |
| 97 // returns true, on failure returns false and erases |forms|. |
| 95 bool GetLoginsList(const std::string& signon_realm, | 98 bool GetLoginsList(const std::string& signon_realm, |
| 96 int wallet_handle, | 99 int wallet_handle, |
| 97 ScopedVector<autofill::PasswordForm>* forms); | 100 ScopedVector<autofill::PasswordForm>* forms); |
| 98 | 101 |
| 99 // Reads PasswordForms from the wallet with the given autofillability state. | 102 // Overwrites |forms| with all credentials matching |options|. On success |
| 100 bool GetLoginsList(bool autofillable, | 103 // returns true, on failure returns false and erases |forms|. |
| 104 bool GetLoginsList(BlacklistOptions options, |
| 101 int wallet_handle, | 105 int wallet_handle, |
| 102 ScopedVector<autofill::PasswordForm>* forms); | 106 ScopedVector<autofill::PasswordForm>* forms); |
| 103 | 107 |
| 104 // Helper for some of the above GetLoginsList() methods. | 108 // Overwrites |forms| with all stored credentials. On success returns true, on |
| 109 // failure returns false and erases |forms|. |
| 105 bool GetAllLogins(int wallet_handle, | 110 bool GetAllLogins(int wallet_handle, |
| 106 ScopedVector<autofill::PasswordForm>* forms); | 111 ScopedVector<autofill::PasswordForm>* forms); |
| 107 | 112 |
| 108 // Writes a list of PasswordForms to the wallet with the given signon_realm. | 113 // 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 | 114 // Overwrites any existing list for this signon_realm. Removes the entry if |
| 110 // |forms| is empty. Returns true on success. | 115 // |forms| is empty. Returns true on success. |
| 111 bool SetLoginsList(const std::vector<autofill::PasswordForm*>& forms, | 116 bool SetLoginsList(const std::vector<autofill::PasswordForm*>& forms, |
| 112 const std::string& signon_realm, | 117 const std::string& signon_realm, |
| 113 int wallet_handle); | 118 int wallet_handle); |
| 114 | 119 |
| 115 // Removes password created/synced in the time interval. Returns |true| if the | 120 // Removes password created/synced in the time interval. Returns |true| if the |
| 116 // operation succeeded. |changes| will contain the changes applied. | 121 // operation succeeded. |changes| will contain the changes applied. |
| 117 bool RemoveLoginsBetween(base::Time delete_begin, | 122 bool RemoveLoginsBetween(base::Time delete_begin, |
| 118 base::Time delete_end, | 123 base::Time delete_end, |
| 119 TimestampToCompare date_to_compare, | 124 TimestampToCompare date_to_compare, |
| 120 password_manager::PasswordStoreChangeList* changes); | 125 password_manager::PasswordStoreChangeList* changes); |
| 121 | 126 |
| 122 // Opens the wallet and ensures that the "Chrome Form Data" folder exists. | 127 // Opens the wallet and ensures that the "Chrome Form Data" folder exists. |
| 123 // Returns kInvalidWalletHandle on error. | 128 // Returns kInvalidWalletHandle on error. |
| 124 int WalletHandle(); | 129 int WalletHandle(); |
| 125 | 130 |
| 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 = 5; | |
| 146 | |
| 147 // Generates a profile-specific folder name based on profile_id_. | 131 // Generates a profile-specific folder name based on profile_id_. |
| 148 std::string GetProfileSpecificFolderName() const; | 132 std::string GetProfileSpecificFolderName() const; |
| 149 | 133 |
| 150 // The local profile id, used to generate the folder name. | 134 // The local profile id, used to generate the folder name. |
| 151 const LocalProfileId profile_id_; | 135 const LocalProfileId profile_id_; |
| 152 | 136 |
| 153 // The KWallet folder name, possibly based on the local profile id. | 137 // The KWallet folder name, possibly based on the local profile id. |
| 154 std::string folder_name_; | 138 std::string folder_name_; |
| 155 | 139 |
| 156 // DBus handle for communication with klauncher and kwalletd. | 140 // DBus handle for communication with klauncher and kwalletd. |
| 157 scoped_refptr<dbus::Bus> session_bus_; | 141 scoped_refptr<dbus::Bus> session_bus_; |
| 158 // Object proxy for kwalletd. We do not own this. | 142 // Object proxy for kwalletd. We do not own this. |
| 159 dbus::ObjectProxy* kwallet_proxy_; | 143 dbus::ObjectProxy* kwallet_proxy_; |
| 160 | 144 |
| 161 // The name of the wallet we've opened. Set during Init(). | 145 // The name of the wallet we've opened. Set during Init(). |
| 162 std::string wallet_name_; | 146 std::string wallet_name_; |
| 163 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs. | 147 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs. |
| 164 const std::string app_name_; | 148 const std::string app_name_; |
| 165 | 149 |
| 166 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet); | 150 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet); |
| 167 }; | 151 }; |
| 168 | 152 |
| 169 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ | 153 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ |
| OLD | NEW |