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/synchronization/lock.h" | |
13 #include "base/threading/thread.h" | |
14 #include "base/threading/thread_task_runner_handle.h" | |
15 #include "device/gamepad/gamepad_data_fetcher.h" | |
16 #include "ui/aura/client/focus_change_observer.h" | |
17 | |
18 namespace exo { | |
19 class GamepadDelegate; | |
20 | |
21 // This class represents one or more gamepads, it implements a background thread | |
22 // for polling gamepad devices and notifies the GamepadDelegate of any | |
23 // changes. | |
24 class Gamepad : public aura::client::FocusChangeObserver { | |
25 public: | |
26 // This class will post tasks to invoke the delegate on the thread runner | |
27 // which is associated with the thread that is creating this instance. | |
28 explicit Gamepad(GamepadDelegate* delegate); | |
29 // Allows test cases to specify a GamepadDataFetcher to provide mock gamepad | |
30 // data. | |
31 Gamepad(GamepadDelegate* delegate, | |
32 std::unique_ptr<device::GamepadDataFetcher> fetcher); | |
33 virtual ~Gamepad(); | |
34 | |
35 // Overridden aura::client::FocusChangeObserver: | |
36 void OnWindowFocused(aura::Window* gained_focus, | |
37 aura::Window* lost_focus) override; | |
38 | |
39 private: | |
40 // Schedules a poll on the polling thread. Can be called from any thread. | |
41 void ScheduleOnPoll(); | |
42 | |
43 // Polls devices for new data and posts delegate updates. | |
44 // Can only be called on the polling thread. | |
45 void OnPoll(); | |
46 | |
47 // Posts updates of gamepad data to delegate. | |
48 // Can only be called on the polling thread. | |
49 void PostGamepadChanges(const blink::WebGamepads new_state); | |
50 | |
51 // Initializes the underlying gamepad data fetcher. | |
52 // Can only be called on the polling thread. | |
53 void InitializePollingThread(); | |
54 | |
55 // The delegate instance that all events are dispatched to. | |
56 GamepadDelegate* const delegate_; | |
57 | |
58 // Implements the logic to fetch gamepad information from connected devices. | |
59 // Only used by polling thread. | |
60 std::unique_ptr<device::GamepadDataFetcher> fetcher_; | |
61 | |
62 // The current state of gamepad. Only used by polling thread. | |
63 blink::WebGamepads state_; | |
64 | |
65 // The thread on which the polling is executed. | |
66 std::unique_ptr<base::Thread> polling_thread_; | |
67 | |
68 // True if an exosphere window is currently focused. | |
69 bool exo_focused_; | |
reveman
2016/06/30 01:19:05
I don't think this is enough. How do we know that
denniskempin
2016/06/30 03:23:43
I can do the CanAcceptKeyboardEventsForSurface equ
denniskempin
2016/06/30 17:08:29
Done.
| |
70 | |
71 // Locks internal state | |
72 base::Lock lock_; | |
73 | |
74 // Reference to the task runner of the thread that created this instance. | |
75 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; | |
76 | |
77 base::ThreadChecker thread_checker_; | |
reveman
2016/06/30 01:19:05
I think a thread checker is a good idea but I'm no
denniskempin
2016/06/30 17:08:29
I used to. With the latest update I changed it to
| |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(Gamepad); | |
80 }; | |
81 | |
82 } // namespace exo | |
83 | |
84 #endif // COMPONENTS_EXO_GAMEPAD_H_ | |
OLD | NEW |