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

Side by Side Diff: chrome/browser/password_manager/native_backend_gnome_x.cc

Issue 2196193002: Expanded GnomeKeyringLoader macros (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix format Created 4 years, 4 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 #include "chrome/browser/password_manager/native_backend_gnome_x.h" 5 #include "chrome/browser/password_manager/native_backend_gnome_x.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <gnome-keyring.h> 8 #include <gnome-keyring.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 24 matching lines...) Expand all
35 using base::UTF8ToUTF16; 35 using base::UTF8ToUTF16;
36 using base::UTF16ToUTF8; 36 using base::UTF16ToUTF8;
37 using content::BrowserThread; 37 using content::BrowserThread;
38 using namespace password_manager::metrics_util; 38 using namespace password_manager::metrics_util;
39 using password_manager::PasswordStore; 39 using password_manager::PasswordStore;
40 40
41 namespace { 41 namespace {
42 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); 42 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max();
43 } 43 }
44 44
45 #define GNOME_KEYRING_DEFINE_POINTER(name) \ 45 decltype(&::gnome_keyring_is_available)
46 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; 46 GnomeKeyringLoader::gnome_keyring_is_available_ptr;
47 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) 47 decltype(&::gnome_keyring_store_password)
48 #undef GNOME_KEYRING_DEFINE_POINTER 48 GnomeKeyringLoader::gnome_keyring_store_password_ptr;
49 decltype(&::gnome_keyring_delete_password)
50 GnomeKeyringLoader::gnome_keyring_delete_password_ptr;
51 decltype(&::gnome_keyring_find_items)
52 GnomeKeyringLoader::gnome_keyring_find_items_ptr;
53 decltype(&::gnome_keyring_result_to_message)
54 GnomeKeyringLoader::gnome_keyring_result_to_message_ptr;
55 decltype(&::gnome_keyring_attribute_list_free)
56 GnomeKeyringLoader::gnome_keyring_attribute_list_free_ptr;
57 decltype(&::gnome_keyring_attribute_list_new)
58 GnomeKeyringLoader::gnome_keyring_attribute_list_new_ptr;
59 decltype(&::gnome_keyring_attribute_list_append_string)
60 GnomeKeyringLoader::gnome_keyring_attribute_list_append_string_ptr;
61 decltype(&::gnome_keyring_attribute_list_append_uint32)
62 GnomeKeyringLoader::gnome_keyring_attribute_list_append_uint32_ptr;
49 63
50 bool GnomeKeyringLoader::keyring_loaded = false; 64 bool GnomeKeyringLoader::keyring_loaded = false;
51 65
52 #define GNOME_KEYRING_FUNCTION_INFO(name) \
53 {"gnome_keyring_"#name, reinterpret_cast<void**>(&gnome_keyring_##name)},
54 const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = { 66 const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = {
55 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_FUNCTION_INFO) 67 {"gnome_keyring_is_available",
56 {nullptr, nullptr} 68 reinterpret_cast<void**>(&gnome_keyring_is_available_ptr)},
57 }; 69 {"gnome_keyring_store_password",
58 #undef GNOME_KEYRING_FUNCTION_INFO 70 reinterpret_cast<void**>(&gnome_keyring_store_password_ptr)},
71 {"gnome_keyring_delete_password",
72 reinterpret_cast<void**>(&gnome_keyring_delete_password_ptr)},
73 {"gnome_keyring_find_items",
74 reinterpret_cast<void**>(&gnome_keyring_find_items_ptr)},
75 {"gnome_keyring_result_to_message",
76 reinterpret_cast<void**>(&gnome_keyring_result_to_message_ptr)},
77 {"gnome_keyring_attribute_list_free",
78 reinterpret_cast<void**>(&gnome_keyring_attribute_list_free_ptr)},
79 {"gnome_keyring_attribute_list_new",
80 reinterpret_cast<void**>(&gnome_keyring_attribute_list_new_ptr)},
81 {"gnome_keyring_attribute_list_append_string",
82 reinterpret_cast<void**>(&gnome_keyring_attribute_list_append_string_ptr)},
83 {"gnome_keyring_attribute_list_append_uint32",
84 reinterpret_cast<void**>(
85 &gnome_keyring_attribute_list_append_uint32_ptr)}};
59 86
60 /* Load the library and initialize the function pointers. */ 87 /* Load the library and initialize the function pointers. */
61 bool GnomeKeyringLoader::LoadGnomeKeyring() { 88 bool GnomeKeyringLoader::LoadGnomeKeyring() {
62 if (keyring_loaded) 89 if (keyring_loaded)
63 return true; 90 return true;
64 91
65 void* handle = dlopen("libgnome-keyring.so.0", RTLD_NOW | RTLD_GLOBAL); 92 void* handle = dlopen("libgnome-keyring.so.0", RTLD_NOW | RTLD_GLOBAL);
66 if (!handle) { 93 if (!handle) {
67 // We wanted to use GNOME Keyring, but we couldn't load it. Warn, because 94 // We wanted to use GNOME Keyring, but we couldn't load it. Warn, because
68 // either the user asked for this, or we autodetected it incorrectly. (Or 95 // either the user asked for this, or we autodetected it incorrectly. (Or
69 // the system has broken libraries, which is also good to warn about.) 96 // the system has broken libraries, which is also good to warn about.)
70 LOG(WARNING) << "Could not load libgnome-keyring.so.0: " << dlerror(); 97 LOG(WARNING) << "Could not load libgnome-keyring.so.0: " << dlerror();
71 return false; 98 return false;
72 } 99 }
73 100
74 for (size_t i = 0; functions[i].name; ++i) { 101 for (size_t i = 0; i < arraysize(functions); ++i) {
75 dlerror(); 102 dlerror();
76 *functions[i].pointer = dlsym(handle, functions[i].name); 103 *functions[i].pointer = dlsym(handle, functions[i].name);
77 const char* error = dlerror(); 104 const char* error = dlerror();
78 if (error) { 105 if (error) {
79 LOG(ERROR) << "Unable to load symbol " 106 LOG(ERROR) << "Unable to load symbol "
80 << functions[i].name << ": " << error; 107 << functions[i].name << ": " << error;
81 dlclose(handle); 108 dlclose(handle);
82 return false; 109 return false;
83 } 110 }
84 } 111 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // Use after AddLogin, RemoveLogin. 309 // Use after AddLogin, RemoveLogin.
283 GnomeKeyringResult WaitResult(); 310 GnomeKeyringResult WaitResult();
284 311
285 // Use after LoginSearch, GetLogins, GetLoginsList, GetAllLogins. Replaces the 312 // Use after LoginSearch, GetLogins, GetLoginsList, GetAllLogins. Replaces the
286 // content of |forms| with found logins. 313 // content of |forms| with found logins.
287 GnomeKeyringResult WaitResult(ScopedVector<PasswordForm>* forms); 314 GnomeKeyringResult WaitResult(ScopedVector<PasswordForm>* forms);
288 315
289 private: 316 private:
290 struct GnomeKeyringAttributeListFreeDeleter { 317 struct GnomeKeyringAttributeListFreeDeleter {
291 inline void operator()(void* list) const { 318 inline void operator()(void* list) const {
292 gnome_keyring_attribute_list_free( 319 gnome_keyring_attribute_list_free_ptr(
293 static_cast<GnomeKeyringAttributeList*>(list)); 320 static_cast<GnomeKeyringAttributeList*>(list));
294 } 321 }
295 }; 322 };
296 323
297 typedef std::unique_ptr<GnomeKeyringAttributeList, 324 typedef std::unique_ptr<GnomeKeyringAttributeList,
298 GnomeKeyringAttributeListFreeDeleter> 325 GnomeKeyringAttributeListFreeDeleter>
299 ScopedAttributeList; 326 ScopedAttributeList;
300 327
301 // Helper methods to abbreviate Gnome Keyring long API names. 328 // Helper methods to abbreviate Gnome Keyring long API names.
302 static void AppendString(ScopedAttributeList* list, 329 static void AppendString(ScopedAttributeList* list,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 DCHECK_CURRENTLY_ON(BrowserThread::UI); 362 DCHECK_CURRENTLY_ON(BrowserThread::UI);
336 int64_t date_created = form.date_created.ToInternalValue(); 363 int64_t date_created = form.date_created.ToInternalValue();
337 // If we are asked to save a password with 0 date, use the current time. 364 // If we are asked to save a password with 0 date, use the current time.
338 // We don't want to actually save passwords as though on January 1, 1601. 365 // We don't want to actually save passwords as though on January 1, 1601.
339 if (!date_created) 366 if (!date_created)
340 date_created = base::Time::Now().ToInternalValue(); 367 date_created = base::Time::Now().ToInternalValue();
341 int64_t date_synced = form.date_synced.ToInternalValue(); 368 int64_t date_synced = form.date_synced.ToInternalValue();
342 std::string form_data; 369 std::string form_data;
343 SerializeFormDataToBase64String(form.form_data, &form_data); 370 SerializeFormDataToBase64String(form.form_data, &form_data);
344 // clang-format off 371 // clang-format off
345 gnome_keyring_store_password( 372 gnome_keyring_store_password_ptr(
346 &kGnomeSchema, 373 &kGnomeSchema,
347 nullptr, // Default keyring. 374 nullptr, // Default keyring.
348 form.origin.spec().c_str(), // Display name. 375 form.origin.spec().c_str(), // Display name.
349 UTF16ToUTF8(form.password_value).c_str(), OnOperationDone, 376 UTF16ToUTF8(form.password_value).c_str(), OnOperationDone,
350 this, // data 377 this, // data
351 nullptr, // destroy_data 378 nullptr, // destroy_data
352 "origin_url", form.origin.spec().c_str(), 379 "origin_url", form.origin.spec().c_str(),
353 "action_url", form.action.spec().c_str(), 380 "action_url", form.action.spec().c_str(),
354 "username_element", UTF16ToUTF8(form.username_element).c_str(), 381 "username_element", UTF16ToUTF8(form.username_element).c_str(),
355 "username_value", UTF16ToUTF8(form.username_value).c_str(), 382 "username_value", UTF16ToUTF8(form.username_value).c_str(),
(...skipping 20 matching lines...) Expand all
376 "application", app_string, 403 "application", app_string,
377 nullptr); 404 nullptr);
378 // clang-format on 405 // clang-format on
379 } 406 }
380 407
381 void GKRMethod::LoginSearch(const PasswordForm& form, 408 void GKRMethod::LoginSearch(const PasswordForm& form,
382 const char* app_string) { 409 const char* app_string) {
383 DCHECK_CURRENTLY_ON(BrowserThread::UI); 410 DCHECK_CURRENTLY_ON(BrowserThread::UI);
384 lookup_form_.reset(nullptr); 411 lookup_form_.reset(nullptr);
385 // Search GNOME Keyring for matching passwords to update. 412 // Search GNOME Keyring for matching passwords to update.
386 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 413 ScopedAttributeList attrs(gnome_keyring_attribute_list_new_ptr());
387 AppendString(&attrs, "origin_url", form.origin.spec()); 414 AppendString(&attrs, "origin_url", form.origin.spec());
388 AppendString(&attrs, "username_element", UTF16ToUTF8(form.username_element)); 415 AppendString(&attrs, "username_element", UTF16ToUTF8(form.username_element));
389 AppendString(&attrs, "username_value", UTF16ToUTF8(form.username_value)); 416 AppendString(&attrs, "username_value", UTF16ToUTF8(form.username_value));
390 AppendString(&attrs, "password_element", UTF16ToUTF8(form.password_element)); 417 AppendString(&attrs, "password_element", UTF16ToUTF8(form.password_element));
391 AppendString(&attrs, "signon_realm", form.signon_realm); 418 AppendString(&attrs, "signon_realm", form.signon_realm);
392 AppendString(&attrs, "application", app_string); 419 AppendString(&attrs, "application", app_string);
393 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 420 gnome_keyring_find_items_ptr(GNOME_KEYRING_ITEM_GENERIC_SECRET, attrs.get(),
394 attrs.get(), 421 OnOperationGetList,
395 OnOperationGetList, 422 /*data=*/this,
396 /*data=*/this, 423 /*destroy_data=*/nullptr);
397 /*destroy_data=*/nullptr);
398 } 424 }
399 425
400 void GKRMethod::RemoveLogin(const PasswordForm& form, const char* app_string) { 426 void GKRMethod::RemoveLogin(const PasswordForm& form, const char* app_string) {
401 DCHECK_CURRENTLY_ON(BrowserThread::UI); 427 DCHECK_CURRENTLY_ON(BrowserThread::UI);
402 // We find forms using the same fields as LoginDatabase::RemoveLogin(). 428 // We find forms using the same fields as LoginDatabase::RemoveLogin().
403 gnome_keyring_delete_password( 429 gnome_keyring_delete_password_ptr(
404 &kGnomeSchema, 430 &kGnomeSchema,
405 OnOperationDone, 431 OnOperationDone,
406 this, // data 432 this, // data
407 nullptr, // destroy_data 433 nullptr, // destroy_data
408 "origin_url", form.origin.spec().c_str(), 434 "origin_url", form.origin.spec().c_str(),
409 "username_element", UTF16ToUTF8(form.username_element).c_str(), 435 "username_element", UTF16ToUTF8(form.username_element).c_str(),
410 "username_value", UTF16ToUTF8(form.username_value).c_str(), 436 "username_value", UTF16ToUTF8(form.username_value).c_str(),
411 "password_element", UTF16ToUTF8(form.password_element).c_str(), 437 "password_element", UTF16ToUTF8(form.password_element).c_str(),
412 "signon_realm", form.signon_realm.c_str(), 438 "signon_realm", form.signon_realm.c_str(),
413 "application", app_string, 439 "application", app_string,
414 nullptr); 440 nullptr);
415 } 441 }
416 442
417 void GKRMethod::GetLogins(const PasswordStore::FormDigest& form, 443 void GKRMethod::GetLogins(const PasswordStore::FormDigest& form,
418 const char* app_string) { 444 const char* app_string) {
419 DCHECK_CURRENTLY_ON(BrowserThread::UI); 445 DCHECK_CURRENTLY_ON(BrowserThread::UI);
420 lookup_form_.reset(new PasswordStore::FormDigest(form)); 446 lookup_form_.reset(new PasswordStore::FormDigest(form));
421 // Search GNOME Keyring for matching passwords. 447 // Search GNOME Keyring for matching passwords.
422 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 448 ScopedAttributeList attrs(gnome_keyring_attribute_list_new_ptr());
423 if (!password_manager::ShouldPSLDomainMatchingApply( 449 if (!password_manager::ShouldPSLDomainMatchingApply(
424 password_manager::GetRegistryControlledDomain( 450 password_manager::GetRegistryControlledDomain(
425 GURL(form.signon_realm))) && 451 GURL(form.signon_realm))) &&
426 form.scheme != PasswordForm::SCHEME_HTML) { 452 form.scheme != PasswordForm::SCHEME_HTML) {
427 // Don't retrieve the PSL matched and federated credentials. 453 // Don't retrieve the PSL matched and federated credentials.
428 AppendString(&attrs, "signon_realm", form.signon_realm); 454 AppendString(&attrs, "signon_realm", form.signon_realm);
429 } 455 }
430 AppendString(&attrs, "application", app_string); 456 AppendString(&attrs, "application", app_string);
431 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 457 gnome_keyring_find_items_ptr(GNOME_KEYRING_ITEM_GENERIC_SECRET, attrs.get(),
432 attrs.get(), 458 OnOperationGetList,
433 OnOperationGetList, 459 /*data=*/this,
434 /*data=*/this, 460 /*destroy_data=*/nullptr);
435 /*destroy_data=*/nullptr);
436 } 461 }
437 462
438 void GKRMethod::GetLoginsList(uint32_t blacklisted_by_user, 463 void GKRMethod::GetLoginsList(uint32_t blacklisted_by_user,
439 const char* app_string) { 464 const char* app_string) {
440 DCHECK_CURRENTLY_ON(BrowserThread::UI); 465 DCHECK_CURRENTLY_ON(BrowserThread::UI);
441 lookup_form_.reset(nullptr); 466 lookup_form_.reset(nullptr);
442 // Search GNOME Keyring for matching passwords. 467 // Search GNOME Keyring for matching passwords.
443 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 468 ScopedAttributeList attrs(gnome_keyring_attribute_list_new_ptr());
444 AppendUint32(&attrs, "blacklisted_by_user", blacklisted_by_user); 469 AppendUint32(&attrs, "blacklisted_by_user", blacklisted_by_user);
445 AppendString(&attrs, "application", app_string); 470 AppendString(&attrs, "application", app_string);
446 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 471 gnome_keyring_find_items_ptr(GNOME_KEYRING_ITEM_GENERIC_SECRET, attrs.get(),
447 attrs.get(), 472 OnOperationGetList,
448 OnOperationGetList, 473 /*data=*/this,
449 /*data=*/this, 474 /*destroy_data=*/nullptr);
450 /*destroy_data=*/nullptr);
451 } 475 }
452 476
453 void GKRMethod::GetAllLogins(const char* app_string) { 477 void GKRMethod::GetAllLogins(const char* app_string) {
454 DCHECK_CURRENTLY_ON(BrowserThread::UI); 478 DCHECK_CURRENTLY_ON(BrowserThread::UI);
455 lookup_form_.reset(nullptr); 479 lookup_form_.reset(nullptr);
456 // We need to search for something, otherwise we get no results - so 480 // We need to search for something, otherwise we get no results - so
457 // we search for the fixed application string. 481 // we search for the fixed application string.
458 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 482 ScopedAttributeList attrs(gnome_keyring_attribute_list_new_ptr());
459 AppendString(&attrs, "application", app_string); 483 AppendString(&attrs, "application", app_string);
460 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 484 gnome_keyring_find_items_ptr(GNOME_KEYRING_ITEM_GENERIC_SECRET, attrs.get(),
461 attrs.get(), 485 OnOperationGetList,
462 OnOperationGetList, 486 /*data=*/this,
463 /*data=*/this, 487 /*destroy_data=*/nullptr);
464 /*destroy_data=*/nullptr);
465 } 488 }
466 489
467 GnomeKeyringResult GKRMethod::WaitResult() { 490 GnomeKeyringResult GKRMethod::WaitResult() {
468 DCHECK_CURRENTLY_ON(BrowserThread::DB); 491 DCHECK_CURRENTLY_ON(BrowserThread::DB);
469 event_.Wait(); 492 event_.Wait();
470 return result_; 493 return result_;
471 } 494 }
472 495
473 GnomeKeyringResult GKRMethod::WaitResult(ScopedVector<PasswordForm>* forms) { 496 GnomeKeyringResult GKRMethod::WaitResult(ScopedVector<PasswordForm>* forms) {
474 DCHECK_CURRENTLY_ON(BrowserThread::DB); 497 DCHECK_CURRENTLY_ON(BrowserThread::DB);
475 event_.Wait(); 498 event_.Wait();
476 *forms = std::move(forms_); 499 *forms = std::move(forms_);
477 return result_; 500 return result_;
478 } 501 }
479 502
480 // static 503 // static
481 void GKRMethod::AppendString(GKRMethod::ScopedAttributeList* list, 504 void GKRMethod::AppendString(GKRMethod::ScopedAttributeList* list,
482 const char* name, 505 const char* name,
483 const char* value) { 506 const char* value) {
484 gnome_keyring_attribute_list_append_string(list->get(), name, value); 507 gnome_keyring_attribute_list_append_string_ptr(list->get(), name, value);
485 } 508 }
486 509
487 // static 510 // static
488 void GKRMethod::AppendString(GKRMethod::ScopedAttributeList* list, 511 void GKRMethod::AppendString(GKRMethod::ScopedAttributeList* list,
489 const char* name, 512 const char* name,
490 const std::string& value) { 513 const std::string& value) {
491 AppendString(list, name, value.c_str()); 514 AppendString(list, name, value.c_str());
492 } 515 }
493 516
494 // static 517 // static
495 void GKRMethod::AppendUint32(GKRMethod::ScopedAttributeList* list, 518 void GKRMethod::AppendUint32(GKRMethod::ScopedAttributeList* list,
496 const char* name, 519 const char* name,
497 guint32 value) { 520 guint32 value) {
498 gnome_keyring_attribute_list_append_uint32(list->get(), name, value); 521 gnome_keyring_attribute_list_append_uint32_ptr(list->get(), name, value);
499 } 522 }
500 523
501 // static 524 // static
502 void GKRMethod::OnOperationDone(GnomeKeyringResult result, gpointer data) { 525 void GKRMethod::OnOperationDone(GnomeKeyringResult result, gpointer data) {
503 GKRMethod* method = static_cast<GKRMethod*>(data); 526 GKRMethod* method = static_cast<GKRMethod*>(data);
504 method->result_ = result; 527 method->result_ = result;
505 method->event_.Signal(); 528 method->event_.Signal();
506 } 529 }
507 530
508 // static 531 // static
(...skipping 21 matching lines...) Expand all
530 } // namespace 553 } // namespace
531 554
532 NativeBackendGnome::NativeBackendGnome(LocalProfileId id) 555 NativeBackendGnome::NativeBackendGnome(LocalProfileId id)
533 : app_string_(GetProfileSpecificAppString(id)) { 556 : app_string_(GetProfileSpecificAppString(id)) {
534 } 557 }
535 558
536 NativeBackendGnome::~NativeBackendGnome() { 559 NativeBackendGnome::~NativeBackendGnome() {
537 } 560 }
538 561
539 bool NativeBackendGnome::Init() { 562 bool NativeBackendGnome::Init() {
540 return LoadGnomeKeyring() && gnome_keyring_is_available(); 563 return LoadGnomeKeyring() && gnome_keyring_is_available_ptr();
541 } 564 }
542 565
543 bool NativeBackendGnome::RawAddLogin(const PasswordForm& form) { 566 bool NativeBackendGnome::RawAddLogin(const PasswordForm& form) {
544 DCHECK_CURRENTLY_ON(BrowserThread::DB); 567 DCHECK_CURRENTLY_ON(BrowserThread::DB);
545 GKRMethod method; 568 GKRMethod method;
546 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 569 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
547 base::Bind(&GKRMethod::AddLogin, 570 base::Bind(&GKRMethod::AddLogin,
548 base::Unretained(&method), 571 base::Unretained(&method),
549 form, app_string_.c_str())); 572 form, app_string_.c_str()));
550 GnomeKeyringResult result = method.WaitResult(); 573 GnomeKeyringResult result = method.WaitResult();
551 if (result != GNOME_KEYRING_RESULT_OK) { 574 if (result != GNOME_KEYRING_RESULT_OK) {
552 LOG(ERROR) << "Keyring save failed: " 575 LOG(ERROR) << "Keyring save failed: "
553 << gnome_keyring_result_to_message(result); 576 << gnome_keyring_result_to_message_ptr(result);
554 return false; 577 return false;
555 } 578 }
556 return true; 579 return true;
557 } 580 }
558 581
559 password_manager::PasswordStoreChangeList NativeBackendGnome::AddLogin( 582 password_manager::PasswordStoreChangeList NativeBackendGnome::AddLogin(
560 const PasswordForm& form) { 583 const PasswordForm& form) {
561 // Based on LoginDatabase::AddLogin(), we search for an existing match based 584 // Based on LoginDatabase::AddLogin(), we search for an existing match based
562 // on origin_url, username_element, username_value, password_element, submit 585 // on origin_url, username_element, username_value, password_element, submit
563 // element, and signon_realm first, remove that, and then add the new entry. 586 // element, and signon_realm first, remove that, and then add the new entry.
564 // We'd add the new one first, and then delete the original, but then the 587 // We'd add the new one first, and then delete the original, but then the
565 // delete might actually delete the newly-added entry! 588 // delete might actually delete the newly-added entry!
566 DCHECK_CURRENTLY_ON(BrowserThread::DB); 589 DCHECK_CURRENTLY_ON(BrowserThread::DB);
567 GKRMethod method; 590 GKRMethod method;
568 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 591 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
569 base::Bind(&GKRMethod::LoginSearch, 592 base::Bind(&GKRMethod::LoginSearch,
570 base::Unretained(&method), 593 base::Unretained(&method),
571 form, app_string_.c_str())); 594 form, app_string_.c_str()));
572 ScopedVector<PasswordForm> forms; 595 ScopedVector<PasswordForm> forms;
573 GnomeKeyringResult result = method.WaitResult(&forms); 596 GnomeKeyringResult result = method.WaitResult(&forms);
574 if (result != GNOME_KEYRING_RESULT_OK && 597 if (result != GNOME_KEYRING_RESULT_OK &&
575 result != GNOME_KEYRING_RESULT_NO_MATCH) { 598 result != GNOME_KEYRING_RESULT_NO_MATCH) {
576 LOG(ERROR) << "Keyring find failed: " 599 LOG(ERROR) << "Keyring find failed: "
577 << gnome_keyring_result_to_message(result); 600 << gnome_keyring_result_to_message_ptr(result);
578 return password_manager::PasswordStoreChangeList(); 601 return password_manager::PasswordStoreChangeList();
579 } 602 }
580 password_manager::PasswordStoreChangeList changes; 603 password_manager::PasswordStoreChangeList changes;
581 if (forms.size() > 0) { 604 if (forms.size() > 0) {
582 password_manager::PasswordStoreChangeList temp_changes; 605 password_manager::PasswordStoreChangeList temp_changes;
583 if (forms.size() > 1) { 606 if (forms.size() > 1) {
584 LOG(WARNING) << "Adding login when there are " << forms.size() 607 LOG(WARNING) << "Adding login when there are " << forms.size()
585 << " matching logins already!"; 608 << " matching logins already!";
586 } 609 }
587 for (const PasswordForm* old_form : forms) { 610 for (const PasswordForm* old_form : forms) {
(...skipping 25 matching lines...) Expand all
613 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 636 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
614 base::Bind(&GKRMethod::LoginSearch, 637 base::Bind(&GKRMethod::LoginSearch,
615 base::Unretained(&method), 638 base::Unretained(&method),
616 form, app_string_.c_str())); 639 form, app_string_.c_str()));
617 ScopedVector<PasswordForm> forms; 640 ScopedVector<PasswordForm> forms;
618 GnomeKeyringResult result = method.WaitResult(&forms); 641 GnomeKeyringResult result = method.WaitResult(&forms);
619 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 642 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
620 return true; 643 return true;
621 if (result != GNOME_KEYRING_RESULT_OK) { 644 if (result != GNOME_KEYRING_RESULT_OK) {
622 LOG(ERROR) << "Keyring find failed: " 645 LOG(ERROR) << "Keyring find failed: "
623 << gnome_keyring_result_to_message(result); 646 << gnome_keyring_result_to_message_ptr(result);
624 return false; 647 return false;
625 } 648 }
626 if (forms.size() == 1 && *forms.front() == form) 649 if (forms.size() == 1 && *forms.front() == form)
627 return true; 650 return true;
628 651
629 password_manager::PasswordStoreChangeList temp_changes; 652 password_manager::PasswordStoreChangeList temp_changes;
630 for (const PasswordForm* keychain_form : forms) { 653 for (const PasswordForm* keychain_form : forms) {
631 // Remove all the obsolete forms. Note that RemoveLogin can remove any form 654 // Remove all the obsolete forms. Note that RemoveLogin can remove any form
632 // matching the unique key. Thus, it's important to call it the right number 655 // matching the unique key. Thus, it's important to call it the right number
633 // of times. 656 // of times.
(...skipping 19 matching lines...) Expand all
653 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 676 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
654 base::Bind(&GKRMethod::RemoveLogin, 677 base::Bind(&GKRMethod::RemoveLogin,
655 base::Unretained(&method), 678 base::Unretained(&method),
656 form, app_string_.c_str())); 679 form, app_string_.c_str()));
657 GnomeKeyringResult result = method.WaitResult(); 680 GnomeKeyringResult result = method.WaitResult();
658 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 681 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
659 return true; 682 return true;
660 683
661 if (result != GNOME_KEYRING_RESULT_OK) { 684 if (result != GNOME_KEYRING_RESULT_OK) {
662 LOG(ERROR) << "Keyring delete failed: " 685 LOG(ERROR) << "Keyring delete failed: "
663 << gnome_keyring_result_to_message(result); 686 << gnome_keyring_result_to_message_ptr(result);
664 return false; 687 return false;
665 } 688 }
666 changes->push_back(password_manager::PasswordStoreChange( 689 changes->push_back(password_manager::PasswordStoreChange(
667 password_manager::PasswordStoreChange::REMOVE, form)); 690 password_manager::PasswordStoreChange::REMOVE, form));
668 return true; 691 return true;
669 } 692 }
670 693
671 bool NativeBackendGnome::RemoveLoginsCreatedBetween( 694 bool NativeBackendGnome::RemoveLoginsCreatedBetween(
672 base::Time delete_begin, 695 base::Time delete_begin,
673 base::Time delete_end, 696 base::Time delete_end,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 GKRMethod method; 730 GKRMethod method;
708 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 731 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
709 base::Bind(&GKRMethod::GetLogins, 732 base::Bind(&GKRMethod::GetLogins,
710 base::Unretained(&method), 733 base::Unretained(&method),
711 form, app_string_.c_str())); 734 form, app_string_.c_str()));
712 GnomeKeyringResult result = method.WaitResult(forms); 735 GnomeKeyringResult result = method.WaitResult(forms);
713 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 736 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
714 return true; 737 return true;
715 if (result != GNOME_KEYRING_RESULT_OK) { 738 if (result != GNOME_KEYRING_RESULT_OK) {
716 LOG(ERROR) << "Keyring find failed: " 739 LOG(ERROR) << "Keyring find failed: "
717 << gnome_keyring_result_to_message(result); 740 << gnome_keyring_result_to_message_ptr(result);
718 return false; 741 return false;
719 } 742 }
720 return true; 743 return true;
721 } 744 }
722 745
723 bool NativeBackendGnome::GetAutofillableLogins( 746 bool NativeBackendGnome::GetAutofillableLogins(
724 ScopedVector<PasswordForm>* forms) { 747 ScopedVector<PasswordForm>* forms) {
725 return GetLoginsList(true, forms); 748 return GetLoginsList(true, forms);
726 } 749 }
727 750
(...skipping 10 matching lines...) Expand all
738 GKRMethod method; 761 GKRMethod method;
739 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 762 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
740 base::Bind(&GKRMethod::GetLoginsList, 763 base::Bind(&GKRMethod::GetLoginsList,
741 base::Unretained(&method), 764 base::Unretained(&method),
742 blacklisted_by_user, app_string_.c_str())); 765 blacklisted_by_user, app_string_.c_str()));
743 GnomeKeyringResult result = method.WaitResult(forms); 766 GnomeKeyringResult result = method.WaitResult(forms);
744 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 767 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
745 return true; 768 return true;
746 if (result != GNOME_KEYRING_RESULT_OK) { 769 if (result != GNOME_KEYRING_RESULT_OK) {
747 LOG(ERROR) << "Keyring find failed: " 770 LOG(ERROR) << "Keyring find failed: "
748 << gnome_keyring_result_to_message(result); 771 << gnome_keyring_result_to_message_ptr(result);
749 return false; 772 return false;
750 } 773 }
751 774
752 // Get rid of the forms with the same sync tags. 775 // Get rid of the forms with the same sync tags.
753 ScopedVector<autofill::PasswordForm> duplicates; 776 ScopedVector<autofill::PasswordForm> duplicates;
754 std::vector<std::vector<autofill::PasswordForm*>> tag_groups; 777 std::vector<std::vector<autofill::PasswordForm*>> tag_groups;
755 password_manager_util::FindDuplicates(forms, &duplicates, &tag_groups); 778 password_manager_util::FindDuplicates(forms, &duplicates, &tag_groups);
756 if (duplicates.empty()) 779 if (duplicates.empty())
757 return true; 780 return true;
758 for (const auto& group : tag_groups) { 781 for (const auto& group : tag_groups) {
(...skipping 13 matching lines...) Expand all
772 GKRMethod method; 795 GKRMethod method;
773 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 796 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
774 base::Bind(&GKRMethod::GetAllLogins, 797 base::Bind(&GKRMethod::GetAllLogins,
775 base::Unretained(&method), 798 base::Unretained(&method),
776 app_string_.c_str())); 799 app_string_.c_str()));
777 GnomeKeyringResult result = method.WaitResult(forms); 800 GnomeKeyringResult result = method.WaitResult(forms);
778 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 801 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
779 return true; 802 return true;
780 if (result != GNOME_KEYRING_RESULT_OK) { 803 if (result != GNOME_KEYRING_RESULT_OK) {
781 LOG(ERROR) << "Keyring find failed: " 804 LOG(ERROR) << "Keyring find failed: "
782 << gnome_keyring_result_to_message(result); 805 << gnome_keyring_result_to_message_ptr(result);
783 return false; 806 return false;
784 } 807 }
785 return true; 808 return true;
786 } 809 }
787 810
788 bool NativeBackendGnome::GetLoginsBetween(base::Time get_begin, 811 bool NativeBackendGnome::GetLoginsBetween(base::Time get_begin,
789 base::Time get_end, 812 base::Time get_end,
790 TimestampToCompare date_to_compare, 813 TimestampToCompare date_to_compare,
791 ScopedVector<PasswordForm>* forms) { 814 ScopedVector<PasswordForm>* forms) {
792 DCHECK_CURRENTLY_ON(BrowserThread::DB); 815 DCHECK_CURRENTLY_ON(BrowserThread::DB);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 ScopedVector<PasswordForm> forms; 847 ScopedVector<PasswordForm> forms;
825 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) 848 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms))
826 return false; 849 return false;
827 850
828 for (size_t i = 0; i < forms.size(); ++i) { 851 for (size_t i = 0; i < forms.size(); ++i) {
829 if (!RemoveLogin(*forms[i], changes)) 852 if (!RemoveLogin(*forms[i], changes))
830 return false; 853 return false;
831 } 854 }
832 return true; 855 return true;
833 } 856 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698