Chromium Code Reviews| Index: content/browser/renderer_host/gamepad_monitor.cc |
| diff --git a/content/browser/renderer_host/gamepad_monitor.cc b/content/browser/renderer_host/gamepad_monitor.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4234557d132d532bf2b8ec557add185fdc9b8387 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/gamepad_monitor.cc |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/renderer_host/gamepad_monitor.h" |
| + |
| +#include "base/memory/shared_memory.h" |
| +#include "content/browser/gamepad/gamepad_service.h" |
| +#include "content/common/gamepad_hardware_buffer.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "mojo/public/cpp/bindings/strong_binding.h" |
| +#include "mojo/public/cpp/system/platform_handle.h" |
| + |
| +namespace content { |
| + |
| +GamepadMonitor::GamepadMonitor() : is_started_(false) {} |
| + |
| +GamepadMonitor::~GamepadMonitor() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (is_started_) |
| + GamepadService::GetInstance()->RemoveConsumer(this); |
| +} |
| + |
| +// static |
| +void GamepadMonitor::Create(device::mojom::GamepadMonitorRequest request) { |
| + mojo::MakeStrongBinding(base::MakeUnique<GamepadMonitor>(), |
| + std::move(request)); |
| +} |
| + |
| +void GamepadMonitor::OnGamepadConnected(unsigned index, |
| + const blink::WebGamepad& gamepad) { |
| + if (gamepad_observer_) |
| + gamepad_observer_->GamepadConnected(index, gamepad); |
| +} |
| + |
| +void GamepadMonitor::OnGamepadDisconnected(unsigned index, |
| + const blink::WebGamepad& gamepad) { |
| + if (gamepad_observer_) |
| + gamepad_observer_->GamepadDisconnected(index, gamepad); |
| +} |
| + |
| +void GamepadMonitor::GamepadStartPolling( |
| + const GamepadStartPollingCallback& callback) { |
| + GamepadService* service = GamepadService::GetInstance(); |
| + DCHECK(!is_started_); |
| + if (is_started_) |
| + return; |
| + |
| + is_started_ = true; |
| + service->ConsumerBecameActive(this); |
| + base::SharedMemoryHandle renderer_handle = |
| + 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
|
| + callback.Run(mojo::WrapSharedMemoryHandle( |
| + renderer_handle, sizeof(GamepadHardwareBuffer), true /* read_only */)); |
| +} |
| + |
| +void GamepadMonitor::GamepadStopPolling() { |
| + DCHECK(is_started_); |
| + if (!is_started_) |
| + return; |
| + |
| + is_started_ = false; |
| + GamepadService::GetInstance()->ConsumerBecameInactive(this); |
| +} |
| + |
| +void GamepadMonitor::SetObserver( |
| + device::mojom::GamepadObserverPtr gamepad_observer) { |
| + gamepad_observer_ = std::move(gamepad_observer); |
| +} |
| + |
| +} // namespace content |