Commit 308a2dfe authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Improve & rename ProfileState::GetSecondaryAccountsForProfile API

It should not get the primary account as argument but instead,
directly retrieve it from the SigninManagerFactory. It's being done in
preparation for the migration to IdentityManager in
https://crrev.com/c/1245784.

Apart from that it was decided to rename the API to
GetSecondaryAccountsForSignedInProfile in order to better reflect
the fact that the profile must be signed in.

Change-Id: Ib897c8d9a2cc585fb442c4ae7aff62455b381339
Reviewed-on: https://chromium-review.googlesource.com/1248742Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarStefan Kuhne <skuhne@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#595142}
parent c32b630b
......@@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
......@@ -157,11 +158,13 @@ void UpdateProfileName(Profile* profile,
base::UTF16ToUTF8(new_profile_name));
}
std::vector<std::string> GetSecondaryAccountsForProfile(
Profile* profile,
const std::string& primary_account) {
std::vector<std::string> GetSecondaryAccountsForSignedInProfile(
Profile* profile) {
std::vector<std::string> accounts =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->GetAccounts();
std::string primary_account =
SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
DCHECK(!primary_account.empty());
// The vector returned by ProfileOAuth2TokenService::GetAccounts() contains
// the primary account too, so we need to remove it from the list.
......
......@@ -69,12 +69,10 @@ base::string16 GetProfileSwitcherTextForItem(const AvatarMenu::Item& item);
void UpdateProfileName(Profile* profile,
const base::string16& new_profile_name);
// Returns the list of secondary accounts for a specific |profile|, which is
// all the email addresses associated with the profile that are not equal to
// the |primary_account|.
std::vector<std::string> GetSecondaryAccountsForProfile(
Profile* profile,
const std::string& primary_account);
// Returns the list of secondary accounts for a specific
// |profile|. Note that the profile must be signed in.
std::vector<std::string> GetSecondaryAccountsForSignedInProfile(
Profile* profile);
#endif // !defined(OS_CHROMEOS)
// Returns whether the |browser|'s profile is a non-incognito or guest profile.
......
......@@ -1425,25 +1425,24 @@ views::View* ProfileChooserView::CreateCurrentProfileAccountsView(
profiles::kAvatarBubbleAccountsBackgroundColor));
views::GridLayout* layout = CreateSingleColumnLayout(view, menu_width_);
Profile* profile = browser_->profile();
std::string primary_account =
SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
DCHECK(!primary_account.empty());
std::vector<std::string> accounts =
profiles::GetSecondaryAccountsForProfile(profile, primary_account);
// Get state of authentication error, if any.
Profile* profile = browser_->profile();
std::string error_account_id = GetAuthErrorAccountId(profile);
// The primary account should always be listed first.
// TODO(rogerta): we still need to further differentiate the primary account
// from the others in the UI, so more work is likely required here:
// crbug.com/311124.
std::string primary_account =
SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
DCHECK(!primary_account.empty());
CreateAccountButton(layout, primary_account, true,
error_account_id == primary_account, menu_width_);
for (size_t i = 0; i < accounts.size(); ++i)
CreateAccountButton(layout, accounts[i], false,
error_account_id == accounts[i], menu_width_);
for (const std::string& account :
profiles::GetSecondaryAccountsForSignedInProfile(profile)) {
CreateAccountButton(layout, account, false, error_account_id == account,
menu_width_);
}
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
const int vertical_spacing =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment