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.
......
...@@ -2,40 +2,33 @@ ...@@ -2,40 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <stddef.h>
#include <memory> #include <memory>
#include <set> #include <set>
#include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h" #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/signin/signin_error_controller_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/sync/sync_ui_util.h" #include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/sync/driver/test_sync_service.h" #include "components/sync/driver/test_sync_service.h"
#include "content/public/test/test_browser_thread.h" #include "components/sync/engine/sync_engine.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "services/identity/public/cpp/identity_manager.h" #include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_environment.h" #include "services/identity/public/cpp/identity_test_environment.h"
#include "services/identity/public/cpp/identity_test_utils.h" #include "services/identity/public/cpp/identity_test_utils.h"
#include "services/identity/public/cpp/primary_account_mutator.h" #include "services/identity/public/cpp/primary_account_mutator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
using syncer::TestSyncService; using syncer::TestSyncService;
using ::testing::_;
using ::testing::AtMost; namespace {
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::SetArgPointee;
// A number of distinct states of the SyncService can be generated for tests. // A number of distinct states of the SyncService can be generated for tests.
enum DistinctState { enum DistinctState {
...@@ -51,8 +44,6 @@ enum DistinctState { ...@@ -51,8 +44,6 @@ enum DistinctState {
NUMBER_OF_STATUS_CASES NUMBER_OF_STATUS_CASES
}; };
namespace {
const char kTestGaiaId[] = "gaia-id-test_user@test.com"; const char kTestGaiaId[] = "gaia-id-test_user@test.com";
const char kTestUser[] = "test_user@test.com"; const char kTestUser[] = "test_user@test.com";
const char kRefreshToken[] = "refresh_token"; const char kRefreshToken[] = "refresh_token";
...@@ -203,13 +194,31 @@ sync_ui_util::ActionType GetActionTypeforDistinctCase(int case_number) { ...@@ -203,13 +194,31 @@ sync_ui_util::ActionType GetActionTypeforDistinctCase(int case_number) {
} }
} }
std::unique_ptr<KeyedService> BuildTestSyncService(
content::BrowserContext* context) {
return std::make_unique<TestSyncService>();
}
std::unique_ptr<TestingProfile> BuildTestingProfile() {
return IdentityTestEnvironmentProfileAdaptor::
CreateProfileForIdentityTestEnvironment(
{{ProfileSyncServiceFactory::GetInstance(),
base::BindRepeating(&BuildTestSyncService)}});
}
std::unique_ptr<TestingProfile> BuildSignedInTestingProfile() {
std::unique_ptr<TestingProfile> profile = BuildTestingProfile();
IdentityTestEnvironmentProfileAdaptor identity_adaptor(profile.get());
identity_adaptor.identity_test_env()->SetPrimaryAccount(kTestUser);
return profile;
}
// This test ensures that each distinctive SyncService status will return a // This test ensures that each distinctive SyncService status will return a
// unique combination of status and link messages from GetStatusLabels(). // unique combination of status and link messages from GetStatusLabels().
TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
std::set<base::string16> messages; std::set<base::string16> messages;
for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) {
std::unique_ptr<Profile> profile = IdentityTestEnvironmentProfileAdaptor:: std::unique_ptr<Profile> profile = BuildTestingProfile();
CreateProfileForIdentityTestEnvironment();
IdentityTestEnvironmentProfileAdaptor env_adaptor(profile.get()); IdentityTestEnvironmentProfileAdaptor env_adaptor(profile.get());
identity::IdentityTestEnvironment* environment = identity::IdentityTestEnvironment* environment =
...@@ -227,13 +236,14 @@ TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { ...@@ -227,13 +236,14 @@ TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
// Need a primary account signed in before calling GetDistinctCase(). // Need a primary account signed in before calling GetDistinctCase().
environment->MakePrimaryAccountAvailable(kTestUser); environment->MakePrimaryAccountAvailable(kTestUser);
TestSyncService service; TestSyncService* service = static_cast<TestSyncService*>(
GetDistinctCase(&service, identity_manager, idx); ProfileSyncServiceFactory::GetSyncServiceForProfile(profile.get()));
GetDistinctCase(service, identity_manager, idx);
base::string16 status_label; base::string16 status_label;
base::string16 link_label; base::string16 link_label;
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
sync_ui_util::GetStatusLabels(profile.get(), &service, identity_manager, sync_ui_util::GetStatusLabels(profile.get(), &status_label, &link_label,
&status_label, &link_label, &action_type); &action_type);
EXPECT_EQ(GetActionTypeforDistinctCase(idx), action_type) EXPECT_EQ(GetActionTypeforDistinctCase(idx), action_type)
<< "Wrong action returned for case #" << idx; << "Wrong action returned for case #" << idx;
...@@ -256,22 +266,21 @@ TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { ...@@ -256,22 +266,21 @@ TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
} }
TEST_F(SyncUIUtilTest, UnrecoverableErrorWithActionableError) { TEST_F(SyncUIUtilTest, UnrecoverableErrorWithActionableError) {
std::unique_ptr<Profile> profile(MakeSignedInTestingProfile()); std::unique_ptr<Profile> profile = BuildSignedInTestingProfile();
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile.get());
TestSyncService service; TestSyncService* service = static_cast<TestSyncService*>(
service.SetFirstSetupComplete(true); ProfileSyncServiceFactory::GetSyncServiceForProfile(profile.get()));
service.SetDisableReasons( service->SetFirstSetupComplete(true);
service->SetDisableReasons(
syncer::SyncService::DISABLE_REASON_UNRECOVERABLE_ERROR); syncer::SyncService::DISABLE_REASON_UNRECOVERABLE_ERROR);
// First time action is not set. We should get unrecoverable error. // First time action is not set. We should get unrecoverable error.
service.SetDetailedSyncStatus(true, syncer::SyncStatus()); service->SetDetailedSyncStatus(true, syncer::SyncStatus());
base::string16 link_label; base::string16 link_label;
base::string16 unrecoverable_error_status_label; base::string16 unrecoverable_error_status_label;
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
sync_ui_util::GetStatusLabels(profile.get(), &service, identity_manager, sync_ui_util::GetStatusLabels(profile.get(),
&unrecoverable_error_status_label, &link_label, &unrecoverable_error_status_label, &link_label,
&action_type); &action_type);
...@@ -282,11 +291,10 @@ TEST_F(SyncUIUtilTest, UnrecoverableErrorWithActionableError) { ...@@ -282,11 +291,10 @@ TEST_F(SyncUIUtilTest, UnrecoverableErrorWithActionableError) {
// from previous one. // from previous one.
syncer::SyncStatus status; syncer::SyncStatus status;
status.sync_protocol_error.action = syncer::UPGRADE_CLIENT; status.sync_protocol_error.action = syncer::UPGRADE_CLIENT;
service.SetDetailedSyncStatus(true, status); service->SetDetailedSyncStatus(true, status);
base::string16 upgrade_client_status_label; base::string16 upgrade_client_status_label;
sync_ui_util::GetStatusLabels(profile.get(), &service, identity_manager, sync_ui_util::GetStatusLabels(profile.get(), &upgrade_client_status_label,
&upgrade_client_status_label, &link_label, &link_label, &action_type);
&action_type);
// Expect an explicit 'client upgrade' action. // Expect an explicit 'client upgrade' action.
EXPECT_EQ(sync_ui_util::UPGRADE_CLIENT, action_type); EXPECT_EQ(sync_ui_util::UPGRADE_CLIENT, action_type);
...@@ -294,24 +302,23 @@ TEST_F(SyncUIUtilTest, UnrecoverableErrorWithActionableError) { ...@@ -294,24 +302,23 @@ TEST_F(SyncUIUtilTest, UnrecoverableErrorWithActionableError) {
} }
TEST_F(SyncUIUtilTest, ActionableErrorWithPassiveMessage) { TEST_F(SyncUIUtilTest, ActionableErrorWithPassiveMessage) {
std::unique_ptr<Profile> profile(MakeSignedInTestingProfile()); std::unique_ptr<Profile> profile = BuildSignedInTestingProfile();
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile.get());
TestSyncService service; TestSyncService* service = static_cast<TestSyncService*>(
service.SetFirstSetupComplete(true); ProfileSyncServiceFactory::GetSyncServiceForProfile(profile.get()));
service.SetDisableReasons( service->SetFirstSetupComplete(true);
service->SetDisableReasons(
syncer::SyncService::DISABLE_REASON_UNRECOVERABLE_ERROR); syncer::SyncService::DISABLE_REASON_UNRECOVERABLE_ERROR);
// Set action to UPGRADE_CLIENT. // Set action to UPGRADE_CLIENT.
syncer::SyncStatus status; syncer::SyncStatus status;
status.sync_protocol_error.action = syncer::UPGRADE_CLIENT; status.sync_protocol_error.action = syncer::UPGRADE_CLIENT;
service.SetDetailedSyncStatus(true, status); service->SetDetailedSyncStatus(true, status);
base::string16 first_actionable_error_status_label; base::string16 first_actionable_error_status_label;
base::string16 link_label; base::string16 link_label;
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
sync_ui_util::GetStatusLabels(profile.get(), &service, identity_manager, sync_ui_util::GetStatusLabels(profile.get(),
&first_actionable_error_status_label, &first_actionable_error_status_label,
&link_label, &action_type); &link_label, &action_type);
// Expect a 'client upgrade' call to action. // Expect a 'client upgrade' call to action.
...@@ -319,11 +326,11 @@ TEST_F(SyncUIUtilTest, ActionableErrorWithPassiveMessage) { ...@@ -319,11 +326,11 @@ TEST_F(SyncUIUtilTest, ActionableErrorWithPassiveMessage) {
// This time set action to ENABLE_SYNC_ON_ACCOUNT. // This time set action to ENABLE_SYNC_ON_ACCOUNT.
status.sync_protocol_error.action = syncer::ENABLE_SYNC_ON_ACCOUNT; status.sync_protocol_error.action = syncer::ENABLE_SYNC_ON_ACCOUNT;
service.SetDetailedSyncStatus(true, status); service->SetDetailedSyncStatus(true, status);
base::string16 second_actionable_error_status_label; base::string16 second_actionable_error_status_label;
action_type = sync_ui_util::NO_ACTION; action_type = sync_ui_util::NO_ACTION;
sync_ui_util::GetStatusLabels(profile.get(), &service, identity_manager, sync_ui_util::GetStatusLabels(profile.get(),
&second_actionable_error_status_label, &second_actionable_error_status_label,
&link_label, &action_type); &link_label, &action_type);
// Expect a passive message instead of a call to action. // Expect a passive message instead of a call to action.
...@@ -334,21 +341,19 @@ TEST_F(SyncUIUtilTest, ActionableErrorWithPassiveMessage) { ...@@ -334,21 +341,19 @@ TEST_F(SyncUIUtilTest, ActionableErrorWithPassiveMessage) {
} }
TEST_F(SyncUIUtilTest, SyncSettingsConfirmationNeededTest) { TEST_F(SyncUIUtilTest, SyncSettingsConfirmationNeededTest) {
std::unique_ptr<Profile> profile(MakeSignedInTestingProfile()); std::unique_ptr<Profile> profile = BuildSignedInTestingProfile();
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile.get());
TestSyncService service; TestSyncService* service = static_cast<TestSyncService*>(
service.SetFirstSetupComplete(false); ProfileSyncServiceFactory::GetSyncServiceForProfile(profile.get()));
ASSERT_TRUE(sync_ui_util::ShouldRequestSyncConfirmation(&service)); service->SetFirstSetupComplete(false);
ASSERT_TRUE(sync_ui_util::ShouldRequestSyncConfirmation(service));
base::string16 actionable_error_status_label; base::string16 actionable_error_status_label;
base::string16 link_label; base::string16 link_label;
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
sync_ui_util::GetStatusLabels(profile.get(), &service, identity_manager, sync_ui_util::GetStatusLabels(profile.get(), &actionable_error_status_label,
&actionable_error_status_label, &link_label, &link_label, &action_type);
&action_type);
EXPECT_EQ(action_type, sync_ui_util::CONFIRM_SYNC_SETTINGS); EXPECT_EQ(action_type, sync_ui_util::CONFIRM_SYNC_SETTINGS);
} }
...@@ -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