• Pavel Shmakov's avatar
    Handle BrowserFragment restoration · 47d9188e
    Pavel Shmakov authored
    When Activity is restarted (either after configuration change, unless
    handled manually, or after being killed due to memory pressure), the
    system FragmentManager restores all the Fragments during Activity's
    onCreate event. The current APIs make it impossible to properly
    create a BrowserFragment without an instance of WebLayer, and that
    prohibits asynchronous WebLayer initialization.
    
    There are two ways to deal with it:
    - Disable it in a hacky way: the embedder runs
    savedInstanceState.remove("android:support:fragments");
    in their activity prior to super.onCreate(). The
    embedder should then manually save and restore the parameters of
    each fragment they have.
    - Handle the restoration the "correct" way.
    
    More detailed discussion:
    
    This CL enables the second path. This means putting BrowserFragment
    on the top of dependency tree, which is opposite to what we have
    now (getWebLayer().createProfile().createBrowserFragment()). In
    this CL, BrowserFragment is created independently, and later
    attached to WebLayer instance.
    
    I suggest making BrowserFragment the only client-side object that
    can temporarily exist without the weblayer counterpart.
    All other objects should have the same lifecycle on both sides.
    
    This is achieved by making all browser APIs accessible only through
    BrowserFragmentController, which in turn can be accessed only after
    the embedder attaches BrowserFragment to WebLayer.
    
    More detailed discussion:
    https://docs.google.com/document/d/15xCcdO8V1tBYH-UJStmi0aEzLXcUWDkc-KWI_Wb7rdQ
    
    This CL doesn't enable async init of WebLayer after process restart: trying to
    retrieve BrowserFragmentController or attach BrowserFragment blocks the thread
    if WebLayer hasn't been already initialized, and in case of process restart it
    can't have been initialized.
    
    Change-Id: Ibe6fd369e8d60af5cedc256d3ebf1db210b579bc
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1829082Reviewed-by: default avatarBo <boliu@chromium.org>
    Reviewed-by: default avatarScott Violet <sky@chromium.org>
    Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#704695}
    47d9188e
BrowserFragmentController.java 3.1 KB