OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/gamepad_monitor.h" | |
6 | |
7 #include "base/memory/shared_memory.h" | |
8 #include "content/browser/gamepad/gamepad_service.h" | |
9 #include "content/common/gamepad_hardware_buffer.h" | |
10 #include "content/public/browser/browser_thread.h" | |
11 #include "mojo/public/cpp/bindings/strong_binding.h" | |
12 | |
13 namespace content { | |
14 | |
15 GamepadMonitor::GamepadMonitor() : is_started_(false) {} | |
16 | |
17 GamepadMonitor::~GamepadMonitor() { | |
18 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
19 if (is_started_) | |
20 GamepadService::GetInstance()->RemoveConsumer(this); | |
21 } | |
22 | |
23 // static | |
24 void GamepadMonitor::Create(device::mojom::GamepadMonitorRequest request) { | |
25 mojo::MakeStrongBinding(base::MakeUnique<GamepadMonitor>(), | |
26 std::move(request)); | |
27 } | |
28 | |
29 void GamepadMonitor::OnGamepadConnected(unsigned index, | |
30 const blink::WebGamepad& gamepad) { | |
31 if (gamepad_observer_) | |
32 gamepad_observer_->GamepadConnected(index, gamepad); | |
33 } | |
34 | |
35 void GamepadMonitor::OnGamepadDisconnected(unsigned index, | |
36 const blink::WebGamepad& gamepad) { | |
37 if (gamepad_observer_) | |
38 gamepad_observer_->GamepadDisconnected(index, gamepad); | |
39 } | |
40 | |
41 void GamepadMonitor::GamepadStartPolling( | |
42 const GamepadStartPollingCallback& callback) { | |
43 DCHECK(!is_started_); | |
44 is_started_ = true; | |
45 | |
46 GamepadService* service = GamepadService::GetInstance(); | |
47 service->ConsumerBecameActive(this); | |
48 callback.Run(service->GetSharedBufferHandle()); | |
49 } | |
50 | |
51 void GamepadMonitor::GamepadStopPolling( | |
52 const GamepadStopPollingCallback& callback) { | |
53 DCHECK(is_started_); | |
54 is_started_ = false; | |
55 | |
56 GamepadService::GetInstance()->ConsumerBecameInactive(this); | |
57 callback.Run(); | |
58 } | |
59 | |
60 void GamepadMonitor::SetObserver( | |
61 device::mojom::GamepadObserverPtr gamepad_observer) { | |
62 gamepad_observer_ = std::move(gamepad_observer); | |
63 } | |
64 | |
65 } // namespace content | |
OLD | NEW |