Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: content/browser/renderer_host/gamepad_monitor.cc

Issue 2522843002: Convert Gamepad IPC messages into mojo interface. (Closed)
Patch Set: hide the "sharedmemory wrap" in GamepadService. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
47 is_started_ = true;
48 service->ConsumerBecameActive(this);
49 callback.Run(service->GetSharedMemoryHandle());
50 }
51
52 void GamepadMonitor::GamepadStopPolling(
53 const GamepadStopPollingCallback& callback) {
54 DCHECK(is_started_);
55
56 is_started_ = false;
57 GamepadService::GetInstance()->ConsumerBecameInactive(this);
58 callback.Run();
59 }
60
61 void GamepadMonitor::SetObserver(
62 device::mojom::GamepadObserverPtr gamepad_observer) {
63 gamepad_observer_ = std::move(gamepad_observer);
64 }
65
66 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698