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