Chromium Code Reviews| 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_GAMING_SEAT_H_ | 5 #ifndef COMPONENTS_EXO_GAMING_SEAT_H_ |
| 6 #define COMPONENTS_EXO_GAMING_SEAT_H_ | 6 #define COMPONENTS_EXO_GAMING_SEAT_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/gaming_seat.h" | |
|
reveman
2017/06/05 22:48:04
avoid including yourself
jkwang
2017/06/06 20:03:07
Sorry. Copy/paste mistake.
Done.
| |
| 16 #include "components/exo/wm_helper.h" | 17 #include "components/exo/wm_helper.h" |
| 17 #include "device/gamepad/gamepad_data_fetcher.h" | 18 #include "device/gamepad/gamepad_data_fetcher.h" |
| 18 #include "ui/aura/client/focus_change_observer.h" | 19 #include "ui/aura/client/focus_change_observer.h" |
| 19 | 20 |
| 21 #if defined(USE_OZONE_GAMEPAD) | |
| 22 #include "ui/events/ozone/gamepad/gamepad_observer.h" | |
| 23 | |
| 24 namespace ui { | |
| 25 class GamepadProviderOzone; | |
| 26 } | |
| 27 #endif | |
| 28 | |
| 29 namespace base { | |
| 30 class Thread; | |
| 31 } | |
| 32 | |
| 20 namespace exo { | 33 namespace exo { |
| 21 class GamingSeatDelegate; | 34 class GamingSeatDelegate; |
| 22 class GamepadDelegate; | 35 class GamepadDelegate; |
| 23 | 36 |
| 24 using CreateGamepadDataFetcherCallback = | 37 using CreateGamepadDataFetcherCallback = |
| 25 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; | 38 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; |
| 26 | 39 |
| 27 // This class represents one gaming seat, it uses a background thread | 40 // TODO(jkwang) always use ozone_gamepad when ozone is default for all chrome os |
| 28 // for polling gamepad devices and notifies the corresponding GampadDelegate of | 41 // build. |
| 29 // any changes. | 42 class GamingSeat : public WMHelper::FocusObserver |
| 30 class GamingSeat : public WMHelper::FocusObserver { | 43 #if defined(USE_OZONE_GAMEPAD) |
| 44 , | |
| 45 public ui::GamepadObserver | |
| 46 #endif | |
| 47 { | |
| 31 public: | 48 public: |
| 32 // This class will post tasks to invoke the delegate on the thread runner | 49 // This function will return pointer to polling thread if it will be needed by |
| 33 // which is associated with the thread that is creating this instance. | 50 // gaming_seat. Otherwise, it will return nullptr. The pointer should be later |
| 51 // used to construct GamingSeat. | |
| 52 static base::Thread* CreatePollingThreadIfNeeded(); | |
|
reveman
2017/06/05 22:48:03
please remove this and always create this thread a
jkwang
2017/06/06 20:03:07
Done.
| |
| 53 | |
| 54 // This class will monitor gamepad connection change and manage gamepad | |
| 55 // returned by gaming_seat_delegate. | |
| 34 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, | 56 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, |
| 35 base::SingleThreadTaskRunner* polling_task_runner); | 57 base::Thread* polling_thread); |
|
reveman
2017/06/05 22:48:03
"base::SingleThreadTaskRunner* polling_task_runner
jkwang
2017/06/06 20:03:07
Done.
| |
| 36 | 58 |
| 59 #if !defined(USE_OZONE_GAMEPAD) | |
|
reveman
2017/06/05 22:48:03
Let's just remove this testing only ctor a related
jkwang
2017/06/06 20:03:07
Make sense. If we are not going to change code of
| |
| 37 // Allows test cases to specify a CreateGamepadDataFetcherCallback that | 60 // Allows test cases to specify a CreateGamepadDataFetcherCallback that |
| 38 // overrides the default GamepadPlatformDataFetcher. | 61 // overrides the default GamepadPlatformDataFetcher. |
| 39 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, | 62 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, |
| 40 base::SingleThreadTaskRunner* polling_task_runner, | 63 base::SingleThreadTaskRunner* polling_task_runner, |
| 41 CreateGamepadDataFetcherCallback create_fetcher_callback); | 64 CreateGamepadDataFetcherCallback create_fetcher_callback); |
| 65 #endif | |
| 42 | 66 |
| 43 ~GamingSeat() override; | 67 ~GamingSeat() override; |
| 44 | 68 |
| 45 // Overridden WMHelper::FocusObserver: | 69 // Overridden WMHelper::FocusObserver: |
|
reveman
2017/06/05 22:48:03
while here, please change to: // Overridden from W
jkwang
2017/06/06 20:03:06
Done.
| |
| 46 void OnWindowFocused(aura::Window* gained_focus, | 70 void OnWindowFocused(aura::Window* gained_focus, |
| 47 aura::Window* lost_focus) override; | 71 aura::Window* lost_focus) override; |
| 72 private: | |
| 73 // The delegate that handles gamepad_added. | |
| 74 GamingSeatDelegate* const delegate_; | |
| 48 | 75 |
| 49 private: | 76 #if defined(USE_OZONE_GAMEPAD) |
| 77 // Overriden ui::GamepadObserver. These functions are overrided as private | |
|
reveman
2017/06/05 22:48:03
s/Overriden/Overridden/ and make it "// Overridden
jkwang
2017/06/06 20:03:07
Done.
| |
| 78 // because they should only be called from a base class(GamepadObserver). | |
| 79 void OnGamepadDevicesUpdated() override; | |
| 80 void OnGamepadEvent(const ui::GamepadEvent& event) override; | |
| 81 | |
| 82 // Enable or disable this gaming seat. | |
| 83 void Enable(bool enable); | |
| 84 | |
| 85 // This map maps device id to gamepad delegates. | |
|
reveman
2017/06/05 22:48:03
nit: describe what is stored in the map instead of
jkwang
2017/06/06 20:03:06
Done.
| |
| 86 std::map<int, GamepadDelegate*> gamepads_; | |
|
reveman
2017/06/05 22:48:04
base::flat_map
jkwang
2017/06/06 20:03:06
Done.
| |
| 87 | |
| 88 ui::GamepadProviderOzone* gamepad_provider_; | |
|
reveman
2017/06/05 22:48:04
nit: short comment above this for consistency
jkwang
2017/06/06 20:03:07
Done.
| |
| 89 | |
|
reveman
2017/06/05 22:48:04
nit: remove this blank line
jkwang
2017/06/06 20:03:07
Done.
| |
| 90 #else | |
| 50 class ThreadSafeGamepadChangeFetcher; | 91 class ThreadSafeGamepadChangeFetcher; |
| 51 | 92 |
| 52 // Processes updates of gamepad data and passes changes on to delegate. | 93 // Processes updates of gamepad data and passes changes on to delegate. |
| 53 void ProcessGamepadChanges(int index, const device::Gamepad new_pad); | 94 void ProcessGamepadChanges(int index, const device::Gamepad new_pad); |
| 54 | 95 |
| 55 // Private implementation of methods and resources that are used on the | 96 // Private implementation of methods and resources that are used on the |
| 56 // polling thread. | 97 // polling thread. |
| 57 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; | 98 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; |
| 58 | 99 |
| 59 // The delegate that handles gamepad_added. | |
| 60 GamingSeatDelegate* const delegate_; | |
| 61 | |
| 62 // The delegate instances that all other events are dispatched to. | 100 // The delegate instances that all other events are dispatched to. |
| 63 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap]; | 101 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap]; |
| 64 | 102 |
| 65 // The current state of the gamepad represented by this instance. | 103 // The current state of the gamepad represented by this instance. |
| 66 device::Gamepads pad_state_; | 104 device::Gamepads pad_state_; |
| 67 | 105 |
| 68 // ThreadChecker for the origin thread. | 106 // ThreadChecker for the origin thread. |
| 69 base::ThreadChecker thread_checker_; | 107 THREAD_CHECKER(thread_checker_); |
| 70 | 108 |
| 71 base::WeakPtrFactory<GamingSeat> weak_ptr_factory_; | 109 base::WeakPtrFactory<GamingSeat> weak_ptr_factory_; |
| 72 | 110 #endif |
| 73 DISALLOW_COPY_AND_ASSIGN(GamingSeat); | 111 DISALLOW_COPY_AND_ASSIGN(GamingSeat); |
|
reveman
2017/06/05 22:48:03
nit: blank line before this
jkwang
2017/06/06 20:03:06
Done.
| |
| 74 }; | 112 }; |
| 75 | 113 |
| 76 } // namespace exo | 114 } // namespace exo |
| 77 | |
| 78 #endif // COMPONENTS_EXO_GAMING_SEAT_H_ | 115 #endif // COMPONENTS_EXO_GAMING_SEAT_H_ |
| OLD | NEW |