This is the cherry pick merge for the M73 branch which was approved here:

[Autofill Assistant] Avoid race conditions in graceful shutdown.

Before this patch, there were cases where the controller would enter
graceful shutdown because of a script, with a successful message, and
then notice an error, and change that message to an error. The error was
usually caused by DidStartNavigation noticing an unexpected navigation
event, triggered by an action run at the end of the last script.

This patch attempts to avoid such case by:
 - only checking for unexpected navigation events in the PROMPT state.
 This specifically excludes the STOPPED and RUNNING states.
 - not reporting errors or accepting script updates (OnGetScript) in the
 STOPPED state
 - stopping script checks when entering the fatal error state

Bug: 806868
Change-Id: I408d2652257d9524740e44c79b7fa5201ef7cc17
Commit-Queue: Stephane Zermatten <>
Reviewed-by: Mathias Carlen <>
Cr-Original-Commit-Position: refs/heads/master@{#626937}(cherry picked from commit a42a78954e4c0da3d5b7dd1935626e815416fe09)
Reviewed-by: Stephane Zermatten <>
Cr-Commit-Position: refs/branch-heads/3683@{#108}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
2 files changed