Commit ebaf6fb9 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[s13n] Convert c/b/ui/views/profiles/profile_chooser_view.cc to IdentityManager

CL also converts ::GetMessagesForAvatarSyncError defined at c/b/sync/sync_ui_util.h|cc,
(but not the whole file).

BUG=890804,890796

Change-Id: I4d7dbbdb1c5ca6f86e44cf9b4b454143eac08d9d
Reviewed-on: https://chromium-review.googlesource.com/c/1324589
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606415}
parent e9e7065b
......@@ -19,6 +19,7 @@
#include "components/sync/base/sync_prefs.h"
#include "components/sync/protocol/sync_protocol_error.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(OS_CHROMEOS)
......@@ -335,7 +336,7 @@ MessageType GetStatusLabels(Profile* profile,
#if !defined(OS_CHROMEOS)
AvatarSyncErrorType GetMessagesForAvatarSyncError(
Profile* profile,
const SigninManagerBase& signin,
const identity::IdentityManager& identity_manager,
int* content_string_id,
int* button_string_id) {
const ProfileSyncService* service =
......@@ -403,7 +404,8 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError(
}
// Check for a sync confirmation error.
if (signin.IsAuthenticated() && service->IsSyncConfirmationNeeded()) {
if (identity_manager.HasPrimaryAccount() &&
service->IsSyncConfirmationNeeded()) {
*content_string_id = IDS_SYNC_SETTINGS_NOT_CONFIRMED;
*button_string_id = IDS_SYNC_ERROR_USER_MENU_CONFIRM_SYNC_SETTINGS_BUTTON;
return SETTINGS_UNCONFIRMED_ERROR;
......
......@@ -11,6 +11,10 @@
class Profile;
class SigninManagerBase;
namespace identity {
class IdentityManager;
}
namespace browser_sync {
class ProfileSyncService;
} // namespace browser_sync
......@@ -69,7 +73,7 @@ MessageType GetStatusLabels(Profile* profile,
// exposed to the user through the titlebar avatar button.
AvatarSyncErrorType GetMessagesForAvatarSyncError(
Profile* profile,
const SigninManagerBase& signin,
const identity::IdentityManager& identity_manager,
int* content_string_id,
int* button_string_id);
#endif
......
......@@ -374,9 +374,8 @@ AvatarToolbarButton::SyncState AvatarToolbarButton::GetSyncState() const {
int unused;
const bool should_show_sync_paused_ui =
AccountConsistencyModeManager::IsDiceEnabledForProfile(profile_) &&
// TODO(http://crbug.com/890796): Migrate to passing an IdentityManager
sync_ui_util::GetMessagesForAvatarSyncError(
profile_, *SigninManagerFactory::GetForProfile(profile_), &unused,
profile_, *IdentityManagerFactory::GetForProfile(profile_), &unused,
&unused) == sync_ui_util::AUTH_ERROR;
return should_show_sync_paused_ui ? SyncState::kPaused : SyncState::kError;
}
......
......@@ -29,7 +29,6 @@
#include "chrome/browser/signin/identity_manager_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_manager_factory.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
......@@ -69,6 +68,7 @@
#include "components/signin/core/browser/signin_header_helper.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/signin/core/browser/signin_metrics.h"
#include "components/signin/core/browser/signin_pref_names.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/render_widget_host_view.h"
#include "services/identity/public/cpp/identity_manager.h"
......@@ -198,7 +198,7 @@ BadgedProfilePhoto::BadgeType GetProfileBadgeType(Profile* profile) {
// policy.
if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile) &&
profile->IsSyncAllowed() &&
SigninManagerFactory::GetForProfile(profile)->IsAuthenticated()) {
IdentityManagerFactory::GetForProfile(profile)->HasPrimaryAccount()) {
return BadgedProfilePhoto::BADGE_TYPE_SYNC_COMPLETE;
}
return BadgedProfilePhoto::BADGE_TYPE_NONE;
......@@ -673,9 +673,11 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
browser_sync::ProfileSyncService::SyncEvent(
browser_sync::ProfileSyncService::STOP_FROM_OPTIONS);
}
SigninManagerFactory::GetForProfile(browser_->profile())
->SignOut(signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS,
signin_metrics::SignoutDelete::IGNORE_METRIC);
IdentityManagerFactory::GetForProfile(browser_->profile())
->ClearPrimaryAccount(
identity::IdentityManager::ClearAccountTokensAction::kDefault,
signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS,
signin_metrics::SignoutDelete::IGNORE_METRIC);
ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN);
break;
case sync_ui_util::SUPERVISED_USER_AUTH_ERROR:
......@@ -707,15 +709,15 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
// The account management view is only available with the
// --account-consistency=mirror flag.
bool account_management_available =
SigninManagerFactory::GetForProfile(profile)->IsAuthenticated() &&
IdentityManagerFactory::GetForProfile(profile)->HasPrimaryAccount() &&
AccountConsistencyModeManager::IsMirrorEnabledForProfile(profile);
ShowViewFromMode(account_management_available ?
profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER);
} else if (sender == current_profile_card_) {
if (dice_enabled_ &&
SigninManagerFactory::GetForProfile(browser_->profile())
->IsAuthenticated()) {
IdentityManagerFactory::GetForProfile(browser_->profile())
->HasPrimaryAccount()) {
chrome::ShowSettingsSubPage(browser_, chrome::kPeopleSubPage);
} else {
// Open settings to edit profile name and image. The profile doesn't need
......@@ -911,11 +913,11 @@ views::View* ProfileChooserView::CreateProfileChooserView(
views::View* ProfileChooserView::CreateSyncErrorViewIfNeeded(
const AvatarMenu::Item& avatar_item) {
int content_string_id, button_string_id;
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(browser_->profile());
auto* identity_manager =
IdentityManagerFactory::GetForProfile(browser_->profile());
sync_ui_util::AvatarSyncErrorType error =
sync_ui_util::GetMessagesForAvatarSyncError(
browser_->profile(), *signin_manager, &content_string_id,
browser_->profile(), *identity_manager, &content_string_id,
&button_string_id);
if (error == sync_ui_util::NO_SYNC_ERROR)
return nullptr;
......@@ -1122,8 +1124,9 @@ views::View* ProfileChooserView::CreateCurrentProfileView(
return view;
}
if (!dice_enabled_ &&
SigninManagerFactory::GetForProfile(profile)->IsSigninAllowed()) {
bool is_signin_allowed =
profile->GetPrefs()->GetBoolean(prefs::kSigninAllowed);
if (!dice_enabled_ && is_signin_allowed) {
views::View* extra_links_view = new views::View();
extra_links_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kVertical,
......@@ -1541,8 +1544,9 @@ views::View* ProfileChooserView::CreateAccountRemovalView() {
views::CreateEmptyBorder(0, dialog_insets.left(),
dialog_insets.bottom(), dialog_insets.right()));
const std::string& primary_account = SigninManagerFactory::GetForProfile(
browser_->profile())->GetAuthenticatedAccountId();
const std::string& primary_account =
IdentityManagerFactory::GetForProfile(browser_->profile())
->GetPrimaryAccountId();
bool is_primary_account = primary_account == account_id_to_remove_;
const int unrelated_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