Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: chrome/browser/password_manager/native_backend_kwallet_x.h

Issue 825773003: PasswordStore: Use ScopedVector to express ownership of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use assignment instead of construction Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "chrome/browser/password_manager/password_store_factory.h" 14 #include "chrome/browser/password_manager/password_store_factory.h"
14 #include "chrome/browser/password_manager/password_store_x.h" 15 #include "chrome/browser/password_manager/password_store_x.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 17
17 class Pickle; 18 class Pickle;
18 class PickleIterator; 19 class PickleIterator;
19 20
20 namespace autofill { 21 namespace autofill {
21 struct PasswordForm; 22 struct PasswordForm;
(...skipping 25 matching lines...) Expand all
47 bool RemoveLogin(const autofill::PasswordForm& form) override; 48 bool RemoveLogin(const autofill::PasswordForm& form) override;
48 bool RemoveLoginsCreatedBetween( 49 bool RemoveLoginsCreatedBetween(
49 base::Time delete_begin, 50 base::Time delete_begin,
50 base::Time delete_end, 51 base::Time delete_end,
51 password_manager::PasswordStoreChangeList* changes) override; 52 password_manager::PasswordStoreChangeList* changes) override;
52 bool RemoveLoginsSyncedBetween( 53 bool RemoveLoginsSyncedBetween(
53 base::Time delete_begin, 54 base::Time delete_begin,
54 base::Time delete_end, 55 base::Time delete_end,
55 password_manager::PasswordStoreChangeList* changes) override; 56 password_manager::PasswordStoreChangeList* changes) override;
56 bool GetLogins(const autofill::PasswordForm& form, 57 bool GetLogins(const autofill::PasswordForm& form,
57 PasswordFormList* forms) override; 58 ScopedVector<autofill::PasswordForm>* forms) override;
58 bool GetAutofillableLogins(PasswordFormList* forms) override; 59 bool GetAutofillableLogins(
59 bool GetBlacklistLogins(PasswordFormList* forms) override; 60 ScopedVector<autofill::PasswordForm>* forms) override;
61 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override;
60 62
61 protected: 63 protected:
62 // Invalid handle returned by WalletHandle(). 64 // Invalid handle returned by WalletHandle().
63 static const int kInvalidKWalletHandle = -1; 65 static const int kInvalidKWalletHandle = -1;
64 66
65 // 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.
66 bool InitWithBus(scoped_refptr<dbus::Bus> optional_bus); 68 bool InitWithBus(scoped_refptr<dbus::Bus> optional_bus);
67 69
68 // Deserializes a list of PasswordForms from the wallet. 70 // Deserializes a list of PasswordForms from the wallet.
69 static void DeserializeValue(const std::string& signon_realm, 71 static void DeserializeValue(const std::string& signon_realm,
70 const Pickle& pickle, 72 const Pickle& pickle,
71 PasswordFormList* forms); 73 ScopedVector<autofill::PasswordForm>* forms);
72 74
73 private: 75 private:
74 enum InitResult { 76 enum InitResult {
75 INIT_SUCCESS, // Init succeeded. 77 INIT_SUCCESS, // Init succeeded.
76 TEMPORARY_FAIL, // Init failed, but might succeed after StartKWalletd(). 78 TEMPORARY_FAIL, // Init failed, but might succeed after StartKWalletd().
77 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.
78 }; 80 };
79 81
80 enum TimestampToCompare { 82 enum TimestampToCompare {
81 CREATION_TIMESTAMP, 83 CREATION_TIMESTAMP,
82 SYNC_TIMESTAMP, 84 SYNC_TIMESTAMP,
83 }; 85 };
84 86
85 // Initialization. 87 // Initialization.
86 bool StartKWalletd(); 88 bool StartKWalletd();
87 InitResult InitWallet(); 89 InitResult InitWallet();
88 void InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus, 90 void InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus,
89 base::WaitableEvent* event, 91 base::WaitableEvent* event,
90 bool* success); 92 bool* success);
91 93
92 // Reads PasswordForms from the wallet that match the given signon_realm. 94 // Reads PasswordForms from the wallet that match the given signon_realm.
93 bool GetLoginsList(PasswordFormList* forms, 95 bool GetLoginsList(const std::string& signon_realm,
94 const std::string& signon_realm, 96 int wallet_handle,
95 int wallet_handle); 97 ScopedVector<autofill::PasswordForm>* forms);
96 98
97 // Reads PasswordForms from the wallet with the given autofillability state. 99 // Reads PasswordForms from the wallet with the given autofillability state.
98 bool GetLoginsList(PasswordFormList* forms, 100 bool GetLoginsList(bool autofillable,
99 bool autofillable, 101 int wallet_handle,
100 int wallet_handle); 102 ScopedVector<autofill::PasswordForm>* forms);
101 103
102 // Helper for some of the above GetLoginsList() methods. 104 // Helper for some of the above GetLoginsList() methods.
103 bool GetAllLogins(PasswordFormList* forms, int wallet_handle); 105 bool GetAllLogins(int wallet_handle,
106 ScopedVector<autofill::PasswordForm>* forms);
104 107
105 // Writes a list of PasswordForms to the wallet with the given signon_realm. 108 // Writes a list of PasswordForms to the wallet with the given signon_realm.
106 // Overwrites any existing list for this signon_realm. Removes the entry if 109 // Overwrites any existing list for this signon_realm. Removes the entry if
107 // |forms| is empty. Returns true on success. 110 // |forms| is empty. Returns true on success.
108 bool SetLoginsList(const PasswordFormList& forms, 111 bool SetLoginsList(const std::vector<autofill::PasswordForm*>& forms,
109 const std::string& signon_realm, 112 const std::string& signon_realm,
110 int wallet_handle); 113 int wallet_handle);
111 114
112 // Removes password created/synced in the time interval. Returns |true| if the 115 // Removes password created/synced in the time interval. Returns |true| if the
113 // operation succeeded. |changes| will contain the changes applied. 116 // operation succeeded. |changes| will contain the changes applied.
114 bool RemoveLoginsBetween(base::Time delete_begin, 117 bool RemoveLoginsBetween(base::Time delete_begin,
115 base::Time delete_end, 118 base::Time delete_end,
116 TimestampToCompare date_to_compare, 119 TimestampToCompare date_to_compare,
117 password_manager::PasswordStoreChangeList* changes); 120 password_manager::PasswordStoreChangeList* changes);
118 121
119 // Opens the wallet and ensures that the "Chrome Form Data" folder exists. 122 // Opens the wallet and ensures that the "Chrome Form Data" folder exists.
120 // Returns kInvalidWalletHandle on error. 123 // Returns kInvalidWalletHandle on error.
121 int WalletHandle(); 124 int WalletHandle();
122 125
123 // Serializes a list of PasswordForms to be stored in the wallet. 126 // Serializes a list of PasswordForms to be stored in the wallet.
124 static void SerializeValue(const PasswordFormList& forms, Pickle* pickle); 127 static void SerializeValue(const std::vector<autofill::PasswordForm*>& forms,
128 Pickle* pickle);
125 129
126 // Deserializes a list of PasswordForms from the wallet. 130 // Deserializes a list of PasswordForms from the wallet.
127 // |size_32| controls reading the size field within the pickle as 32 bits. 131 // |size_32| controls reading the size field within the pickle as 32 bits.
128 // We used to use Pickle::WriteSize() to write the number of password forms, 132 // We used to use Pickle::WriteSize() to write the number of password forms,
129 // but that has a different size on 32- and 64-bit systems. So, now we always 133 // but that has a different size on 32- and 64-bit systems. So, now we always
130 // write a 64-bit quantity, but we support trying to read it as either size 134 // write a 64-bit quantity, but we support trying to read it as either size
131 // when reading old pickles that fail to deserialize using the native size. 135 // when reading old pickles that fail to deserialize using the native size.
132 static bool DeserializeValueSize(const std::string& signon_realm, 136 static bool DeserializeValueSize(const std::string& signon_realm,
133 const PickleIterator& iter, 137 const PickleIterator& iter,
134 int version, bool size_32, bool warn_only, 138 int version,
135 PasswordFormList* forms); 139 bool size_32,
140 bool warn_only,
141 ScopedVector<autofill::PasswordForm>* forms);
136 142
137 // In case the fields in the pickle ever change, version them so we can try to 143 // In case the fields in the pickle ever change, version them so we can try to
138 // read old pickles. (Note: do not eat old pickles past the expiration date.) 144 // read old pickles. (Note: do not eat old pickles past the expiration date.)
139 static const int kPickleVersion = 4; 145 static const int kPickleVersion = 4;
140 146
141 // Generates a profile-specific folder name based on profile_id_. 147 // Generates a profile-specific folder name based on profile_id_.
142 std::string GetProfileSpecificFolderName() const; 148 std::string GetProfileSpecificFolderName() const;
143 149
144 // The local profile id, used to generate the folder name. 150 // The local profile id, used to generate the folder name.
145 const LocalProfileId profile_id_; 151 const LocalProfileId profile_id_;
146 152
147 // The KWallet folder name, possibly based on the local profile id. 153 // The KWallet folder name, possibly based on the local profile id.
148 std::string folder_name_; 154 std::string folder_name_;
149 155
150 // DBus handle for communication with klauncher and kwalletd. 156 // DBus handle for communication with klauncher and kwalletd.
151 scoped_refptr<dbus::Bus> session_bus_; 157 scoped_refptr<dbus::Bus> session_bus_;
152 // Object proxy for kwalletd. We do not own this. 158 // Object proxy for kwalletd. We do not own this.
153 dbus::ObjectProxy* kwallet_proxy_; 159 dbus::ObjectProxy* kwallet_proxy_;
154 160
155 // The name of the wallet we've opened. Set during Init(). 161 // The name of the wallet we've opened. Set during Init().
156 std::string wallet_name_; 162 std::string wallet_name_;
157 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs. 163 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs.
158 const std::string app_name_; 164 const std::string app_name_;
159 165
160 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet); 166 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet);
161 }; 167 };
162 168
163 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ 169 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698