Android: Fix a bug not receiving activity state update
The reported bug is a corner case where the WebContents at the front when Chrome is put background, is not at the front when Chrome is back to foreground. When coming to foreground in normal flow, |OnAttachedToWindow| callback reestablishes the front WebContents' ActivityStateObserver(ViewEventSinkImpl) first, which then reacts to |onActivityResumed| callback to update the state to 'resumed' as expected. The bug happens because the WebContents, not being in the front anymore, loses the chance to receive |onActivityResumed| when Chrome gets foreground, since it is still in the state where the observer is not registered. The observer is added later when the tab is moved to the front, upon receiving |onAttachedToWindow| callback. The observer will still remain in paused state that causes inconsistency leading the the bug. This CL fixes the bug by checking activity state when registring the activity state observer, which is done when attached to window. If it is already in the 'resumed' state, it invokes |onActivityResumed| to put WebContents in the right state. In a normal flow this will make |onActivityResumed| invoked twice but it is ok - the second one will be no-op. Bug: 852336 Change-Id: I24aae020908b6a537b258c44b26e63fe5b314474 Reviewed-on: https://chromium-review.googlesource.com/1105344 Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org> Reviewed-by:Bo <boliu@chromium.org> Reviewed-by:
Ted Choc <tedchoc@chromium.org> Cr-Commit-Position: refs/heads/master@{#568670}
Showing
Please register or sign in to comment