Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[base] Stop using ObserverListThreadSafe::NotifySynchronously…
… in FieldTrialList." == Changes since original CL == This CL registers ChildProcessFieldTrialSyncer as a FieldTrialList observer instead of ChildThreadImpl and it makes ChildProcessFieldTrialSyncer a leaky singleton. This eliminates lifetime issues. An alternative would have been to remove ChildThreadImpl from the list of FieldTrialList observers upon destruction. We decided not to do that because it would have required extra synchronization. Diff: https://crrev.com/c/2867567/1..16 == Original description == This CL removes usage of ObserverListThreadSafe::NotifySynchronously in FieldTrialList, to support the removal of this method in a separate CL. Currently, FieldTrialList uses ObserverListThreadSafe::NotifySynchronously to notify observers when a group is selected for a field trial. This method dispatches synchronous notifications to observers which were registered on the current sequence, and uses PostTask to notify other observers asynchronously. Through code inspection, we found that all implementations of FieldTrialList::Observer::OnFieldTrialGroupFinalized are thread-safe. Therefore, they can always be notified synchronously, no matter which sequence they were registered from. This CL makes these changes: - Observers are stored in a lock-protected std::vector instead of in an ObserverListThreadSafe. - To notify observers, the list of observers is copied to a local variable while holding the lock. Then, after releasing the lock, all observers in the local list are notified. - In the scope where observers are notified, an atomic variable is incremented. The RemoveObserver method checks that the variable is equal to zero. This ensures that no observer is removed while dispatching notifications (which could cause a use-after-free). For reference, the implementations of FieldTrialList::Observer::OnFieldTrialGroupFinalized are: base/android/field_trial_list.cc: LOG(INFO) is thread-safe base/metrics/field_trial_unittest.cc: The test is single-threaded. components/variations/child_process_field_trial_syncer_unittest.cc: The test is single-threaded. components/variations/variations_crash_keys.cc: The observer checks whether it runs on the UI thread and forwards the notification to the UI thread if it's not the case. components/variations/variations_ids_provider.cc: The observer uses a lock. content/browser/field_trial_synchronizer.cc: The observer checks whether it runs on the UI thread and forwards the notification to the UI thread if it's not the case. content/browser/net/network_field_trial_browsertest.cc RunLoop::Quit() is thread-safe. content/child/child_thread_impl.cc A mojo::SharedRemote is thread-safe. Bug: 1193750 Change-Id: I8351a2cbbce4d5deaafbe2aa75f902e6da822d53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2867567 Commit-Queue: François Doray <fdoray@chromium.org> Auto-Submit: François Doray <fdoray@chromium.org> Reviewed-by: Nasko Oskov <nasko@chromium.org> Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Cr-Commit-Position: refs/heads/master@{#880105}
- Loading branch information
Showing
15 changed files
with
286 additions
and
281 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
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
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
Oops, something went wrong.