Commit f707f203 authored by Anatoliy Potapchuk's avatar Anatoliy Potapchuk Committed by Commit Bot

Fix race condition during kiosk launch error check

When a kiosk app is set to be auto-launched and the user cancels its
launch, we should disable auto-launch on next boot. This was
achieved by setting "KioskAppLaunch" variable into the local state,
and subsequently resetting it every time. This variable was reused
by both plain kiosk and arc kiosk modes.
The variable was reset in only one of the code paths, leading to a race
condition when second one tries to read from already reset variable.

There are many possible solutions for this, one of the simplest ones
is to persist the error state during the whole boot.

Bug: 984740
Change-Id: I161daae80a4fedb51d47ebff93b84e34bfc475b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1781431Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Anatoliy Potapchuk <apotapchuk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692819}
parent e63048d1
......@@ -22,6 +22,9 @@ constexpr char kKeyLaunchError[] = "launch_error";
// Key under "kiosk" dictionary to store the last cryptohome error.
constexpr char kKeyCryptohomeFailure[] = "cryptohome_failure";
// Error from the last kiosk launch.
KioskAppLaunchError::Error s_last_error = KioskAppLaunchError::ERROR_COUNT;
} // namespace
// static
......@@ -70,6 +73,7 @@ void KioskAppLaunchError::Save(KioskAppLaunchError::Error error) {
DictionaryPrefUpdate dict_update(local_state,
KioskAppManager::kKioskDictionaryName);
dict_update->SetInteger(kKeyLaunchError, error);
s_last_error = error;
}
// static
......@@ -83,13 +87,18 @@ void KioskAppLaunchError::SaveCryptohomeFailure(
// static
KioskAppLaunchError::Error KioskAppLaunchError::Get() {
if (s_last_error != KioskAppLaunchError::ERROR_COUNT)
return s_last_error;
s_last_error = KioskAppLaunchError::NONE;
PrefService* local_state = g_browser_process->local_state();
const base::DictionaryValue* dict =
local_state->GetDictionary(KioskAppManager::kKioskDictionaryName);
int error;
if (dict->GetInteger(kKeyLaunchError, &error))
return static_cast<KioskAppLaunchError::Error>(error);
if (dict->GetInteger(kKeyLaunchError, &error)) {
s_last_error = static_cast<KioskAppLaunchError::Error>(error);
return s_last_error;
}
return KioskAppLaunchError::NONE;
}
......
......@@ -46,7 +46,7 @@ class KioskAppLaunchError {
// next Chrome run.
static void SaveCryptohomeFailure(const AuthFailure& auth_failure);
// Gets the saved error.
// Gets the last launch error.
static Error Get();
// Records the launch error and cryptohome auth error metric and clears them.
......
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