OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_EXO_GAMEPAD_H_ | 5 #ifndef COMPONENTS_EXO_GAMEPAD_H_ |
6 #define COMPONENTS_EXO_GAMEPAD_H_ | 6 #define COMPONENTS_EXO_GAMEPAD_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "components/exo/wm_helper.h" |
16 #include "device/gamepad/gamepad_data_fetcher.h" | 17 #include "device/gamepad/gamepad_data_fetcher.h" |
17 #include "ui/aura/client/focus_change_observer.h" | 18 #include "ui/aura/client/focus_change_observer.h" |
18 | 19 |
19 namespace exo { | 20 namespace exo { |
20 class GamepadDelegate; | 21 class GamepadDelegate; |
21 | 22 |
22 using CreateGamepadDataFetcherCallback = | 23 using CreateGamepadDataFetcherCallback = |
23 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; | 24 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; |
24 | 25 |
25 // This class represents one or more gamepads, it uses a background thread | 26 // This class represents one or more gamepads, it uses a background thread |
26 // for polling gamepad devices and notifies the GamepadDelegate of any | 27 // for polling gamepad devices and notifies the GamepadDelegate of any |
27 // changes. | 28 // changes. |
28 class Gamepad : public aura::client::FocusChangeObserver { | 29 class Gamepad : public WMHelper::FocusObserver { |
29 public: | 30 public: |
30 // This class will post tasks to invoke the delegate on the thread runner | 31 // This class will post tasks to invoke the delegate on the thread runner |
31 // which is associated with the thread that is creating this instance. | 32 // which is associated with the thread that is creating this instance. |
32 Gamepad(GamepadDelegate* delegate, | 33 Gamepad(GamepadDelegate* delegate, |
33 base::SingleThreadTaskRunner* polling_task_runner); | 34 base::SingleThreadTaskRunner* polling_task_runner); |
34 // Allows test cases to specify a CreateGamepadDataFetcherCallback that | 35 // Allows test cases to specify a CreateGamepadDataFetcherCallback that |
35 // overrides the default GamepadPlatformDataFetcher. | 36 // overrides the default GamepadPlatformDataFetcher. |
36 Gamepad(GamepadDelegate* delegate, | 37 Gamepad(GamepadDelegate* delegate, |
37 base::SingleThreadTaskRunner* polling_task_runner, | 38 base::SingleThreadTaskRunner* polling_task_runner, |
38 CreateGamepadDataFetcherCallback create_fetcher_callback); | 39 CreateGamepadDataFetcherCallback create_fetcher_callback); |
39 ~Gamepad() override; | 40 ~Gamepad() override; |
40 | 41 |
41 // Overridden aura::client::FocusChangeObserver: | 42 // Overridden WMHelper::FocusObserver: |
42 void OnWindowFocused(aura::Window* gained_focus, | 43 void OnWindowFocused(aura::Window* gained_focus, |
43 aura::Window* lost_focus) override; | 44 aura::Window* lost_focus) override; |
44 | 45 |
45 private: | 46 private: |
46 class ThreadSafeGamepadChangeFetcher; | 47 class ThreadSafeGamepadChangeFetcher; |
47 | 48 |
48 // Processes updates of gamepad data and passes changes on to delegate. | 49 // Processes updates of gamepad data and passes changes on to delegate. |
49 void ProcessGamepadChanges(const blink::WebGamepad new_pad); | 50 void ProcessGamepadChanges(const blink::WebGamepad new_pad); |
50 | 51 |
51 // Private implementation of methods and resources that are used on the | 52 // Private implementation of methods and resources that are used on the |
(...skipping 10 matching lines...) Expand all Loading... |
62 base::ThreadChecker thread_checker_; | 63 base::ThreadChecker thread_checker_; |
63 | 64 |
64 base::WeakPtrFactory<Gamepad> weak_factory_; | 65 base::WeakPtrFactory<Gamepad> weak_factory_; |
65 | 66 |
66 DISALLOW_COPY_AND_ASSIGN(Gamepad); | 67 DISALLOW_COPY_AND_ASSIGN(Gamepad); |
67 }; | 68 }; |
68 | 69 |
69 } // namespace exo | 70 } // namespace exo |
70 | 71 |
71 #endif // COMPONENTS_EXO_GAMEPAD_H_ | 72 #endif // COMPONENTS_EXO_GAMEPAD_H_ |
OLD | NEW |