Commit b2cceb55 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Migrate ProfilesState to use IdentityManager

Users of ProfileOAuth2TokenService should use instead the
IdentityManager API so that they could eventually use the identity
service.

Bug: 887245
Change-Id: I2ac628d92759488530ee699d438dea920b8b6a9b
Reviewed-on: https://chromium-review.googlesource.com/1245784
Commit-Queue: Sergio Villar <svillar@igalia.com>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarStefan Kuhne <skuhne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595761}
parent 7f831f83
...@@ -15,15 +15,17 @@ ...@@ -15,15 +15,17 @@
#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/account_info.h"
#include "content/public/browser/browsing_data_remover.h" #include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/resource_dispatcher_host.h" #include "content/public/browser/resource_dispatcher_host.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -144,18 +146,22 @@ void UpdateProfileName(Profile* profile, ...@@ -144,18 +146,22 @@ void UpdateProfileName(Profile* profile,
base::UTF16ToUTF8(new_profile_name)); base::UTF16ToUTF8(new_profile_name));
} }
std::vector<std::string> GetSecondaryAccountsForSignedInProfile( std::vector<AccountInfo> GetSecondaryAccountsForSignedInProfile(
Profile* profile) { Profile* profile) {
std::vector<std::string> accounts = auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->GetAccounts(); std::vector<AccountInfo> accounts =
std::string primary_account = identity_manager->GetAccountsWithRefreshTokens();
SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
DCHECK(!primary_account.empty());
// The vector returned by ProfileOAuth2TokenService::GetAccounts() contains // The vector returned by GetAccountsWithRefreshTokens() contains
// the primary account too, so we need to remove it from the list. // the primary account too, so we need to remove it from the list.
std::vector<std::string>::iterator primary_index = DCHECK(identity_manager->HasPrimaryAccount());
std::find(accounts.begin(), accounts.end(), primary_account); AccountInfo primary_account = identity_manager->GetPrimaryAccountInfo();
std::vector<AccountInfo>::iterator primary_index = std::find_if(
accounts.begin(), accounts.end(),
[&primary_account](const AccountInfo& account_info) {
return account_info.account_id == primary_account.account_id;
});
DCHECK(primary_index != accounts.end()); DCHECK(primary_index != accounts.end());
accounts.erase(primary_index); accounts.erase(primary_index);
......
...@@ -23,6 +23,8 @@ class SigninErrorController; ...@@ -23,6 +23,8 @@ class SigninErrorController;
namespace base { class FilePath; } namespace base { class FilePath; }
struct AccountInfo;
namespace profiles { namespace profiles {
// Assortment of methods for dealing with profiles. // Assortment of methods for dealing with profiles.
...@@ -66,7 +68,7 @@ void UpdateProfileName(Profile* profile, ...@@ -66,7 +68,7 @@ void UpdateProfileName(Profile* profile,
// Returns the list of secondary accounts for a specific // Returns the list of secondary accounts for a specific
// |profile|. Note that the profile must be signed in. // |profile|. Note that the profile must be signed in.
std::vector<std::string> GetSecondaryAccountsForSignedInProfile( std::vector<AccountInfo> GetSecondaryAccountsForSignedInProfile(
Profile* profile); Profile* profile);
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_helper.h" #include "chrome/browser/signin/chrome_signin_helper.h"
#include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h" #include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
...@@ -70,6 +71,7 @@ ...@@ -70,6 +71,7 @@
#include "components/signin/core/browser/signin_metrics.h" #include "components/signin/core/browser/signin_metrics.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
...@@ -1429,16 +1431,17 @@ views::View* ProfileChooserView::CreateCurrentProfileAccountsView( ...@@ -1429,16 +1431,17 @@ views::View* ProfileChooserView::CreateCurrentProfileAccountsView(
// TODO(rogerta): we still need to further differentiate the primary account // TODO(rogerta): we still need to further differentiate the primary account
// from the others in the UI, so more work is likely required here: // from the others in the UI, so more work is likely required here:
// crbug.com/311124. // crbug.com/311124.
std::string primary_account = auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); DCHECK(identity_manager->HasPrimaryAccount());
DCHECK(!primary_account.empty()); AccountInfo primary_account = identity_manager->GetPrimaryAccountInfo();
CreateAccountButton(layout, primary_account, true,
error_account_id == primary_account, menu_width_); CreateAccountButton(layout, primary_account.account_id, true,
for (const std::string& account : error_account_id == primary_account.account_id,
profiles::GetSecondaryAccountsForSignedInProfile(profile)) { menu_width_);
CreateAccountButton(layout, account, false, error_account_id == account, for (const AccountInfo& account :
menu_width_); profiles::GetSecondaryAccountsForSignedInProfile(profile))
} CreateAccountButton(layout, account.account_id, false,
error_account_id == account.account_id, menu_width_);
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
const int vertical_spacing = 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