DescriptionAlways call StorageMonitor::RemoveObserver in ~MediaFileSystemRegistry.
To make ObserverListThreadSafe TaskScheduler-friendly, we plan to
dispatch notifications to observers in separate tasks (previously,
observers registered from the same thread were notified in the
same task). This change causes a use-after-free in
GalleryWatchManagerTest.TestStorageRemovedAfterProfileShutdown:
1. StorageMonitor sends a notification to its observers.
2. The notification is dispatched to GalleryWatchManager, which
requests the loop to exit after the current task (ConfirmWatch).
3. StorageMonitor is destroyed.
4. MediaFileSystemRegistry is destroyed. Because StorageMonitor has
already been destroyed, it doesn't call
StorageMonitor::RemoveObserver.
5. TestBrowserThreadBundle is destroyed. In its destructor, it
dispatches the notification to the deleted MediaFileSystemRegistry,
which causes a use-after-free.
When observers registered from the same thread are notified from
the same task, MediaFileSystemRegistry is notified before the
loop exits (and hence no notification is dispatched to a deleted
MediaFileSystemRegistry in step 5).
This CL moves step 4 before step 3. This allows
MediaFileSystemRegistry to call StorageMonitor::RemoveObserver
from its destructor and prevents it from receiving notifications
after being destroyed.
BUG=675631
Review-Url: https://codereview.chromium.org/2654303002
Cr-Commit-Position: refs/heads/master@{#446569}
Committed: https://chromium.googlesource.com/chromium/src/+/4f5235b9f2a3d151c85f497e9963809f11fe7bac
Patch Set 1 #Patch Set 2 : fix test error #Patch Set 3 : add DCHECK #Patch Set 4 : add include #
Messages
Total messages: 22 (18 generated)
|