Commit e699a7c5 authored by Justin Gallagher's avatar Justin Gallagher Committed by Commit Bot

[omnibox] Fix TSAN issues with field tests in SearchProviderTest

Command line flags, field trials, and feature flags must be initialized
before BrowserTaskEnvironment to avoid a potential race condition, where
the browser is reading from the trial state at the same time that it is
being written to.

This isn't done in SearchProviderTest, which causes potential races in
two tests:
    SearchProviderTest.CommandLineOverrides
    SearchProviderTest.SendsWarmUpRequestOnFocus

To resolve, a new class SearchProviderFeatureTestComponent was created
to handle field trial state. It's initialized before the
BrowserTaskEnvironment member.

BrowserTaskEnvironment is responsible for spinning up the thread pool,
so everything before that point is synchronous. That's adding a thread
which is reading the field trial state, causing the race. C++
initializes it's member variables in order of declaration, so adding the
FeatureTestComponent before BrowserTaskEnvironment ensures that the
command line and field tests are set before any other threads are added.

This change is heavily based on mpearson's prior fix, which was
reverted. http://crrev.com/c/1263562

Bug: 891959
Change-Id: I5590579ad9aef73d2d055dec5712dfd5dc567ce9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902786
Commit-Queue: Justin Gallagher <jugallag@microsoft.com>
Reviewed-by: default avatarKevin Bailey <krb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714824}
parent df0c51a6
......@@ -102,13 +102,13 @@ class SearchProvider : public BaseSearchProvider,
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveExtraAnswers);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoesNotProvideOnFocus);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SendsWarmUpRequestOnFocus);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoTrimHttpScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
DontTrimHttpSchemeIfInputHasScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
DontTrimHttpsSchemeIfInputHasScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoTrimHttpsScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderWarmUpTest, SendsWarmUpRequestOnFocus);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery);
......
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