Commit 63eaca87 authored by Roman Aleksandrov's avatar Roman Aleksandrov Committed by Commit Bot

Reland "SyncConsentScreen: Skip screen properly."

This is a reland of 8cd221ee

Original change's description:
> SyncConsentScreen: Skip screen properly.
> 
> Use new MaybeSkip method for skipping screen. Add tests for UMA stats.
> 
> Bug: 1064561
> Change-Id: I9ddfa0fb5c994f1cb6d6c7abf5e61ca42fd065a3
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2146900
> Commit-Queue: Roman Aleksandrov <raleksandrov@google.com>
> Reviewed-by: Roman Sorokin [CET] <rsorokin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#762370}

Bug: 1064561
Change-Id: Ic9f6be0ea98423614d0ed2a524313679dd99baa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2166163
Commit-Queue: Roman Aleksandrov <raleksandrov@google.com>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762667}
parent c5ff8ec7
......@@ -65,7 +65,7 @@ IN_PROC_BROWSER_TEST_F(LoginUIShelfVisibilityTest, GaiaDialogOpen) {
// Verifies that guest button and add user button are hidden on post-login
// screens, after a user session is started.
IN_PROC_BROWSER_TEST_F(LoginUIShelfVisibilityTest, PostLoginScreen) {
auto override = WizardController::ForceBrandedBuildForTesting();
auto autoreset = SyncConsentScreen::ForceBrandedBuildForTesting(true);
EXPECT_TRUE(ash::LoginScreenTestApi::ClickAddUserButton());
test::OobeGaiaPageWaiter().WaitUntilReady();
LoginDisplayHost::default_host()
......
......@@ -46,6 +46,23 @@ void RecordUmaReviewFollowingSetup(bool value) {
} // namespace
// static
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
bool g_is_branded_build = true;
#else
bool g_is_branded_build = false;
#endif
// static
std::string SyncConsentScreen::GetResultString(Result result) {
switch (result) {
case Result::NEXT:
return "Next";
case Result::NOT_APPLICABLE:
return BaseScreen::kNotApplicable;
}
}
// static
void SyncConsentScreen::MaybeLaunchSyncConsentSettings(Profile* profile) {
if (profile->GetPrefs()->GetBoolean(prefs::kShowSyncSettingsOnSessionStart)) {
......@@ -66,9 +83,8 @@ void SyncConsentScreen::MaybeLaunchSyncConsentSettings(Profile* profile) {
}
}
SyncConsentScreen::SyncConsentScreen(
SyncConsentScreenView* view,
const base::RepeatingClosure& exit_callback)
SyncConsentScreen::SyncConsentScreen(SyncConsentScreenView* view,
const ScreenExitCallback& exit_callback)
: BaseScreen(SyncConsentScreenView::kScreenId, OobeScreenPriority::DEFAULT),
view_(view),
exit_callback_(exit_callback) {
......@@ -80,17 +96,33 @@ SyncConsentScreen::~SyncConsentScreen() {
view_->Bind(NULL);
}
void SyncConsentScreen::ShowImpl() {
void SyncConsentScreen::Init() {
if (is_initialized_)
return;
is_initialized_ = true;
user_ = user_manager::UserManager::Get()->GetPrimaryUser();
profile_ = ProfileHelper::Get()->GetProfileByUser(user_);
UpdateScreen();
}
bool SyncConsentScreen::MaybeSkip() {
if (!g_is_branded_build) {
exit_callback_.Run(Result::NOT_APPLICABLE);
return true;
}
Init();
if (behavior_ == SyncScreenBehavior::SKIP) {
exit_callback_.Run();
return;
exit_callback_.Run(Result::NOT_APPLICABLE);
return true;
}
return false;
}
void SyncConsentScreen::ShowImpl() {
Init();
if (behavior_ != SyncScreenBehavior::SHOW) {
// Wait for updates and set the loading throbber to be visible.
view_->SetThrobberVisible(true /*visible*/);
......@@ -122,7 +154,7 @@ void SyncConsentScreen::OnContinueAndReview(
RecordConsent(CONSENT_GIVEN, consent_description, consent_confirmation);
profile_->GetPrefs()->SetBoolean(prefs::kShowSyncSettingsOnSessionStart,
true);
exit_callback_.Run();
exit_callback_.Run(Result::NEXT);
}
void SyncConsentScreen::OnContinueWithDefaults(
......@@ -132,7 +164,7 @@ void SyncConsentScreen::OnContinueWithDefaults(
return;
RecordUmaReviewFollowingSetup(false);
RecordConsent(CONSENT_GIVEN, consent_description, consent_confirmation);
exit_callback_.Run();
exit_callback_.Run(Result::NEXT);
}
void SyncConsentScreen::OnAcceptAndContinue(
......@@ -156,7 +188,13 @@ void SyncConsentScreen::OnAcceptAndContinue(
true);
}
exit_callback_.Run();
exit_callback_.Run(Result::NEXT);
}
// static
std::unique_ptr<base::AutoReset<bool>>
SyncConsentScreen::ForceBrandedBuildForTesting(bool value) {
return std::make_unique<base::AutoReset<bool>>(&g_is_branded_build, value);
}
void SyncConsentScreen::SetDelegateForTesting(
......@@ -215,7 +253,7 @@ void SyncConsentScreen::UpdateScreen() {
// Screen is shown and behavior has changed.
if (behavior_ == SyncScreenBehavior::SKIP)
exit_callback_.Run();
exit_callback_.Run(Result::NEXT);
if (behavior_ == SyncScreenBehavior::SHOW) {
view_->SetThrobberVisible(false /*visible*/);
......
......@@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include "base/auto_reset.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/scoped_observer.h"
......@@ -35,6 +36,12 @@ class SyncConsentScreen : public BaseScreen,
public:
enum ConsentGiven { CONSENT_NOT_GIVEN, CONSENT_GIVEN };
enum class Result { NEXT, NOT_APPLICABLE };
static std::string GetResultString(Result result);
using ScreenExitCallback = base::RepeatingCallback<void(Result result)>;
class SyncConsentScreenTestDelegate {
public:
SyncConsentScreenTestDelegate() = default;
......@@ -61,9 +68,12 @@ class SyncConsentScreen : public BaseScreen,
static void MaybeLaunchSyncConsentSettings(Profile* profile);
SyncConsentScreen(SyncConsentScreenView* view,
const base::RepeatingClosure& exit_callback);
const ScreenExitCallback& exit_callback);
~SyncConsentScreen() override;
// Inits |user_|, its |profile_| and |behavior_| before using the screen.
void Init();
// syncer::SyncServiceObserver:
void OnStateChanged(syncer::SyncService* sync) override;
......@@ -81,6 +91,9 @@ class SyncConsentScreen : public BaseScreen,
bool enable_os_sync,
bool review_browser_sync);
static std::unique_ptr<base::AutoReset<bool>> ForceBrandedBuildForTesting(
bool value);
// Sets internal condition "Sync disabled by policy" for tests.
void SetProfileSyncDisabledByPolicyForTesting(bool value);
......@@ -92,8 +105,17 @@ class SyncConsentScreen : public BaseScreen,
SyncConsentScreen::SyncConsentScreenTestDelegate* delegate);
SyncConsentScreenTestDelegate* GetDelegateForTesting() const;
void set_exit_callback_for_testing(const ScreenExitCallback& exit_callback) {
exit_callback_ = exit_callback;
}
const ScreenExitCallback& get_exit_callback_for_testing() {
return exit_callback_;
}
private:
// BaseScreen:
bool MaybeSkip() override;
void ShowImpl() override;
void HideImpl() override;
......@@ -119,7 +141,7 @@ class SyncConsentScreen : public BaseScreen,
SyncScreenBehavior behavior_ = UNKNOWN;
SyncConsentScreenView* const view_;
base::RepeatingClosure exit_callback_;
ScreenExitCallback exit_callback_;
// Manages sync service observer lifetime.
ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver>
......@@ -128,6 +150,7 @@ class SyncConsentScreen : public BaseScreen,
// Primary user ind his Profile (if screen is shown).
const user_manager::User* user_ = nullptr;
Profile* profile_ = nullptr;
bool is_initialized_ = false;
base::Optional<bool> test_sync_disabled_by_policy_;
base::Optional<bool> test_sync_engine_initialized_;
......
......@@ -680,10 +680,7 @@ void WizardController::ShowSyncConsentScreen() {
// region. Currently used on the MarketingOptInScreen.
StartNetworkTimezoneResolve();
if (is_branded_build_)
SetCurrentScreen(GetScreen(SyncConsentScreenView::kScreenId));
else
OnSyncConsentFinished();
SetCurrentScreen(GetScreen(SyncConsentScreenView::kScreenId));
}
void WizardController::ShowFingerprintSetupScreen() {
......@@ -1095,12 +1092,10 @@ void WizardController::OnTermsOfServiceScreenExit(
}
}
void WizardController::OnSyncConsentScreenExit() {
OnScreenExit(SyncConsentScreenView::kScreenId, kDefaultExitReason);
OnSyncConsentFinished();
}
void WizardController::OnSyncConsentFinished() {
void WizardController::OnSyncConsentScreenExit(
SyncConsentScreen::Result result) {
OnScreenExit(SyncConsentScreenView::kScreenId,
SyncConsentScreen::GetResultString(result));
ShowFingerprintSetupScreen();
}
......
......@@ -34,6 +34,7 @@
#include "chrome/browser/chromeos/login/screens/network_screen.h"
#include "chrome/browser/chromeos/login/screens/packaged_license_screen.h"
#include "chrome/browser/chromeos/login/screens/recommend_apps_screen.h"
#include "chrome/browser/chromeos/login/screens/sync_consent_screen.h"
#include "chrome/browser/chromeos/login/screens/terms_of_service_screen.h"
#include "chrome/browser/chromeos/login/screens/update_screen.h"
#include "chrome/browser/chromeos/policy/enrollment_config.h"
......@@ -228,9 +229,8 @@ class WizardController {
void OnDemoPreferencesScreenExit(DemoPreferencesScreen::Result result);
void OnDemoSetupScreenExit(DemoSetupScreen::Result result);
void OnTermsOfServiceScreenExit(TermsOfServiceScreen::Result result);
void OnSyncConsentScreenExit();
void OnSyncConsentFinished();
void OnFingerprintSetupScreenExit(FingerprintSetupScreen::Result result);
void OnSyncConsentScreenExit(SyncConsentScreen::Result result);
void OnDiscoverScreenExit();
void OnArcTermsOfServiceScreenExit(ArcTermsOfServiceScreen::Result result);
void OnArcTermsOfServiceAccepted();
......
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