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

Convert chrome/browser/sync/sync_ui_util.cc to IdentityManager

Also update all the callers and adapt the unit tests to stop using a custom
FakeSigninManagerBase and PO2TS, using IdentityManager and related test
utilities (e.g. IdentityTestEnvironment, PrimaryAccountMutator) instead,
so that the actual code being ported to can be tested. This means that
the STATUS_CASE_AUTHENTICATING case can't be tested anymore for ChromeOS,
but hopefully that should not be an issue since ChromeOS doesn't support
signin-in/out the primary account anyway.

Bug: 890796
Change-Id: Iadcb5440eef126a801dd6c0cd145cbbe0bfb0b6d
Reviewed-on: https://chromium-review.googlesource.com/c/1362902Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#616094}
parent 89ae4532
......@@ -12,7 +12,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/browsing_data/core/pref_names.h"
......@@ -61,7 +60,7 @@ bool ShouldShowCookieException(Profile* profile) {
sync_ui_util::MessageType sync_status = sync_ui_util::GetStatus(
profile,
ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile),
*SigninManagerFactory::GetForProfile(profile));
IdentityManagerFactory::GetForProfile(profile));
return sync_status == sync_ui_util::SYNCED;
}
#endif
......
......@@ -19,19 +19,19 @@
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_reconcilor_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "components/browsing_data/core/pref_names.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_remover.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
#include "services/identity/public/cpp/identity_manager.h"
using content::BrowserThread;
using browsing_data::ClearBrowsingDataTab;
......@@ -132,10 +132,10 @@ bool IsRemovalPermitted(int removal_mask, PrefService* prefs) {
bool IsSyncRunning(Profile* profile) {
syncer::SyncService* sync_service =
ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile);
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile);
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
sync_ui_util::MessageType sync_status =
sync_ui_util::GetStatus(profile, sync_service, *signin_manager);
sync_ui_util::GetStatus(profile, sync_service, identity_manager);
return sync_status == sync_ui_util::SYNCED;
}
} // namespace
......
......@@ -18,6 +18,7 @@
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_reconcilor_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/scoped_account_consistency.h"
#include "chrome/browser/signin/signin_manager_factory.h"
......@@ -40,6 +41,7 @@
#include "google_apis/gaia/google_service_auth_error.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "net/cookies/canonical_cookie.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "url/gurl.h"
using extension_function_test_utils::RunFunctionAndReturnError;
......@@ -427,8 +429,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, Syncing) {
browser_sync::ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(profile);
sync_service->GetUserSettings()->SetFirstSetupComplete();
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
sync_ui_util::MessageType sync_status =
sync_ui_util::GetStatus(profile, sync_service, *signin_manager);
sync_ui_util::GetStatus(profile, sync_service, identity_manager);
ASSERT_EQ(sync_ui_util::SYNCED, sync_status);
// Clear browsing data.
scoped_refptr<BrowsingDataRemoveFunction> function =
......@@ -461,9 +466,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SyncError) {
GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_SERVER));
// Sync is not running.
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
sync_ui_util::MessageType sync_status = sync_ui_util::GetStatus(
profile, ProfileSyncServiceFactory::GetForProfile(profile),
*signin_manager);
identity_manager);
ASSERT_NE(sync_ui_util::SYNCED, sync_status);
// Clear browsing data.
scoped_refptr<BrowsingDataRemoveFunction> function =
......
......@@ -14,11 +14,11 @@
#include "components/browser_sync/profile_sync_service.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "components/strings/grit/components_strings.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 "services/identity/public/cpp/primary_account_mutator.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(OS_CHROMEOS)
......@@ -33,7 +33,6 @@ namespace {
// and can connect to the sync server. If the user hasn't yet authenticated, an
// empty string is returned.
base::string16 GetSyncedStateStatusLabel(const syncer::SyncService* service,
const SigninManagerBase& signin,
StatusLabelStyle style,
bool sync_everything) {
if (!service || service->HasDisableReason(
......@@ -125,7 +124,6 @@ void GetStatusForUnrecoverableError(Profile* profile,
// Depending on the authentication state, returns labels to be used to display
// information about the sync status.
void GetStatusForAuthError(Profile* profile,
const SigninManagerBase& signin_manager,
base::string16* status_label,
base::string16* link_label,
ActionType* action_type) {
......@@ -164,7 +162,7 @@ void GetStatusForAuthError(Profile* profile,
// status_label and link_label must either be both null or both non-null.
MessageType GetStatusInfo(Profile* profile,
const syncer::SyncService* service,
const SigninManagerBase& signin,
identity::IdentityManager* identity_manager,
StatusLabelStyle style,
base::string16* status_label,
base::string16* link_label,
......@@ -173,9 +171,12 @@ MessageType GetStatusInfo(Profile* profile,
MessageType result_type(SYNCED);
if (!signin.IsAuthenticated())
if (!identity_manager->HasPrimaryAccount())
return PRE_SYNCED;
// Needed to check the state of the authentication process below.
auto* primary_account_mutator = identity_manager->GetPrimaryAccountMutator();
if (!service || service->GetUserSettings()->IsFirstSetupComplete() ||
service->HasDisableReason(
syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY) ||
......@@ -193,7 +194,8 @@ MessageType GetStatusInfo(Profile* profile,
}
// For auth errors first check if an auth is in progress.
if (signin.AuthInProgress()) {
if (primary_account_mutator &&
primary_account_mutator->LegacyIsPrimaryAccountAuthInProgress()) {
if (status_label) {
status_label->assign(
l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
......@@ -211,8 +213,7 @@ MessageType GetStatusInfo(Profile* profile,
SigninErrorControllerFactory::GetForProfile(profile)->auth_error();
if (auth_error.state() != GoogleServiceAuthError::NONE) {
if (status_label && link_label) {
GetStatusForAuthError(profile, signin, status_label, link_label,
action_type);
GetStatusForAuthError(profile, status_label, link_label, action_type);
}
return SYNC_ERROR;
}
......@@ -247,8 +248,8 @@ MessageType GetStatusInfo(Profile* profile,
syncer::SyncService::DISABLE_REASON_USER_CHOICE) &&
status.sync_protocol_error.error_type == syncer::NOT_MY_BIRTHDAY) {
if (status_label) {
status_label->assign(GetSyncedStateStatusLabel(service, signin, style,
sync_everything));
status_label->assign(
GetSyncedStateStatusLabel(service, style, sync_everything));
}
return PRE_SYNCED;
}
......@@ -257,7 +258,7 @@ MessageType GetStatusInfo(Profile* profile,
// There is no error. Display "Last synced..." message.
if (status_label) {
status_label->assign(
GetSyncedStateStatusLabel(service, signin, style, sync_everything));
GetSyncedStateStatusLabel(service, style, sync_everything));
}
return SYNCED;
} else {
......@@ -273,7 +274,8 @@ MessageType GetStatusInfo(Profile* profile,
status_label->assign(
l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS));
}
if (signin.AuthInProgress()) {
if (primary_account_mutator &&
primary_account_mutator->LegacyIsPrimaryAccountAuthInProgress()) {
if (status_label) {
status_label->assign(
l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
......@@ -281,8 +283,7 @@ MessageType GetStatusInfo(Profile* profile,
} else if (auth_error.state() != GoogleServiceAuthError::NONE &&
auth_error.state() != GoogleServiceAuthError::TWO_FACTOR) {
if (status_label && link_label) {
GetStatusForAuthError(profile, signin, status_label, link_label,
action_type);
GetStatusForAuthError(profile, status_label, link_label, action_type);
}
result_type = SYNC_ERROR;
}
......@@ -292,7 +293,7 @@ MessageType GetStatusInfo(Profile* profile,
GetStatusForUnrecoverableError(profile, service, status_label,
link_label, action_type);
}
} else if (signin.IsAuthenticated()) {
} else if (identity_manager->HasPrimaryAccount()) {
if (ShouldRequestSyncConfirmation(service)) {
if (status_label && link_label) {
status_label->assign(
......@@ -319,20 +320,20 @@ MessageType GetStatusInfo(Profile* profile,
MessageType GetStatusLabels(Profile* profile,
const syncer::SyncService* service,
const SigninManagerBase& signin,
identity::IdentityManager* identity_manager,
base::string16* status_label,
base::string16* link_label,
ActionType* action_type) {
DCHECK(status_label);
DCHECK(link_label);
return GetStatusInfo(profile, service, signin, PLAIN_TEXT, status_label,
link_label, action_type);
return GetStatusInfo(profile, service, identity_manager, PLAIN_TEXT,
status_label, link_label, action_type);
}
#if !defined(OS_CHROMEOS)
AvatarSyncErrorType GetMessagesForAvatarSyncError(
Profile* profile,
const identity::IdentityManager& identity_manager,
identity::IdentityManager* identity_manager,
int* content_string_id,
int* button_string_id) {
const syncer::SyncService* service =
......@@ -400,7 +401,7 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError(
}
// Check for a sync confirmation error.
if (identity_manager.HasPrimaryAccount() &&
if (identity_manager->HasPrimaryAccount() &&
ShouldRequestSyncConfirmation(service)) {
*content_string_id = IDS_SYNC_SETTINGS_NOT_CONFIRMED;
*button_string_id = IDS_SYNC_ERROR_USER_MENU_CONFIRM_SYNC_SETTINGS_BUTTON;
......@@ -415,10 +416,10 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError(
MessageType GetStatus(Profile* profile,
const syncer::SyncService* service,
const SigninManagerBase& signin) {
identity::IdentityManager* identity_manager) {
ActionType action_type = NO_ACTION;
return GetStatusInfo(profile, service, signin, WITH_HTML, nullptr, nullptr,
&action_type);
return GetStatusInfo(profile, service, identity_manager, WITH_HTML, nullptr,
nullptr, &action_type);
}
bool ShouldRequestSyncConfirmation(const syncer::SyncService* service) {
......
......@@ -9,7 +9,6 @@
#include "build/build_config.h"
class Profile;
class SigninManagerBase;
namespace identity {
class IdentityManager;
......@@ -60,7 +59,7 @@ enum AvatarSyncErrorType {
// by querying |service|.
MessageType GetStatusLabels(Profile* profile,
const syncer::SyncService* service,
const SigninManagerBase& signin,
identity::IdentityManager* identity_manager,
base::string16* status_label,
base::string16* link_label,
ActionType* action_type);
......@@ -70,14 +69,14 @@ MessageType GetStatusLabels(Profile* profile,
// exposed to the user through the titlebar avatar button.
AvatarSyncErrorType GetMessagesForAvatarSyncError(
Profile* profile,
const identity::IdentityManager& identity_manager,
identity::IdentityManager* identity_manager,
int* content_string_id,
int* button_string_id);
#endif
MessageType GetStatus(Profile* profile,
const syncer::SyncService* service,
const SigninManagerBase& signin);
identity::IdentityManager* identity_manager);
// Whether sync is currently blocked from starting because the sync
// confirmation dialog hasn't been shown. Note that once the dialog is
......
......@@ -373,7 +373,7 @@ AvatarToolbarButton::SyncState AvatarToolbarButton::GetSyncState() const {
const bool should_show_sync_paused_ui =
AccountConsistencyModeManager::IsDiceEnabledForProfile(profile_) &&
sync_ui_util::GetMessagesForAvatarSyncError(
profile_, *IdentityManagerFactory::GetForProfile(profile_), &unused,
profile_, IdentityManagerFactory::GetForProfile(profile_), &unused,
&unused) == sync_ui_util::AUTH_ERROR;
return should_show_sync_paused_ui ? SyncState::kPaused : SyncState::kError;
}
......
......@@ -928,7 +928,7 @@ views::View* ProfileChooserView::CreateSyncErrorViewIfNeeded(
IdentityManagerFactory::GetForProfile(browser_->profile());
sync_ui_util::AvatarSyncErrorType error =
sync_ui_util::GetMessagesForAvatarSyncError(
browser_->profile(), *identity_manager, &content_string_id,
browser_->profile(), identity_manager, &content_string_id,
&button_string_id);
if (error == sync_ui_util::NO_SYNC_ERROR)
return nullptr;
......
......@@ -968,8 +968,8 @@ PeopleHandler::GetSyncStatusDictionary() {
base::string16 link_label;
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
bool status_has_error =
sync_ui_util::GetStatusLabels(profile_, service, *signin, &status_label,
&link_label,
sync_ui_util::GetStatusLabels(profile_, service, identity_manager,
&status_label, &link_label,
&action_type) == sync_ui_util::SYNC_ERROR;
sync_status->SetString("statusText", status_label);
sync_status->SetString("statusActionText", link_label);
......
......@@ -20,7 +20,6 @@
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/signin/account_reconcilor_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/common/channel_info.h"
......@@ -256,7 +255,7 @@ void ClearBrowsingDataHandler::HandleClearBrowsingData(
std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion>
scoped_data_deletion;
sync_ui_util::MessageType sync_status = sync_ui_util::GetStatus(
profile_, sync_service_, *SigninManagerFactory::GetForProfile(profile_));
profile_, sync_service_, IdentityManagerFactory::GetForProfile(profile_));
if (sync_status == sync_ui_util::SYNCED) {
scoped_data_deletion = AccountReconcilorFactory::GetForProfile(profile_)
->GetScopedSyncDataDeletion();
......
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