• Han Leon's avatar
    [DeviceService] Use WeakPtrFactory instead of SupportsWeakPtr<> for SerialConnection · b9f8dc9d
    Han Leon authored
    This CL changes device::SerialConnection to hold a base::WeakPtrFactory
    member rather than inherit base::SupportsWeakPtr<> to avoid the subtle
    use-after-destroy issue:
    1.
    SerialConnection dtor starts, destroyes its'
    device::mojom::SerialIoHandlerPtr |io_handler_| member.
    2.
    The SerialIoHandlerPtr dtor triggers some one callback XXX wrapped by
    ScopedCallbackRunner to run.
    3.
    The callback XXX was actually bound with a weak ptr of SerialConnection,
    at this time point the parent class SupportsWeakPtr's dtor has not been
    triggered yet so that the weak ptr is still in a valid state, although
    we are already inside the execution context of SerialConnection dtor.
    
    A base::WeakPtrFactory member at the end of member list will be
    destroyed immediatelly once entering SerialConnection dtor, thus in the
    above step 3 the bound weak ptr should be identified as invalid so that
    callback XXX won't be called at all. This is the expected behavior.
    
    BUG=757756
    
    Change-Id: Ib73ac55dcfba250c4f8b96fb9e3d3e85490ea9a0
    Reviewed-on: https://chromium-review.googlesource.com/626197Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
    Commit-Queue: Han Leon <leon.han@intel.com>
    Cr-Commit-Position: refs/heads/master@{#496526}
    b9f8dc9d
serial_connection.cc 16.4 KB