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 #include "chrome/browser/password_manager/native_backend_kwallet_x.h" | 5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 if (!reader.PopString(&wallet_name_)) { | 258 if (!reader.PopString(&wallet_name_)) { |
259 LOG(ERROR) << "Error reading response from kwalletd (networkWallet): " | 259 LOG(ERROR) << "Error reading response from kwalletd (networkWallet): " |
260 << response->ToString(); | 260 << response->ToString(); |
261 return PERMANENT_FAIL; | 261 return PERMANENT_FAIL; |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 return INIT_SUCCESS; | 265 return INIT_SUCCESS; |
266 } | 266 } |
267 | 267 |
268 bool NativeBackendKWallet::AddLogin(const PasswordForm& form) { | 268 password_manager::PasswordStoreChangeList NativeBackendKWallet::AddLogin( |
| 269 const PasswordForm& form) { |
269 int wallet_handle = WalletHandle(); | 270 int wallet_handle = WalletHandle(); |
270 if (wallet_handle == kInvalidKWalletHandle) | 271 if (wallet_handle == kInvalidKWalletHandle) |
271 return false; | 272 return password_manager::PasswordStoreChangeList(); |
272 | 273 |
273 PasswordFormList forms; | 274 ScopedVector<autofill::PasswordForm> forms; |
274 GetLoginsList(&forms, form.signon_realm, wallet_handle); | 275 GetLoginsList(&forms.get(), form.signon_realm, wallet_handle); |
275 | 276 |
276 // We search for a login to update, rather than unconditionally appending the | 277 // We search for a login to update, rather than unconditionally appending the |
277 // login, because in some cases (especially involving sync) we can be asked to | 278 // login, because in some cases (especially involving sync) we can be asked to |
278 // add a login that already exists. In these cases we want to just update. | 279 // add a login that already exists. In these cases we want to just update. |
279 bool updated = false; | 280 bool updated = false; |
| 281 password_manager::PasswordStoreChangeList changes; |
280 for (size_t i = 0; i < forms.size(); ++i) { | 282 for (size_t i = 0; i < forms.size(); ++i) { |
281 // Use the more restrictive removal comparison, so that we never have | 283 // Use the more restrictive removal comparison, so that we never have |
282 // duplicate logins that would all be removed together by RemoveLogin(). | 284 // duplicate logins that would all be removed together by RemoveLogin(). |
283 if (CompareForms(form, *forms[i], false)) { | 285 if (CompareForms(form, *forms[i], false)) { |
| 286 changes.push_back(password_manager::PasswordStoreChange( |
| 287 password_manager::PasswordStoreChange::REMOVE, *forms[i])); |
284 *forms[i] = form; | 288 *forms[i] = form; |
285 updated = true; | 289 updated = true; |
286 } | 290 } |
287 } | 291 } |
288 if (!updated) | 292 if (!updated) |
289 forms.push_back(new PasswordForm(form)); | 293 forms.push_back(new PasswordForm(form)); |
| 294 changes.push_back(password_manager::PasswordStoreChange( |
| 295 password_manager::PasswordStoreChange::ADD, form)); |
290 | 296 |
291 bool ok = SetLoginsList(forms, form.signon_realm, wallet_handle); | 297 bool ok = SetLoginsList(forms.get(), form.signon_realm, wallet_handle); |
| 298 if (!ok) |
| 299 changes.clear(); |
292 | 300 |
293 STLDeleteElements(&forms); | 301 return changes; |
294 return ok; | |
295 } | 302 } |
296 | 303 |
297 bool NativeBackendKWallet::UpdateLogin(const PasswordForm& form) { | 304 bool NativeBackendKWallet::UpdateLogin(const PasswordForm& form) { |
298 int wallet_handle = WalletHandle(); | 305 int wallet_handle = WalletHandle(); |
299 if (wallet_handle == kInvalidKWalletHandle) | 306 if (wallet_handle == kInvalidKWalletHandle) |
300 return false; | 307 return false; |
301 | 308 |
302 PasswordFormList forms; | 309 PasswordFormList forms; |
303 GetLoginsList(&forms, form.signon_realm, wallet_handle); | 310 GetLoginsList(&forms, form.signon_realm, wallet_handle); |
304 | 311 |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 } | 922 } |
916 | 923 |
917 return handle; | 924 return handle; |
918 } | 925 } |
919 | 926 |
920 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { | 927 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { |
921 // Originally, the folder name was always just "Chrome Form Data". | 928 // Originally, the folder name was always just "Chrome Form Data". |
922 // Now we use it to distinguish passwords for different profiles. | 929 // Now we use it to distinguish passwords for different profiles. |
923 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); | 930 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); |
924 } | 931 } |
OLD | NEW |