forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webview: fix minor race in init and clean up code.
If an app called a thread-safe WebView function and then, before the init task posted to the UI thread had a chance to complete, another thread also called a WebView function, then we would attempt to set the UI thread twice. In almost all cases this is benign as it would be set to the main looper both times, but edge cases may exist that would result in an attempt to *change* the UI thread, causing a crash in ThreadUtils.setUiThread. Fix this by replacing mStarted with a state enum. All existing uses of mStarted now refer to INIT_FINISHED; INIT_STARTED is (currently) only used to determine whether the UI thread has already been chosen or not. To make the code easier to understand, rename the "onMainThread" parameter to "fromThreadSafeFunction" to more clearly reflect what it actually means: if true, the caller was a thread-safe function and so init must be started on the main looper, regardless of the current thread. This does *not* change the value at any callsites; this was already the meaning, just with a bad name. Flip the ternary operator usage so that the condition is not negated, making it easier to read. Add comments describing the process in more detail, as WebView threading requirements are not obvious. Change-Id: I8f916bfcd7eae04ba97d87f2fa9655844fd50663 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626516 Commit-Queue: Richard Coles <[email protected]> Reviewed-by: Nate Fischer <[email protected]> Cr-Commit-Position: refs/heads/master@{#847673}
- Loading branch information
Showing
1 changed file
with
65 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters