Commit 24c6d042 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

OOBE refactor: Let individual screens determine the visibility

This is the refactor portion of https://crrev.com/c/1272085.

The logic in wizard_controller.cc is very complex. We should try to
move the screen specific logic out of it.

Bug: NONE
Change-Id: Id89479b4b145b2a80333bbbadd1e51472fb8ab49
Reviewed-on: https://chromium-review.googlesource.com/c/1281171
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599872}
parent 6b6c0f46
......@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "chrome/browser/chromeos/login/screens/base_screen_delegate.h"
#include "chrome/browser/chromeos/login/screens/model_view_channel.h"
#include "components/user_manager/user_manager.h"
namespace chromeos {
......@@ -101,6 +102,15 @@ void BaseScreen::Finish(ScreenExitCode exit_code) {
base_screen_delegate_->OnExit(exit_code);
}
bool BaseScreen::IsPublicSessionOrEphemeralLogin() {
const user_manager::UserManager* user_manager =
user_manager::UserManager::Get();
return user_manager->IsLoggedInAsPublicAccount() ||
(user_manager->IsCurrentUserNonCryptohomeDataEphemeral() &&
user_manager->GetActiveUser()->GetType() !=
user_manager::USER_TYPE_REGULAR);
}
void BaseScreen::OnUserAction(const std::string& action_id) {
LOG(WARNING) << "Unhandled user action: action_id=" << action_id;
}
......
......@@ -106,6 +106,12 @@ class BaseScreen {
// it's work with |outcome|.
void Finish(ScreenExitCode exit_code);
// Returns whether the active user is public session user or non-regular
// ephemeral user.
// TODO(agawronska): Test that there are no wizard screens shown every time
// public session launches.
bool IsPublicSessionOrEphemeralLogin();
// The method is called each time some key in screen context is
// updated by JS side. Default implementation does nothing, so
// subclasses should override it in order to observe updates in
......
......@@ -26,6 +26,10 @@ DiscoverScreen::~DiscoverScreen() {
}
void DiscoverScreen::Show() {
if (IsPublicSessionOrEphemeralLogin()) {
Finish(ScreenExitCode::DISCOVER_FINISHED);
return;
}
view_->Show();
}
......
......@@ -25,7 +25,10 @@ FingerprintSetupScreen::~FingerprintSetupScreen() {
}
void FingerprintSetupScreen::Show() {
// Show the screen.
if (IsPublicSessionOrEphemeralLogin()) {
Finish(ScreenExitCode::FINGERPRINT_SETUP_FINISHED);
return;
}
view_->Show();
}
......
......@@ -6,6 +6,11 @@
#include "base/logging.h"
#include "chrome/browser/chromeos/login/screens/marketing_opt_in_screen_view.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_switches.h"
#include "components/prefs/pref_service.h"
namespace chromeos {
......@@ -23,7 +28,20 @@ MarketingOptInScreen::~MarketingOptInScreen() {
}
void MarketingOptInScreen::Show() {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
// Skip the screen if:
// 1) the feature is disabled, or
// 2) the screen has been shown for this user, or
// 3) it is public session or non-regular ephemeral user login.
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kEnableMarketingOptInScreen) ||
prefs->GetBoolean(prefs::kOobeMarketingOptInScreenFinished) ||
IsPublicSessionOrEphemeralLogin()) {
Finish(ScreenExitCode::MARKETING_OPT_IN_FINISHED);
return;
}
view_->Show();
prefs->SetBoolean(prefs::kOobeMarketingOptInScreenFinished, true);
}
void MarketingOptInScreen::Hide() {
......
......@@ -4,8 +4,13 @@
#include "chrome/browser/chromeos/login/screens/multidevice_setup_screen.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "chrome/browser/chromeos/login/screens/multidevice_setup_screen_view.h"
#include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_client_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
namespace chromeos {
......@@ -29,6 +34,38 @@ MultiDeviceSetupScreen::~MultiDeviceSetupScreen() {
}
void MultiDeviceSetupScreen::Show() {
// If multi-device flags are disabled, skip the associated setup flow.
if (!base::FeatureList::IsEnabled(features::kMultiDeviceApi) ||
!base::FeatureList::IsEnabled(features::kEnableUnifiedMultiDeviceSetup)) {
ExitScreen();
return;
}
// Only attempt the setup flow for non-guest users.
if (IsPublicSessionOrEphemeralLogin()) {
ExitScreen();
return;
}
multidevice_setup::MultiDeviceSetupClient* client =
multidevice_setup::MultiDeviceSetupClientFactory::GetForProfile(
ProfileManager::GetActiveUserProfile());
if (!client) {
ExitScreen();
return;
}
// If there is no eligible multi-device host phone or if there is a phone and
// it has already been set, skip the setup flow.
if (client->GetHostStatus().first !=
multidevice_setup::mojom::HostStatus::kEligibleHostExistsButNoHostSet) {
VLOG(1) << "Skipping MultiDevice setup screen; host status: "
<< client->GetHostStatus().first;
ExitScreen();
return;
}
view_->Show();
}
......@@ -38,11 +75,15 @@ void MultiDeviceSetupScreen::Hide() {
void MultiDeviceSetupScreen::OnUserAction(const std::string& action_id) {
if (action_id == kFinishedUserAction) {
Finish(ScreenExitCode::MULTIDEVICE_SETUP_FINISHED);
ExitScreen();
return;
}
BaseScreen::OnUserAction(action_id);
}
void MultiDeviceSetupScreen::ExitScreen() {
Finish(ScreenExitCode::MULTIDEVICE_SETUP_FINISHED);
}
} // namespace chromeos
......@@ -27,6 +27,9 @@ class MultiDeviceSetupScreen : public BaseScreen {
void OnUserAction(const std::string& action_id) override;
private:
// Exits the screen.
void ExitScreen();
MultiDeviceSetupScreenView* view_;
DISALLOW_COPY_AND_ASSIGN(MultiDeviceSetupScreen);
......
......@@ -171,6 +171,10 @@ void UserImageScreen::Show() {
if (!view_)
return;
if (IsPublicSessionOrEphemeralLogin()) {
ExitScreen();
return;
}
DCHECK(!policy_registrar_);
if (Profile* profile = ProfileHelper::Get()->GetProfileByUser(GetUser())) {
policy::PolicyService* policy_service =
......
......@@ -107,7 +107,6 @@
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/portal_detector/network_portal_detector.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
#include "chromeos/settings/cros_settings_names.h"
#include "chromeos/settings/cros_settings_provider.h"
#include "chromeos/settings/timezone_settings.h"
......@@ -257,15 +256,6 @@ bool IsBootstrappingMaster() {
chromeos::switches::kOobeBootstrappingMaster);
}
bool IsPublicSessionOrEphemeralLogin() {
const user_manager::UserManager* user_manager =
user_manager::UserManager::Get();
return user_manager->IsLoggedInAsPublicAccount() ||
(user_manager->IsCurrentUserNonCryptohomeDataEphemeral() &&
user_manager->GetActiveUser()->GetType() !=
user_manager::USER_TYPE_REGULAR);
}
bool NetworkAllowUpdate(const chromeos::NetworkState* network) {
if (!network || !network->IsConnectedState())
return false;
......@@ -605,19 +595,11 @@ void WizardController::ShowPreviousScreen() {
}
void WizardController::ShowUserImageScreen() {
// Skip user image selection for public sessions and ephemeral non-regular
// user logins.
if (IsPublicSessionOrEphemeralLogin()) {
OnUserImageSkipped();
return;
}
VLOG(1) << "Showing user image screen.";
// Status area has been already shown at sign in screen so it
// doesn't make sense to hide it here and then show again at user session as
// this produces undesired UX transitions.
UpdateStatusAreaVisibilityForScreen(OobeScreen::SCREEN_USER_IMAGE_PICKER);
SetCurrentScreen(GetScreen(OobeScreen::SCREEN_USER_IMAGE_PICKER));
}
......@@ -698,35 +680,15 @@ void WizardController::ShowSyncConsentScreen() {
}
void WizardController::ShowFingerprintSetupScreen() {
// Skip the screen for public sessions and non-regular ephemeral users.
// TODO(agawronska): Test that there are no wizard screens shown every time
// Public Session launches.
if (IsPublicSessionOrEphemeralLogin()) {
OnFingerprintSetupFinished();
return;
}
VLOG(1) << "Showing Fingerprint Setup screen.";
UpdateStatusAreaVisibilityForScreen(OobeScreen::SCREEN_FINGERPRINT_SETUP);
SetCurrentScreen(GetScreen(OobeScreen::SCREEN_FINGERPRINT_SETUP));
}
void WizardController::ShowMarketingOptInScreen() {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
// Skip the screen if:
// 1) the feature is disabled, or
// 2) the screen has been shown for this user, or
// 3) it is public session or non-regular ephemeral user login.
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kEnableMarketingOptInScreen) ||
prefs->GetBoolean(prefs::kOobeMarketingOptInScreenFinished) ||
IsPublicSessionOrEphemeralLogin()) {
OnMarketingOptInFinished();
return;
}
VLOG(1) << "Showing Marketing Opt-In screen.";
UpdateStatusAreaVisibilityForScreen(OobeScreen::SCREEN_MARKETING_OPT_IN);
SetCurrentScreen(GetScreen(OobeScreen::SCREEN_MARKETING_OPT_IN));
prefs->SetBoolean(prefs::kOobeMarketingOptInScreenFinished, true);
}
void WizardController::ShowArcTermsOfServiceScreen() {
......@@ -855,48 +817,12 @@ void WizardController::ShowAssistantOptInFlowScreen() {
}
void WizardController::ShowMultiDeviceSetupScreen() {
// If multi-device flags are disabled, skip the associated setup flow.
if (!base::FeatureList::IsEnabled(features::kMultiDeviceApi) ||
!base::FeatureList::IsEnabled(features::kEnableUnifiedMultiDeviceSetup)) {
OnMultiDeviceSetupFinished();
return;
}
// Only attempt the setup flow for non-guest users.
if (IsPublicSessionOrEphemeralLogin()) {
OnMultiDeviceSetupFinished();
return;
}
multidevice_setup::MultiDeviceSetupClient* client =
multidevice_setup::MultiDeviceSetupClientFactory::GetForProfile(
ProfileManager::GetActiveUserProfile());
if (!client) {
OnMultiDeviceSetupFinished();
return;
}
// If there is no eligible multi-device host phone or if there is a phone and
// it has already been set, skip the setup flow.
if (client->GetHostStatus().first !=
multidevice_setup::mojom::HostStatus::kEligibleHostExistsButNoHostSet) {
VLOG(1) << "Skipping MultiDevice setup screen; host status: "
<< client->GetHostStatus().first;
OnMultiDeviceSetupFinished();
return;
}
VLOG(1) << "Showing MultiDevice setup screen.";
UpdateStatusAreaVisibilityForScreen(OobeScreen::SCREEN_MULTIDEVICE_SETUP);
SetCurrentScreen(GetScreen(OobeScreen::SCREEN_MULTIDEVICE_SETUP));
}
void WizardController::ShowDiscoverScreen() {
if (IsPublicSessionOrEphemeralLogin()) {
OnDiscoverScreenFinished();
return;
}
VLOG(1) << "Showing Discover screen.";
UpdateStatusAreaVisibilityForScreen(OobeScreen::SCREEN_DISCOVER);
SetCurrentScreen(GetScreen(OobeScreen::SCREEN_DISCOVER));
......@@ -1083,10 +1009,6 @@ void WizardController::OnUserImageSelected() {
OnOobeFlowFinished();
}
void WizardController::OnUserImageSkipped() {
OnUserImageSelected();
}
void WizardController::OnEnrollmentDone() {
PerformOOBECompletedActions();
......
......@@ -221,7 +221,6 @@ class WizardController : public BaseScreenDelegate,
void OnUpdateErrorCheckingForUpdate();
void OnUpdateErrorUpdating(bool is_critical_update);
void OnUserImageSelected();
void OnUserImageSkipped();
void OnEnrollmentDone();
void OnDeviceModificationCanceled();
void OnKioskAutolaunchCanceled();
......
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