Commit 00a67f1d authored by Matt Reynolds's avatar Matt Reynolds Committed by Commit Bot

[gamepad] Unregister GamepadMonitor at destruction

Previously, GamepadMonitor would only remove itself as a gamepad
consumer if it was active (GamepadStartPolling called with no
corresponding GamepadStopPolling), and would leak if it was
inactive.

This CL ensures GamepadMonitor is always removed if it was ever
added as a gamepad consumer.

BUG=998128

Change-Id: If4f1ac4d1f3b6889acffeb584c2c6dc04b310e31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1804836Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697451}
parent aada6f56
......@@ -14,10 +14,10 @@
namespace device {
GamepadMonitor::GamepadMonitor() : is_started_(false) {}
GamepadMonitor::GamepadMonitor() = default;
GamepadMonitor::~GamepadMonitor() {
if (is_started_)
if (is_registered_consumer_)
GamepadService::GetInstance()->RemoveConsumer(this);
}
......@@ -49,6 +49,7 @@ void GamepadMonitor::OnGamepadButtonOrAxisChanged(uint32_t index,
void GamepadMonitor::GamepadStartPolling(GamepadStartPollingCallback callback) {
DCHECK(!is_started_);
is_started_ = true;
is_registered_consumer_ = true;
GamepadService* service = GamepadService::GetInstance();
service->ConsumerBecameActive(this);
......
......@@ -37,7 +37,12 @@ class DEVICE_GAMEPAD_EXPORT GamepadMonitor : public GamepadConsumer,
private:
mojo::Remote<mojom::GamepadObserver> gamepad_observer_remote_;
bool is_started_;
// True if this monitor is an active gamepad consumer.
bool is_started_ = false;
// True if this monitor has been registered with the gamepad service.
bool is_registered_consumer_ = false;
DISALLOW_COPY_AND_ASSIGN(GamepadMonitor);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment