OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #ifndef COMPONENTS_EXO_GAMEPAD_H_ | |
6 #define COMPONENTS_EXO_GAMEPAD_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/sequenced_task_runner.h" | |
12 #include "base/threading/thread.h" | |
13 #include "base/threading/thread_task_runner_handle.h" | |
14 #include "device/gamepad/gamepad_data_fetcher.h" | |
15 | |
16 namespace exo { | |
17 class GamepadDelegate; | |
18 | |
19 // This class represents one or more gamepads, it implements a background thread | |
20 // for polling gamepad devices and notifies the GamepadDelegate of any | |
21 // changes. | |
22 class Gamepad { | |
23 public: | |
24 // This class will post tasks to invoke the delegate on the thread runner | |
25 // which is associated with the thread that is creating this instance. | |
26 Gamepad(GamepadDelegate* delegate); | |
reveman
2016/06/29 21:55:45
nit: explicit
denniskempin
2016/06/30 00:29:22
Done.
| |
27 | |
reveman
2016/06/29 21:55:45
nit: remove this blank line to ctors and dtor in o
denniskempin
2016/06/30 00:29:22
Done.
| |
28 // Allows test cases to specify a GamepadDataFetcher to provide mock gamepad | |
29 // data. | |
30 Gamepad(GamepadDelegate* delegate, | |
31 std::unique_ptr<device::GamepadDataFetcher> fetcher); | |
32 virtual ~Gamepad(); | |
33 | |
34 private: | |
35 // Schedules a poll on the polling thread. Can be called from any thread. | |
36 void ScheduleOnPoll(); | |
37 | |
38 // Polls devices for new data and posts delegate updates. | |
39 // Can only be called on the polling thread. | |
40 void OnPoll(); | |
41 | |
42 // Posts updates of gamepad data to delegate. | |
43 // Can only be called on the polling thread. | |
44 void PostGamepadChanges(const blink::WebGamepads new_state); | |
45 | |
46 // Initializes the underlying gamepad data fetcher. | |
47 // Can only be called on the polling thread. | |
48 void InitializePollingThread(); | |
49 | |
50 // The delegate instance that all events are dispatched to. | |
51 GamepadDelegate* const delegate_; | |
52 | |
53 // Implements the logic to fetch gamepad information from connected devices. | |
54 std::unique_ptr<device::GamepadDataFetcher> fetcher_; | |
55 | |
56 // The thread on which the polling is executed. | |
57 std::unique_ptr<base::Thread> polling_thread_; | |
58 | |
59 // The current state of gamepad. | |
60 blink::WebGamepads state_; | |
61 | |
62 // Reference to the task runner of the thread that created this instance. | |
63 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; | |
64 | |
65 base::ThreadChecker thread_checker_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(Gamepad); | |
68 }; | |
69 | |
70 } // namespace exo | |
71 | |
72 #endif // COMPONENTS_EXO_GAMEPAD_H_ | |
OLD | NEW |