[gamepad] Enforce GamepadService consumers invariant

GamepadService maintains a set of GamepadConsumers that are
registered to receive gamepad events. In normal operation,
ConsumerBecameActive is called when the consumer is ready to
receive events and ConsumerBecameInactive is called when the
consumer wants to temporarily pause events without
unregistering. The |num_active_consumers_| member tracks how
many consumers are currently active and should always equal
the count of consumers in |consumers_| that have the is_active
flag set.

If a consumer calls these methods in an invalid order, this
invariant may be broken. For instance, calling
ConsumerBecameInactive will decrement |num_active_consumers_|
even if the consumer was already inactive. This CL enforces
the invariant by changing DCHECKs into CHECKs.

This also fixes a bug where consumers_.end() may be
dereferenced when ConsumerBecameInactive is called for a
consumer that was never added to |consumers_|.

BUG=998431

Change-Id: I86c53a481601cf05a66b3b0a8b011412660c805e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1804379
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697706}
4 files changed