Commit 6aa1608e authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

sync_ui_util: Only take a Profile* param, not other KeyedService*s

If these functions need the Profile anyway, they can just grab any
KeyedServices they require themselves. No need to make clients get them
and pass them in.

Bug: 911153
Change-Id: I31e9ecd3739e06fd2d4c9da00a1727cf9833e116
Reviewed-on: https://chromium-review.googlesource.com/c/1454539Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630705}
parent 25117a7b
......@@ -54,12 +54,7 @@ bool ShouldShowCookieException(Profile* profile) {
}
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile)) {
// TODO(http://crbug.com/890796): Migrate this part once sync_ui_util has
// been migrated to the IdentityManager.
sync_ui_util::MessageType sync_status = sync_ui_util::GetStatus(
profile, ProfileSyncServiceFactory::GetSyncServiceForProfile(profile),
IdentityManagerFactory::GetForProfile(profile));
return sync_status == sync_ui_util::SYNCED;
return sync_ui_util::GetStatus(profile) == sync_ui_util::SYNCED;
}
#endif
return false;
......
......@@ -149,13 +149,7 @@ bool IsRemovalPermitted(int removal_mask, PrefService* prefs) {
// Returns true if Sync is currently running (i.e. enabled and not in error).
bool IsSyncRunning(Profile* profile) {
syncer::SyncService* sync_service =
ProfileSyncServiceFactory::GetSyncServiceForProfile(profile);
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
sync_ui_util::MessageType sync_status =
sync_ui_util::GetStatus(profile, sync_service, identity_manager);
return sync_status == sync_ui_util::SYNCED;
return sync_ui_util::GetStatus(profile) == sync_ui_util::SYNCED;
}
} // namespace
......
......@@ -422,9 +422,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, Syncing) {
ProfileSyncServiceFactory::GetForProfile(profile);
sync_service->GetUserSettings()->SetFirstSetupComplete();
sync_ui_util::MessageType sync_status =
sync_ui_util::GetStatus(profile, sync_service, identity_manager);
ASSERT_EQ(sync_ui_util::SYNCED, sync_status);
ASSERT_EQ(sync_ui_util::SYNCED, sync_ui_util::GetStatus(profile));
// Clear browsing data.
auto function = base::MakeRefCounted<BrowsingDataRemoveFunction>();
EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
......@@ -459,10 +457,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SyncError) {
CREDENTIALS_REJECTED_BY_SERVER));
// Sync is not running.
sync_ui_util::MessageType sync_status = sync_ui_util::GetStatus(
profile, ProfileSyncServiceFactory::GetForProfile(profile),
identity_manager);
ASSERT_NE(sync_ui_util::SYNCED, sync_status);
ASSERT_NE(sync_ui_util::SYNCED, sync_ui_util::GetStatus(profile));
// Clear browsing data.
auto function = base::MakeRefCounted<BrowsingDataRemoveFunction>();
EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
......
......@@ -72,18 +72,6 @@ ProfileSyncService::InitParams CreateProfileSyncServiceParamsForTest(
return init_params;
}
std::unique_ptr<TestingProfile> MakeSignedInTestingProfile() {
std::unique_ptr<TestingProfile> profile =
IdentityTestEnvironmentProfileAdaptor::
CreateProfileForIdentityTestEnvironment();
auto identity_test_env_profile_adaptor =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile.get());
identity_test_env_profile_adaptor->identity_test_env()->SetPrimaryAccount(
"test@mail.com");
return profile;
}
std::unique_ptr<KeyedService> BuildMockProfileSyncService(
content::BrowserContext* context) {
return std::make_unique<NiceMock<browser_sync::ProfileSyncServiceMock>>(
......
......@@ -19,7 +19,6 @@
class KeyedService;
class Profile;
class TestingProfile;
namespace content {
class BrowserContext;
......@@ -49,10 +48,6 @@ CreateProfileSyncServiceParamsForTest(
std::unique_ptr<syncer::SyncClient> sync_client,
Profile* profile);
// A utility used by sync tests to create a TestingProfile with a Google
// Services username stored in a (Testing)PrefService.
std::unique_ptr<TestingProfile> MakeSignedInTestingProfile();
// Helper routine to be used in conjunction with
// BrowserContextKeyedServiceFactory::SetTestingFactory().
std::unique_ptr<KeyedService> BuildMockProfileSyncService(
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
......@@ -286,13 +287,14 @@ MessageType GetStatusLabelsImpl(const syncer::SyncService* service,
} // namespace
MessageType GetStatusLabels(Profile* profile,
const syncer::SyncService* service,
identity::IdentityManager* identity_manager,
base::string16* status_label,
base::string16* link_label,
ActionType* action_type) {
DCHECK(service);
DCHECK(profile);
syncer::SyncService* service =
ProfileSyncServiceFactory::GetSyncServiceForProfile(profile);
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
const bool is_user_signout_allowed =
signin_util::IsUserSignoutAllowedForProfile(profile);
GoogleServiceAuthError auth_error =
......@@ -301,6 +303,12 @@ MessageType GetStatusLabels(Profile* profile,
auth_error, status_label, link_label, action_type);
}
MessageType GetStatus(Profile* profile) {
ActionType action_type = NO_ACTION;
return GetStatusLabels(profile, /*status_label=*/nullptr,
/*link_label=*/nullptr, &action_type);
}
#if !defined(OS_CHROMEOS)
AvatarSyncErrorType GetMessagesForAvatarSyncError(
Profile* profile,
......@@ -375,16 +383,6 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError(
}
#endif // !defined(OS_CHROMEOS)
MessageType GetStatus(Profile* profile,
const syncer::SyncService* service,
identity::IdentityManager* identity_manager) {
DCHECK(service);
ActionType action_type = NO_ACTION;
return GetStatusLabels(profile, service, identity_manager,
/*status_label=*/nullptr, /*link_label=*/nullptr,
&action_type);
}
bool ShouldRequestSyncConfirmation(const syncer::SyncService* service) {
return !service->IsLocalSyncEnabled() &&
service->GetUserSettings()->IsSyncRequested() &&
......
......@@ -10,10 +10,6 @@
class Profile;
namespace identity {
class IdentityManager;
}
namespace syncer {
class SyncService;
} // namespace syncer
......@@ -43,23 +39,27 @@ enum AvatarSyncErrorType {
NO_SYNC_ERROR, // No sync error.
MANAGED_USER_UNRECOVERABLE_ERROR, // Unrecoverable error for managed users.
UNRECOVERABLE_ERROR, // Unrecoverable error for regular users.
SUPERVISED_USER_AUTH_ERROR, // Auth token error for supervised users.
AUTH_ERROR, // Authentication error.
UPGRADE_CLIENT_ERROR, // Out-of-date client error.
PASSPHRASE_ERROR, // Sync passphrase error.
SETTINGS_UNCONFIRMED_ERROR, // Sync settings dialog not confirmed yet.
// TODO(crbug.com/911153): Remove this value. It is never returned, but some
// clients still check for it.
SUPERVISED_USER_AUTH_ERROR, // Auth token error for supervised users.
AUTH_ERROR, // Authentication error.
UPGRADE_CLIENT_ERROR, // Out-of-date client error.
PASSPHRASE_ERROR, // Sync passphrase error.
SETTINGS_UNCONFIRMED_ERROR, // Sync settings dialog not confirmed yet.
};
// Create status and link labels for the current status labels and link text
// by querying |service|.
// Returns the high-level sync status, and populates status and link label
// strings for the current sync status by querying |profile|.
// |status_label| and |link_label| must either be both null or both non-null.
MessageType GetStatusLabels(Profile* profile,
const syncer::SyncService* service,
identity::IdentityManager* identity_manager,
base::string16* status_label,
base::string16* link_label,
ActionType* action_type);
// Convenience version of GetStatusLabels for when you're not interested in the
// actual labels, only in the return value.
MessageType GetStatus(Profile* profile);
#if !defined(OS_CHROMEOS)
// Gets the error message and button label for the sync errors that should be
// exposed to the user through the titlebar avatar button.
......@@ -69,10 +69,6 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError(
int* button_string_id);
#endif
MessageType GetStatus(Profile* profile,
const syncer::SyncService* service,
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
// showing (i.e. IsFirstSetupInProgress() is true), this will return false.
......
......@@ -928,8 +928,7 @@ PeopleHandler::GetSyncStatusDictionary() {
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
bool status_has_error =
sync_ui_util::GetStatusLabels(profile_, service, identity_manager,
&status_label, &link_label,
sync_ui_util::GetStatusLabels(profile_, &status_label, &link_label,
&action_type) == sync_ui_util::SYNC_ERROR;
sync_status->SetString("statusText", status_label);
sync_status->SetString("statusActionText", link_label);
......
......@@ -250,9 +250,7 @@ void ClearBrowsingDataHandler::HandleClearBrowsingData(
// However, if Sync is in error, clearing cookies should pause it.
std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion>
scoped_data_deletion;
sync_ui_util::MessageType sync_status = sync_ui_util::GetStatus(
profile_, sync_service_, IdentityManagerFactory::GetForProfile(profile_));
if (sync_status == sync_ui_util::SYNCED) {
if (sync_ui_util::GetStatus(profile_) == 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