• Dana Fried's avatar
    Make LayoutManager::GetAvailableSize() more robust · cff5155b
    Dana Fried authored
    LayoutManagerBase::GetAvailableSize(host, child) will now do the
    following:
     - as before, if the cached layout is still valid since the last call to
       Layout(), it will return the available size of |child| in |host|'s
       layout
     - if the layout has been invalidated since the last call to Layout(), a
       new cached layout for |host| is calculated, which will be used in the
       next call to Layout() assuming the layout is not invalidated again
    
    This gives us two guarantees we did not have before:
     1. instead of returning [no bounds], a correct size bound will almost
        always be returned
     2. a safeguard is in place to ensure that we don't get a stale value
        during |host|'s layout calculation - in fact, we no longer allow the
    	method to be called during |host|'s layout calculation (it will
    	DCHECK())
    
    In general it is legal to call GetAvailableSize() during |child|'s
    Layout() - which happens after |host|'s layout is committed - but not
    during, for example, a FlexRule computation. It doesn't make sense for a
    FlexRule (or similar) to call GetAvailableSize() because it already
    receives a size bound from the caller.
    
    This also fixes a potential issue (related to crbug.com/1041614) which
    could result in a view calling layout code in response to certain types
    of widget setup (among other possible situations) before the layout's
    child data is updated, resulting in a DCHECK() or crash in the layout
    manager. (For at least the short term an example crash can be found here:
    https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8858322112097966752/+/steps/unit_tests__with_patch_/0/logs/Deterministic_failure:_PasswordSaveUpdateWithAccountStoreViewTest.HasTitleAndTwoButtons__status_CRASH_/0)
    
    Change-Id: I3e491c3cb7a648867597ecf830fe52d11f483419
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2622720
    Commit-Queue: Dana Fried <dfried@chromium.org>
    Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#842653}
    cff5155b
view.cc 99.3 KB