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_GAMEPADS_H_ | |
6 #define COMPONENTS_EXO_GAMEPADS_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 "third_party/WebKit/public/platform/WebGamepads.h" | |
15 | |
16 namespace device { | |
17 class GamepadDataFetcher; | |
18 } | |
19 | |
20 namespace exo { | |
21 class GamepadsDelegate; | |
22 | |
23 // This class represents multiple gamepads, it implements a background thread | |
24 // for polling gamepad devices and notifies the GamepadsDelegate of any | |
25 // changes. | |
26 class Gamepads { | |
reveman
2016/06/27 17:30:35
I've made a similar comment on the interface chang
denniskempin
2016/06/29 17:12:26
Done.
| |
27 public: | |
28 // This class will post tasks to invoke the delegate on the thread runner | |
29 // which is associated with the thread that is creating this instance. | |
30 Gamepads(GamepadsDelegate* delegate); | |
31 | |
32 // Allows test cases to specify a GamepadDataFetcher to provide mock gamepad | |
33 // data. | |
34 Gamepads(GamepadsDelegate* delegate, | |
35 std::unique_ptr<device::GamepadDataFetcher> fetcher); | |
reveman
2016/06/27 17:30:35
Add SetGamepadDataFetcherForTesting function would
denniskempin
2016/06/29 17:12:25
Not sure we can do that since this class will init
| |
36 virtual ~Gamepads(); | |
37 | |
38 private: | |
39 // Schedules a poll on the polling thread. Can be called from any thread. | |
40 void ScheduleOnPoll(); | |
41 | |
42 // Polls devices for new data and posts delegate updates. | |
43 // Can only be called on the polling thread. | |
44 void OnPoll(); | |
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 GamepadsDelegate* delegate_; | |
reveman
2016/06/27 17:30:35
nit: GamepadsDelegate* const delegate_;
denniskempin
2016/06/29 17:12:25
Done.
| |
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_; | |
reveman
2016/06/27 17:30:35
Do we need to add a thread for this? Can we use an
denniskempin
2016/06/29 17:12:26
I've been following the code of GamepadService her
| |
58 | |
59 // The current state of gamepads. | |
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 DISALLOW_COPY_AND_ASSIGN(Gamepads); | |
reveman
2016/06/27 17:30:35
nit: blank line before this
denniskempin
2016/06/29 17:12:26
Done.
| |
67 }; | |
68 | |
69 } // namespace exo | |
70 | |
71 #endif // COMPONENTS_EXO_GAMEPADS_H_ | |
OLD | NEW |