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

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

Issue 2522843002: Convert Gamepad IPC messages into mojo interface. (Closed)
Patch Set: add GetSharedMemoryHandle() 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 if (is_started_)
blundell 2016/12/05 15:22:34 You shouldn't handle a condition that you've DCHEC
ke.he 2016/12/06 09:51:27 Done.
47 return;
48
49 is_started_ = true;
50 service->ConsumerBecameActive(this);
51 base::SharedMemoryHandle renderer_handle = service->GetSharedMemoryHandle();
52 // TODO(heke): Use mojo::SharedBuffer rather than base::Sharedmemory in
53 // GamepadSharedBuffer. See crbug.com/670655 for details.
54 callback.Run(mojo::WrapSharedMemoryHandle(
55 renderer_handle, sizeof(GamepadHardwareBuffer), true /* read_only */));
56 }
57
58 void GamepadMonitor::GamepadStopPolling(
59 const GamepadStopPollingCallback& callback) {
60 DCHECK(is_started_);
61 if (!is_started_)
blundell 2016/12/05 15:22:34 same comment as above.
ke.he 2016/12/06 09:51:27 Done.
62 return;
63
64 is_started_ = false;
65 GamepadService::GetInstance()->ConsumerBecameInactive(this);
66 callback.Run();
67 }
68
69 void GamepadMonitor::SetObserver(
70 device::mojom::GamepadObserverPtr gamepad_observer) {
71 gamepad_observer_ = std::move(gamepad_observer);
72 }
73
74 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698