• Elly Fong-Jones's avatar
    cocoa: weakly reference MenuModel from MenuController · 1bbf19c5
    Elly Fong-Jones authored
    Before this CL, MenuController's contract required that the provided
    MenuModel outlived a MenuController instance. As of 10.15, it's
    impossible to fulfill that contract: AppKit seems to like keeping
    MenuController instances (via [NSMenuItem target]) alive until the
    next autorelease pool drain, and there's no way for the C++ code that
    creates & manages a MenuModel to know when that will happen. See bug
    998773 for more details about this change in 10.15.
    
    As such, this CL has MenuController hold a WeakPtr to its MenuModel,
    rather than a raw pointer, and handles the MenuModel being destroyed
    before the MenuController.
    
    One other possible approach would be to make MenuController own the
    MenuModel, but that would be a very large change to the ownership of
    MenuModel, and in particular would conflict with the fact that Views
    (in the //ui/views sense) are often used as MenuModels but are owned
    by their parent View.
    
    Bug: 998835
    Change-Id: Ieb3b8928a40d07edf1b9a4d394fb4adc0410fde5
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1804538Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
    Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#697297}
    1bbf19c5
menu_controller.mm 14 KB