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) { ...@@ -54,12 +54,7 @@ bool ShouldShowCookieException(Profile* profile) {
} }
#if BUILDFLAG(ENABLE_DICE_SUPPORT) #if BUILDFLAG(ENABLE_DICE_SUPPORT)
if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile)) { if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile)) {
// TODO(http://crbug.com/890796): Migrate this part once sync_ui_util has return sync_ui_util::GetStatus(profile) == sync_ui_util::SYNCED;
// 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;
} }
#endif #endif
return false; return false;
......
...@@ -149,13 +149,7 @@ bool IsRemovalPermitted(int removal_mask, PrefService* prefs) { ...@@ -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). // Returns true if Sync is currently running (i.e. enabled and not in error).
bool IsSyncRunning(Profile* profile) { bool IsSyncRunning(Profile* profile) {
syncer::SyncService* sync_service = return sync_ui_util::GetStatus(profile) == sync_ui_util::SYNCED;
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;
} }
} // namespace } // namespace
......
...@@ -422,9 +422,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, Syncing) { ...@@ -422,9 +422,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, Syncing) {
ProfileSyncServiceFactory::GetForProfile(profile); ProfileSyncServiceFactory::GetForProfile(profile);
sync_service->GetUserSettings()->SetFirstSetupComplete(); sync_service->GetUserSettings()->SetFirstSetupComplete();
sync_ui_util::MessageType sync_status = ASSERT_EQ(sync_ui_util::SYNCED, sync_ui_util::GetStatus(profile));
sync_ui_util::GetStatus(profile, sync_service, identity_manager);
ASSERT_EQ(sync_ui_util::SYNCED, sync_status);
// Clear browsing data. // Clear browsing data.
auto function = base::MakeRefCounted<BrowsingDataRemoveFunction>(); auto function = base::MakeRefCounted<BrowsingDataRemoveFunction>();
EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
...@@ -459,10 +457,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SyncError) { ...@@ -459,10 +457,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SyncError) {
CREDENTIALS_REJECTED_BY_SERVER)); CREDENTIALS_REJECTED_BY_SERVER));
// Sync is not running. // Sync is not running.
sync_ui_util::MessageType sync_status = sync_ui_util::GetStatus( ASSERT_NE(sync_ui_util::SYNCED, sync_ui_util::GetStatus(profile));
profile, ProfileSyncServiceFactory::GetForProfile(profile),
identity_manager);
ASSERT_NE(sync_ui_util::SYNCED, sync_status);
// Clear browsing data. // Clear browsing data.
auto function = base::MakeRefCounted<BrowsingDataRemoveFunction>(); auto function = base::MakeRefCounted<BrowsingDataRemoveFunction>();
EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
......
...@@ -72,18 +72,6 @@ ProfileSyncService::InitParams CreateProfileSyncServiceParamsForTest( ...@@ -72,18 +72,6 @@ ProfileSyncService::InitParams CreateProfileSyncServiceParamsForTest(
return init_params; 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( std::unique_ptr<KeyedService> BuildMockProfileSyncService(
content::BrowserContext* context) { content::BrowserContext* context) {
return std::make_unique<NiceMock<browser_sync::ProfileSyncServiceMock>>( return std::make_unique<NiceMock<browser_sync::ProfileSyncServiceMock>>(
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
class KeyedService; class KeyedService;
class Profile; class Profile;
class TestingProfile;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
...@@ -49,10 +48,6 @@ CreateProfileSyncServiceParamsForTest( ...@@ -49,10 +48,6 @@ CreateProfileSyncServiceParamsForTest(
std::unique_ptr<syncer::SyncClient> sync_client, std::unique_ptr<syncer::SyncClient> sync_client,
Profile* profile); 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 // Helper routine to be used in conjunction with
// BrowserContextKeyedServiceFactory::SetTestingFactory(). // BrowserContextKeyedServiceFactory::SetTestingFactory().
std::unique_ptr<KeyedService> BuildMockProfileSyncService( std::unique_ptr<KeyedService> BuildMockProfileSyncService(
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/sync/sync_ui_util.h" #include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/profiles/profile.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_error_controller_factory.h"
#include "chrome/browser/signin/signin_util.h" #include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
...@@ -286,13 +287,14 @@ MessageType GetStatusLabelsImpl(const syncer::SyncService* service, ...@@ -286,13 +287,14 @@ MessageType GetStatusLabelsImpl(const syncer::SyncService* service,
} // namespace } // namespace
MessageType GetStatusLabels(Profile* profile, MessageType GetStatusLabels(Profile* profile,
const syncer::SyncService* service,
identity::IdentityManager* identity_manager,
base::string16* status_label, base::string16* status_label,
base::string16* link_label, base::string16* link_label,
ActionType* action_type) { 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 = const bool is_user_signout_allowed =
signin_util::IsUserSignoutAllowedForProfile(profile); signin_util::IsUserSignoutAllowedForProfile(profile);
GoogleServiceAuthError auth_error = GoogleServiceAuthError auth_error =
...@@ -301,6 +303,12 @@ MessageType GetStatusLabels(Profile* profile, ...@@ -301,6 +303,12 @@ MessageType GetStatusLabels(Profile* profile,
auth_error, status_label, link_label, action_type); 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) #if !defined(OS_CHROMEOS)
AvatarSyncErrorType GetMessagesForAvatarSyncError( AvatarSyncErrorType GetMessagesForAvatarSyncError(
Profile* profile, Profile* profile,
...@@ -375,16 +383,6 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError( ...@@ -375,16 +383,6 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError(
} }
#endif // !defined(OS_CHROMEOS) #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) { bool ShouldRequestSyncConfirmation(const syncer::SyncService* service) {
return !service->IsLocalSyncEnabled() && return !service->IsLocalSyncEnabled() &&
service->GetUserSettings()->IsSyncRequested() && service->GetUserSettings()->IsSyncRequested() &&
......
...@@ -10,10 +10,6 @@ ...@@ -10,10 +10,6 @@
class Profile; class Profile;
namespace identity {
class IdentityManager;
}
namespace syncer { namespace syncer {
class SyncService; class SyncService;
} // namespace syncer } // namespace syncer
...@@ -43,6 +39,8 @@ enum AvatarSyncErrorType { ...@@ -43,6 +39,8 @@ enum AvatarSyncErrorType {
NO_SYNC_ERROR, // No sync error. NO_SYNC_ERROR, // No sync error.
MANAGED_USER_UNRECOVERABLE_ERROR, // Unrecoverable error for managed users. MANAGED_USER_UNRECOVERABLE_ERROR, // Unrecoverable error for managed users.
UNRECOVERABLE_ERROR, // Unrecoverable error for regular users. UNRECOVERABLE_ERROR, // Unrecoverable error for regular users.
// 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. SUPERVISED_USER_AUTH_ERROR, // Auth token error for supervised users.
AUTH_ERROR, // Authentication error. AUTH_ERROR, // Authentication error.
UPGRADE_CLIENT_ERROR, // Out-of-date client error. UPGRADE_CLIENT_ERROR, // Out-of-date client error.
...@@ -50,16 +48,18 @@ enum AvatarSyncErrorType { ...@@ -50,16 +48,18 @@ enum AvatarSyncErrorType {
SETTINGS_UNCONFIRMED_ERROR, // Sync settings dialog not confirmed yet. SETTINGS_UNCONFIRMED_ERROR, // Sync settings dialog not confirmed yet.
}; };
// Create status and link labels for the current status labels and link text // Returns the high-level sync status, and populates status and link label
// by querying |service|. // strings for the current sync status by querying |profile|.
// |status_label| and |link_label| must either be both null or both non-null. // |status_label| and |link_label| must either be both null or both non-null.
MessageType GetStatusLabels(Profile* profile, MessageType GetStatusLabels(Profile* profile,
const syncer::SyncService* service,
identity::IdentityManager* identity_manager,
base::string16* status_label, base::string16* status_label,
base::string16* link_label, base::string16* link_label,
ActionType* action_type); 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) #if !defined(OS_CHROMEOS)
// Gets the error message and button label for the sync errors that should be // Gets the error message and button label for the sync errors that should be
// exposed to the user through the titlebar avatar button. // exposed to the user through the titlebar avatar button.
...@@ -69,10 +69,6 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError( ...@@ -69,10 +69,6 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError(
int* button_string_id); int* button_string_id);
#endif #endif
MessageType GetStatus(Profile* profile,
const syncer::SyncService* service,
identity::IdentityManager* identity_manager);
// Whether sync is currently blocked from starting because the sync // Whether sync is currently blocked from starting because the sync
// confirmation dialog hasn't been shown. Note that once the dialog is // confirmation dialog hasn't been shown. Note that once the dialog is
// showing (i.e. IsFirstSetupInProgress() is true), this will return false. // showing (i.e. IsFirstSetupInProgress() is true), this will return false.
......
...@@ -928,8 +928,7 @@ PeopleHandler::GetSyncStatusDictionary() { ...@@ -928,8 +928,7 @@ PeopleHandler::GetSyncStatusDictionary() {
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
bool status_has_error = bool status_has_error =
sync_ui_util::GetStatusLabels(profile_, service, identity_manager, sync_ui_util::GetStatusLabels(profile_, &status_label, &link_label,
&status_label, &link_label,
&action_type) == sync_ui_util::SYNC_ERROR; &action_type) == sync_ui_util::SYNC_ERROR;
sync_status->SetString("statusText", status_label); sync_status->SetString("statusText", status_label);
sync_status->SetString("statusActionText", link_label); sync_status->SetString("statusActionText", link_label);
......
...@@ -250,9 +250,7 @@ void ClearBrowsingDataHandler::HandleClearBrowsingData( ...@@ -250,9 +250,7 @@ void ClearBrowsingDataHandler::HandleClearBrowsingData(
// However, if Sync is in error, clearing cookies should pause it. // However, if Sync is in error, clearing cookies should pause it.
std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion> std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion>
scoped_data_deletion; scoped_data_deletion;
sync_ui_util::MessageType sync_status = sync_ui_util::GetStatus( if (sync_ui_util::GetStatus(profile_) == sync_ui_util::SYNCED) {
profile_, sync_service_, IdentityManagerFactory::GetForProfile(profile_));
if (sync_status == sync_ui_util::SYNCED) {
scoped_data_deletion = AccountReconcilorFactory::GetForProfile(profile_) scoped_data_deletion = AccountReconcilorFactory::GetForProfile(profile_)
->GetScopedSyncDataDeletion(); ->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