Don't fire onnegotiationneeded if flag has already been reset.

Per-spec, updating the negotiation needed flag is slightly more
complicated than "= true;" and involves checking if negotiation is
needed.
https://w3c.github.io/webrtc-pc/#dfn-update-the-negotiation-needed-flag

This operation is not implemented in third_party/webrtc, so both before
and after this CL we trust that when the negotiation needed signal
reaches the main thread negotiation is still needed. This may not hold
in some obscure edge cases like rollback. This is an existing problem
not new to this CL.

This CL implements the part of the spec that says to queue a task that
fires the event and resets the flag if the flag is not already reset.
This resolves a long-lived bug where onnegotiationneeded is fired
multiple times - once per API call instead of once for each time the
flag goes from false to true.

Example:
  pc.addTrack(t1);
  pc.addTrack(t2);
  pc.onnegotiationneeded = () => {
    console.log('negotiation needed!');
  }

Before the CL, that fired twice. Now it fires once. Both tracks set the
flag and queue a task, but by the time the second task is executed the
flag has already been reset so the second event is not redundently
fired.

Bug: 740501, webrtc:7693
Change-Id: I0430d26158d50aa4d18d5f27f92a5a7bb3e68a9d
Reviewed-on: https://chromium-review.googlesource.com/908450
Commit-Queue: Henrik Boström <hbos@chromium.org>
Reviewed-by: Harald Alvestrand <hta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535681}
5 files changed