| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/gamepad/gamepad_monitor.h" | 5 #include "device/gamepad/gamepad_monitor.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 8 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 9 #include "device/gamepad/gamepad_service.h" | 11 #include "device/gamepad/gamepad_service.h" |
| 10 #include "device/gamepad/gamepad_shared_buffer.h" | 12 #include "device/gamepad/gamepad_shared_buffer.h" |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 12 | 14 |
| 13 namespace device { | 15 namespace device { |
| 14 | 16 |
| 15 GamepadMonitor::GamepadMonitor() : is_started_(false) {} | 17 GamepadMonitor::GamepadMonitor() : is_started_(false) {} |
| 16 | 18 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 31 if (gamepad_observer_) | 33 if (gamepad_observer_) |
| 32 gamepad_observer_->GamepadConnected(index, gamepad); | 34 gamepad_observer_->GamepadConnected(index, gamepad); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void GamepadMonitor::OnGamepadDisconnected(unsigned index, | 37 void GamepadMonitor::OnGamepadDisconnected(unsigned index, |
| 36 const Gamepad& gamepad) { | 38 const Gamepad& gamepad) { |
| 37 if (gamepad_observer_) | 39 if (gamepad_observer_) |
| 38 gamepad_observer_->GamepadDisconnected(index, gamepad); | 40 gamepad_observer_->GamepadDisconnected(index, gamepad); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void GamepadMonitor::GamepadStartPolling( | 43 void GamepadMonitor::GamepadStartPolling(GamepadStartPollingCallback callback) { |
| 42 const GamepadStartPollingCallback& callback) { | |
| 43 DCHECK(!is_started_); | 44 DCHECK(!is_started_); |
| 44 is_started_ = true; | 45 is_started_ = true; |
| 45 | 46 |
| 46 GamepadService* service = GamepadService::GetInstance(); | 47 GamepadService* service = GamepadService::GetInstance(); |
| 47 service->ConsumerBecameActive(this); | 48 service->ConsumerBecameActive(this); |
| 48 callback.Run(service->GetSharedBufferHandle()); | 49 std::move(callback).Run(service->GetSharedBufferHandle()); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void GamepadMonitor::GamepadStopPolling( | 52 void GamepadMonitor::GamepadStopPolling(GamepadStopPollingCallback callback) { |
| 52 const GamepadStopPollingCallback& callback) { | |
| 53 DCHECK(is_started_); | 53 DCHECK(is_started_); |
| 54 is_started_ = false; | 54 is_started_ = false; |
| 55 | 55 |
| 56 GamepadService::GetInstance()->ConsumerBecameInactive(this); | 56 GamepadService::GetInstance()->ConsumerBecameInactive(this); |
| 57 callback.Run(); | 57 std::move(callback).Run(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void GamepadMonitor::SetObserver(mojom::GamepadObserverPtr gamepad_observer) { | 60 void GamepadMonitor::SetObserver(mojom::GamepadObserverPtr gamepad_observer) { |
| 61 gamepad_observer_ = std::move(gamepad_observer); | 61 gamepad_observer_ = std::move(gamepad_observer); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace device | 64 } // namespace device |
| OLD | NEW |