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 #include "mojo/public/cpp/system/platform_handle.h" | |
13 | |
14 namespace content { | |
15 | |
16 GamepadMonitor::GamepadMonitor() : is_started_(false) {} | |
17 | |
18 GamepadMonitor::~GamepadMonitor() { | |
19 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
20 if (is_started_) | |
21 GamepadService::GetInstance()->RemoveConsumer(this); | |
22 } | |
23 | |
24 // static | |
25 void GamepadMonitor::Create(device::mojom::GamepadMonitorRequest request) { | |
26 mojo::MakeStrongBinding(base::MakeUnique<GamepadMonitor>(), | |
27 std::move(request)); | |
28 } | |
29 | |
30 void GamepadMonitor::OnGamepadConnected(unsigned index, | |
31 const blink::WebGamepad& gamepad) { | |
32 if (gamepad_observer_) | |
33 gamepad_observer_->GamepadConnected(index, gamepad); | |
34 } | |
35 | |
36 void GamepadMonitor::OnGamepadDisconnected(unsigned index, | |
37 const blink::WebGamepad& gamepad) { | |
38 if (gamepad_observer_) | |
39 gamepad_observer_->GamepadDisconnected(index, gamepad); | |
40 } | |
41 | |
42 void GamepadMonitor::GamepadStartPolling( | |
43 const GamepadStartPollingCallback& callback) { | |
44 GamepadService* service = GamepadService::GetInstance(); | |
45 DCHECK(!is_started_); | |
46 if (is_started_) | |
47 return; | |
48 | |
49 is_started_ = true; | |
50 service->ConsumerBecameActive(this); | |
51 base::SharedMemoryHandle renderer_handle = | |
52 service->GetSharedMemoryHandleForProcess(base::GetCurrentProcessHandle()); | |
blundell
2016/11/29 15:36:24
I don't think that this is the same as what the co
ke.he
2016/11/30 05:45:11
The logic is here on purpose.
In the original base
blundell
2016/12/01 16:01:26
OK, this makes sense, thanks. The key is that mojo
blundell
2016/12/01 16:04:39
Sorry, the GamepadService method name should proba
ke.he
2016/12/02 13:20:47
blundell@, Thanks!
1) Add a new GetSharedMemoryHa
| |
53 callback.Run(mojo::WrapSharedMemoryHandle( | |
54 renderer_handle, sizeof(GamepadHardwareBuffer), true /* read_only */)); | |
55 } | |
56 | |
57 void GamepadMonitor::GamepadStopPolling() { | |
58 DCHECK(is_started_); | |
59 if (!is_started_) | |
60 return; | |
61 | |
62 is_started_ = false; | |
63 GamepadService::GetInstance()->ConsumerBecameInactive(this); | |
64 } | |
65 | |
66 void GamepadMonitor::SetObserver( | |
67 device::mojom::GamepadObserverPtr gamepad_observer) { | |
68 gamepad_observer_ = std::move(gamepad_observer); | |
69 } | |
70 | |
71 } // namespace content | |
OLD | NEW |