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 "components/exo/wm_helper.h" |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 namespace base { |
| 11 #include "base/memory/weak_ptr.h" | 11 class Thread; |
| 12 #include "base/sequenced_task_runner.h" | 12 } |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "base/threading/thread.h" | |
| 15 #include "base/threading/thread_task_runner_handle.h" | |
| 16 #include "components/exo/wm_helper.h" | |
| 17 #include "device/gamepad/gamepad_data_fetcher.h" | |
| 18 #include "ui/aura/client/focus_change_observer.h" | |
| 19 | 13 |
| 20 namespace exo { | 14 namespace exo { |
| 21 class GamingSeatDelegate; | 15 class GamingSeatDelegate; |
| 22 class GamepadDelegate; | |
| 23 | 16 |
| 24 using CreateGamepadDataFetcherCallback = | 17 // TODO(jkwang): Remove this GamingSeat and always use ozone gamepad once ozone |
| 25 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; | 18 // is default for all chrome os. |
| 26 | |
| 27 // This class represents one gaming seat, it uses a background thread | |
| 28 // for polling gamepad devices and notifies the corresponding GampadDelegate of | |
| 29 // any changes. | |
| 30 class GamingSeat : public WMHelper::FocusObserver { | 19 class GamingSeat : public WMHelper::FocusObserver { |
| 31 public: | 20 public: |
| 32 // This class will post tasks to invoke the delegate on the thread runner | 21 static base::Thread* CreatePollingThreadIfNeeded(); |
| 33 // which is associated with the thread that is creating this instance. | |
| 34 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, | |
| 35 base::SingleThreadTaskRunner* polling_task_runner); | |
| 36 | 22 |
| 37 // Allows test cases to specify a CreateGamepadDataFetcherCallback that | 23 static GamingSeat* CreateGamingSeat(GamingSeatDelegate* gaming_seat_delegate, |
|
reveman
2017/05/31 22:42:23
do we need to use a factory pattern if this is now
jkwang
2017/06/01 19:43:15
No..It does not need to be like this, but I would
reveman
2017/06/01 22:24:52
Performance is not a concern of mine. Making the c
| |
| 38 // overrides the default GamepadPlatformDataFetcher. | 24 base::Thread* polling_thread); |
| 39 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, | |
| 40 base::SingleThreadTaskRunner* polling_task_runner, | |
| 41 CreateGamepadDataFetcherCallback create_fetcher_callback); | |
| 42 | |
| 43 ~GamingSeat() override; | |
| 44 | |
| 45 // Overridden WMHelper::FocusObserver: | |
| 46 void OnWindowFocused(aura::Window* gained_focus, | |
| 47 aura::Window* lost_focus) override; | |
| 48 | |
| 49 private: | |
| 50 class ThreadSafeGamepadChangeFetcher; | |
| 51 | |
| 52 // Processes updates of gamepad data and passes changes on to delegate. | |
| 53 void ProcessGamepadChanges(int index, const device::Gamepad new_pad); | |
| 54 | |
| 55 // Private implementation of methods and resources that are used on the | |
| 56 // polling thread. | |
| 57 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; | |
| 58 | |
| 59 // The delegate that handles gamepad_added. | |
| 60 GamingSeatDelegate* const delegate_; | |
| 61 | |
| 62 // The delegate instances that all other events are dispatched to. | |
| 63 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap]; | |
| 64 | |
| 65 // The current state of the gamepad represented by this instance. | |
| 66 device::Gamepads pad_state_; | |
| 67 | |
| 68 // ThreadChecker for the origin thread. | |
| 69 base::ThreadChecker thread_checker_; | |
| 70 | |
| 71 base::WeakPtrFactory<GamingSeat> weak_ptr_factory_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(GamingSeat); | |
| 74 }; | 25 }; |
| 75 | 26 |
| 76 } // namespace exo | 27 } // namespace exo |
| 77 | 28 |
| 78 #endif // COMPONENTS_EXO_GAMING_SEAT_H_ | 29 #endif // COMPONENTS_EXO_GAMING_SEAT_H_ |
| OLD | NEW |