OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/webui/signin/inline_login_handler_impl.h" | 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 origin != kGaiaExtOrigin && | 506 origin != kGaiaExtOrigin && |
507 !gaia::IsGaiaSignonRealm(origin)) { | 507 !gaia::IsGaiaSignonRealm(origin)) { |
508 confirm_untrusted_signin_ = true; | 508 confirm_untrusted_signin_ = true; |
509 } | 509 } |
510 } | 510 } |
511 } | 511 } |
512 | 512 |
513 // static | 513 // static |
514 bool InlineLoginHandlerImpl::CanOffer(Profile* profile, | 514 bool InlineLoginHandlerImpl::CanOffer(Profile* profile, |
515 CanOfferFor can_offer_for, | 515 CanOfferFor can_offer_for, |
| 516 const std::string& gaia_id, |
516 const std::string& email, | 517 const std::string& email, |
517 std::string* error_message) { | 518 std::string* error_message) { |
518 if (error_message) | 519 if (error_message) |
519 error_message->clear(); | 520 error_message->clear(); |
520 | 521 |
521 if (!profile) | 522 if (!profile) |
522 return false; | 523 return false; |
523 | 524 |
524 SigninManager* manager = SigninManagerFactory::GetForProfile(profile); | 525 SigninManager* manager = SigninManagerFactory::GetForProfile(profile); |
525 if (manager && !manager->IsSigninAllowed()) | 526 if (manager && !manager->IsSigninAllowed()) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 return false; | 562 return false; |
562 } | 563 } |
563 | 564 |
564 // If some profile, not just the current one, is already connected to this | 565 // If some profile, not just the current one, is already connected to this |
565 // account, don't show the infobar. | 566 // account, don't show the infobar. |
566 if (g_browser_process && !same_email) { | 567 if (g_browser_process && !same_email) { |
567 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 568 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
568 if (profile_manager) { | 569 if (profile_manager) { |
569 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 570 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
570 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 571 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 572 // For backward compatibility, need to also check the username of the |
| 573 // profile, since the GAIA ID may not have been set yet for the |
| 574 // profile cache info. It will get set once the profile is opened. |
| 575 std::string profile_gaia_id = cache.GetGAIAIdOfProfileAtIndex(i); |
571 std::string profile_email = | 576 std::string profile_email = |
572 base::UTF16ToUTF8(cache.GetUserNameOfProfileAtIndex(i)); | 577 base::UTF16ToUTF8(cache.GetUserNameOfProfileAtIndex(i)); |
573 if (gaia::AreEmailsSame(email, profile_email)) { | 578 if (gaia_id == profile_gaia_id || |
| 579 gaia::AreEmailsSame(email, profile_email)) { |
574 if (error_message) { | 580 if (error_message) { |
575 error_message->assign( | 581 error_message->assign( |
576 l10n_util::GetStringUTF8(IDS_SYNC_USER_NAME_IN_USE_ERROR)); | 582 l10n_util::GetStringUTF8(IDS_SYNC_USER_NAME_IN_USE_ERROR)); |
577 } | 583 } |
578 return false; | 584 return false; |
579 } | 585 } |
580 } | 586 } |
581 } | 587 } |
582 } | 588 } |
583 } | 589 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; | 684 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; |
679 break; | 685 break; |
680 } | 686 } |
681 default: | 687 default: |
682 // No need to change |can_offer_for|. | 688 // No need to change |can_offer_for|. |
683 break; | 689 break; |
684 } | 690 } |
685 | 691 |
686 std::string error_msg; | 692 std::string error_msg; |
687 bool can_offer = CanOffer(Profile::FromWebUI(web_ui()), can_offer_for, | 693 bool can_offer = CanOffer(Profile::FromWebUI(web_ui()), can_offer_for, |
688 email, &error_msg); | 694 gaia_id, email, &error_msg); |
689 if (!can_offer) { | 695 if (!can_offer) { |
690 HandleLoginError(error_msg); | 696 HandleLoginError(error_msg); |
691 return; | 697 return; |
692 } | 698 } |
693 | 699 |
694 AboutSigninInternals* about_signin_internals = | 700 AboutSigninInternals* about_signin_internals = |
695 AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 701 AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
696 about_signin_internals->OnAuthenticationResultReceived("Successful"); | 702 about_signin_internals->OnAuthenticationResultReceived("Successful"); |
697 | 703 |
698 content::StoragePartition* partition = | 704 content::StoragePartition* partition = |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 } | 780 } |
775 } | 781 } |
776 | 782 |
777 if (show_account_management) { | 783 if (show_account_management) { |
778 browser->window()->ShowAvatarBubbleFromAvatarButton( | 784 browser->window()->ShowAvatarBubbleFromAvatarButton( |
779 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 785 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
780 signin::ManageAccountsParams()); | 786 signin::ManageAccountsParams()); |
781 } | 787 } |
782 } | 788 } |
783 } | 789 } |
OLD | NEW |