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

Side by Side Diff: device/gamepad/gamepad_monitor.cc

Issue 2808093006: [Device Service] Move Gamepad Blink headers to be part of the Gamepad client library (Closed)
Patch Set: rebase and address comments Created 3 years, 8 months 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
« no previous file with comments | « device/gamepad/gamepad_monitor.h ('k') | device/gamepad/gamepad_pad_state_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/gamepad/gamepad_monitor.h" 5 #include "device/gamepad/gamepad_monitor.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "device/gamepad/gamepad_service.h" 9 #include "device/gamepad/gamepad_service.h"
10 #include "device/gamepad/gamepad_shared_buffer.h" 10 #include "device/gamepad/gamepad_shared_buffer.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h" 11 #include "mojo/public/cpp/bindings/strong_binding.h"
12 12
13 namespace device { 13 namespace device {
14 14
15 GamepadMonitor::GamepadMonitor() : is_started_(false) {} 15 GamepadMonitor::GamepadMonitor() : is_started_(false) {}
16 16
17 GamepadMonitor::~GamepadMonitor() { 17 GamepadMonitor::~GamepadMonitor() {
18 if (is_started_) 18 if (is_started_)
19 GamepadService::GetInstance()->RemoveConsumer(this); 19 GamepadService::GetInstance()->RemoveConsumer(this);
20 } 20 }
21 21
22 // static 22 // static
23 void GamepadMonitor::Create(mojom::GamepadMonitorRequest request) { 23 void GamepadMonitor::Create(mojom::GamepadMonitorRequest request) {
24 mojo::MakeStrongBinding(base::MakeUnique<GamepadMonitor>(), 24 mojo::MakeStrongBinding(base::MakeUnique<GamepadMonitor>(),
25 std::move(request)); 25 std::move(request));
26 } 26 }
27 27
28 void GamepadMonitor::OnGamepadConnected(unsigned index, 28 void GamepadMonitor::OnGamepadConnected(unsigned index,
29 const blink::WebGamepad& gamepad) { 29 const Gamepad& gamepad) {
30 if (gamepad_observer_) 30 if (gamepad_observer_)
31 gamepad_observer_->GamepadConnected(index, gamepad); 31 gamepad_observer_->GamepadConnected(index, gamepad);
32 } 32 }
33 33
34 void GamepadMonitor::OnGamepadDisconnected(unsigned index, 34 void GamepadMonitor::OnGamepadDisconnected(unsigned index,
35 const blink::WebGamepad& gamepad) { 35 const Gamepad& gamepad) {
36 if (gamepad_observer_) 36 if (gamepad_observer_)
37 gamepad_observer_->GamepadDisconnected(index, gamepad); 37 gamepad_observer_->GamepadDisconnected(index, gamepad);
38 } 38 }
39 39
40 void GamepadMonitor::GamepadStartPolling( 40 void GamepadMonitor::GamepadStartPolling(
41 const GamepadStartPollingCallback& callback) { 41 const GamepadStartPollingCallback& callback) {
42 DCHECK(!is_started_); 42 DCHECK(!is_started_);
43 is_started_ = true; 43 is_started_ = true;
44 44
45 GamepadService* service = GamepadService::GetInstance(); 45 GamepadService* service = GamepadService::GetInstance();
46 service->ConsumerBecameActive(this); 46 service->ConsumerBecameActive(this);
47 callback.Run(service->GetSharedBufferHandle()); 47 callback.Run(service->GetSharedBufferHandle());
48 } 48 }
49 49
50 void GamepadMonitor::GamepadStopPolling( 50 void GamepadMonitor::GamepadStopPolling(
51 const GamepadStopPollingCallback& callback) { 51 const GamepadStopPollingCallback& callback) {
52 DCHECK(is_started_); 52 DCHECK(is_started_);
53 is_started_ = false; 53 is_started_ = false;
54 54
55 GamepadService::GetInstance()->ConsumerBecameInactive(this); 55 GamepadService::GetInstance()->ConsumerBecameInactive(this);
56 callback.Run(); 56 callback.Run();
57 } 57 }
58 58
59 void GamepadMonitor::SetObserver(mojom::GamepadObserverPtr gamepad_observer) { 59 void GamepadMonitor::SetObserver(mojom::GamepadObserverPtr gamepad_observer) {
60 gamepad_observer_ = std::move(gamepad_observer); 60 gamepad_observer_ = std::move(gamepad_observer);
61 } 61 }
62 62
63 } // namespace device 63 } // namespace device
OLDNEW
« no previous file with comments | « device/gamepad/gamepad_monitor.h ('k') | device/gamepad/gamepad_pad_state_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698