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/memory/weak_ptr.h" |
| 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/synchronization/lock.h" |
| 14 #include "base/threading/thread.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "device/gamepad/gamepad_data_fetcher.h" |
| 17 #include "ui/aura/client/focus_change_observer.h" |
| 18 |
| 19 namespace exo { |
| 20 class GamepadDelegate; |
| 21 |
| 22 using CreateGamepadDataFetcherCallback = |
| 23 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; |
| 24 |
| 25 // This class represents one or more gamepads, it uses a background thread |
| 26 // for polling gamepad devices and notifies the GamepadDelegate of any |
| 27 // changes. |
| 28 class Gamepad : public aura::client::FocusChangeObserver { |
| 29 public: |
| 30 // 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 Gamepad(GamepadDelegate* delegate, |
| 33 base::SingleThreadTaskRunner* polling_task_runner); |
| 34 // Allows test cases to specify a CreateGamepadDataFetcherCallback that |
| 35 // overrides the default GamepadPlatformDataFetcher. |
| 36 Gamepad(GamepadDelegate* delegate, |
| 37 base::SingleThreadTaskRunner* polling_task_runner, |
| 38 CreateGamepadDataFetcherCallback create_fetcher_callback); |
| 39 ~Gamepad() override; |
| 40 |
| 41 // Overridden aura::client::FocusChangeObserver: |
| 42 void OnWindowFocused(aura::Window* gained_focus, |
| 43 aura::Window* lost_focus) override; |
| 44 |
| 45 private: |
| 46 class ThreadSafeGamepadChangeFetcher; |
| 47 |
| 48 // Processes updates of gamepad data and passes changes on to delegate. |
| 49 void ProcessGamepadChanges(const blink::WebGamepad new_pad); |
| 50 |
| 51 // Private implementation of methods and resources that are used on the |
| 52 // polling thread. |
| 53 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; |
| 54 |
| 55 // The delegate instance that all events are dispatched to. |
| 56 GamepadDelegate* const delegate_; |
| 57 |
| 58 // The current state of the gamepad represented by this instance. |
| 59 blink::WebGamepad pad_state_; |
| 60 |
| 61 // ThreadChecker for the origin thread. |
| 62 base::ThreadChecker thread_checker_; |
| 63 |
| 64 base::WeakPtrFactory<Gamepad> weak_factory_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(Gamepad); |
| 67 }; |
| 68 |
| 69 } // namespace exo |
| 70 |
| 71 #endif // COMPONENTS_EXO_GAMEPAD_H_ |
OLD | NEW |