wake lock: Do not dispatch events if the context has been destroyed.
Both WakeLock and WakeLockSentinel inherit from ContextLifecycleObserver, but by design a WakeLock is always created before a WakeLockSentinel, and thus its ContextDestroyed() implementation is called before WakeLockSentinel's. This can result in the following call chain: 1. WakeLock::ContextDestroyed() 2. WakeLockManager::ClearWakeLocks() 3. WakeLockSentinel::DoRelease() if a WakeLockSentinel has an event handler, DoRelease() will try to dispatch an event after the context has been destroyed, as WakeLockSentinel::ContextDestroyed(), which calls RemoveAllEventListeners(), has not been called yet. We now check if we have a usable context before dispatching events. WakeLockSentinelTest.ContextDestruction() has been augmented and now tests the entire flow (i.e. starting with a WakeLock object) rather than just context destruction when a WakeLockSentinel is present. Bug: 1023477 Change-Id: I3211d60d624456b950a884771c3fba79a4f8fa8d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1917359 Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com> Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com> Reviewed-by:Reilly Grant <reillyg@chromium.org> Cr-Commit-Position: refs/heads/master@{#715406}
Showing
Please register or sign in to comment