Skip to content

Commit

Permalink
OOBE: Fix ash::GaiaScreen::LoadOnlineGaia crashes
Browse files Browse the repository at this point in the history
Fix the crashes in GaiaScreen caused by accessing the pointer
returned from `BaseScreen::context()` while the screen is not shown.

The pointer returned from `BaseScreen::context()` is only set before
`GaiaScreen::ShowImpl()` is called and is reset after
`GaiaScreen::HideImpl()` is called. Outside this range the
`WizardContext` should be accessed from `LoginDisplayHost`.

Bug: b:306728962
Change-Id: Iecc4308d4b09f23cd835d0da4f57f6ae910cf114
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4961793
Reviewed-by: Denis Kuznetsov <antrim@chromium.org>
Commit-Queue: Osama Fathy <osamafathy@google.com>
Cr-Commit-Position: refs/heads/main@{#1213141}
  • Loading branch information
Osama Fathy authored and Chromium LUCI CQ committed Oct 21, 2023
1 parent 6c17a70 commit 9c8613c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions chrome/browser/ash/login/screens/gaia_screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ void GaiaScreen::LoadOnlineGaia() {
return;
}

switch (context()->gaia_config.gaia_path) {
auto* context = LoginDisplayHost::default_host()->GetWizardContext();
switch (context->gaia_config.gaia_path) {
case WizardContext::GaiaPath::kDefault:
LoadDefaultOnlineGaia(context()->gaia_config.prefilled_account);
LoadDefaultOnlineGaia(context->gaia_config.prefilled_account);
break;
case WizardContext::GaiaPath::kReauth:
LoadDefaultOnlineGaia(EmptyAccountId());
Expand All @@ -152,7 +153,9 @@ void GaiaScreen::LoadDefaultOnlineGaia(const AccountId& account) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceCryptohomeRecoveryForTesting)) {
DCHECK(features::IsCryptohomeRecoveryEnabled());
context()->gaia_config.gaia_path = WizardContext::GaiaPath::kReauth;
LoginDisplayHost::default_host()
->GetWizardContext()
->gaia_config.gaia_path = WizardContext::GaiaPath::kReauth;
FetchGaiaReauthToken(account);
return;
}
Expand All @@ -172,8 +175,10 @@ void GaiaScreen::LoadDefaultOnlineGaia(const AccountId& account) {
void GaiaScreen::Reset() {
if (!view_)
return;
context()->gaia_config.gaia_path = WizardContext::GaiaPath::kDefault;
context()->gaia_config.prefilled_account = EmptyAccountId();

auto* context = LoginDisplayHost::default_host()->GetWizardContext();
context->gaia_config.gaia_path = WizardContext::GaiaPath::kDefault;
context->gaia_config.prefilled_account = EmptyAccountId();
view_->SetIsGaiaPasswordRequired(false);
view_->Reset();
}
Expand Down Expand Up @@ -330,7 +335,9 @@ void GaiaScreen::OnGetAuthFactorsConfiguration(

const AccountId& account_id = user_context->GetAccountId();
if (ShouldUseReauthEndpoint(account_id, is_recovery_configured)) {
context()->gaia_config.gaia_path = WizardContext::GaiaPath::kReauth;
LoginDisplayHost::default_host()
->GetWizardContext()
->gaia_config.gaia_path = WizardContext::GaiaPath::kReauth;
}

if (ShouldPrepareForRecovery(account_id) && is_recovery_configured) {
Expand Down

0 comments on commit 9c8613c

Please sign in to comment.