• Leon Han's avatar
    [webnfc] Generate watch ids in Blink rather than DeviceService · 53814b9e
    Leon Han authored
    Previously watch ids were generated in the DeviceService. This CL
    switches to do that in Blink side, more specifically NFCProxy is
    responsible to generate/manage them, and still keeps their uniqueness
    over a given Mojo connection of device.mojom.NFC interface.
    
    This makes it easier for NFCProxy to track the set of active readers,
    specifically the 2 problems below can get solved.
    
    1.
      a. NFCReader#start() --> device.mojom.NFC.Watch(options), we'll get
         the watch id via the response callback.
      b. in DeviceService the NFCImpl Watch() generates WATCH_ID_XXX and
         passes it back via the WatchResponse callback.
      c. in DeviceService NFCImpl gets a matched NDEFMessage from a NFC tag
         and call device.mojom.NFCClient.OnWatch(WATCH_ID_XXX, ndef_message).
    As NFC and NFCClient run on separated Mojo message pipes, the Mojo
    messages sent by the above a and b do not have any ordering guarantee,
    i.e. c may gets to NFCProxy earlier than b, then, because NFCProxy did
    not get WATCH_ID_XXX yet, it can not find the corresponding reader
    that should actually be the receiver of this NDEFMessage.
    
    2.
      a. NFCReader#start() --> device.mojom.NFC.Watch(options)
      b. NFCReader#stop() --> can not call device.mojom.NFC.CancelWatch(id)
         because we did not get the watch id yet.
      c. the WATCH_ID_XXX for step a above comes back.
    This just leaves the watch session of WATCH_ID_XXX long live in NFCImpl
    without any chance to cancel it.
    
    BUG=520391
    
    Change-Id: I136ee6aab54eb464e5dd684ed34a2d738d2f5198
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730515
    Commit-Queue: Leon Han <leon.han@intel.com>
    Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
    Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#683914}
    53814b9e
nfc-helpers.js 13.1 KB