Fix a crash on showing sync setup dialog in guest mode.

Navigating directly to chrome://settings/syncSetup in guest mode is causing a DCHECK() failure, since the ProfileSyncService is NULL in the guest mode.

This patch adds a NULL check on ProfileSyncService to fix the crash
and also terminates the sync setup if the service is NULL.

BUG=370861

Review URL: https://codereview.chromium.org/277433003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269566 0039d316-1c4b-4281-b951-d872f2087c98
parent 83100cd8
...@@ -729,8 +729,11 @@ void SyncSetupHandler::HandleConfigure(const base::ListValue* args) { ...@@ -729,8 +729,11 @@ void SyncSetupHandler::HandleConfigure(const base::ListValue* args) {
} }
void SyncSetupHandler::HandleShowSetupUI(const base::ListValue* args) { void SyncSetupHandler::HandleShowSetupUI(const base::ListValue* args) {
ProfileSyncService* service = GetSyncService(); if (!GetSyncService()) {
DCHECK(service); DLOG(WARNING) << "Cannot display sync UI when sync is disabled";
CloseUI();
return;
}
SigninManagerBase* signin = SigninManagerBase* signin =
SigninManagerFactory::GetForProfile(GetProfile()); SigninManagerFactory::GetForProfile(GetProfile());
......
...@@ -61,6 +61,7 @@ class SyncSetupHandler : public options::OptionsPageUIHandler, ...@@ -61,6 +61,7 @@ class SyncSetupHandler : public options::OptionsPageUIHandler,
friend class SyncSetupHandlerTest; friend class SyncSetupHandlerTest;
FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest,
DisplayConfigureWithBackendDisabledAndCancel); DisplayConfigureWithBackendDisabledAndCancel);
FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, HandleSetupUIWhenSyncDisabled);
FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SelectCustomEncryption); FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SelectCustomEncryption);
FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn); FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn);
FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SuccessfullySetPassphrase); FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SuccessfullySetPassphrase);
......
...@@ -442,6 +442,19 @@ TEST_F(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn) { ...@@ -442,6 +442,19 @@ TEST_F(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn) {
} }
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
// Verifies that the sync setup is terminated correctly when the
// sync is disabled.
TEST_F(SyncSetupHandlerTest, HandleSetupUIWhenSyncDisabled) {
EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true));
handler_->HandleShowSetupUI(NULL);
// Sync setup is closed when sync is disabled.
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
ASSERT_FALSE(handler_->is_configuring_sync());
}
// Verifies that the handler correctly handles a cancellation when // Verifies that the handler correctly handles a cancellation when
// it is displaying the spinner to the user. // it is displaying the spinner to the user.
TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) {
......
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