Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: components/exo/gaming_seat.h

Issue 2900773003: Allow gaming_seat to use ozone gamepad as back-end (Closed)
Patch Set: Allow gaming_seat to use ozone gamepad as backend Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/exo/BUILD.gn ('k') | components/exo/gaming_seat.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/exo/gaming_seat.h
diff --git a/components/exo/gaming_seat.h b/components/exo/gaming_seat.h
index 40e44ae33352eeb4cf86c473177ce37d6e52c548..2c9787f08a9cb23e856b28fa1e0a4748e277d505 100644
--- a/components/exo/gaming_seat.h
+++ b/components/exo/gaming_seat.h
@@ -7,6 +7,7 @@
#include <memory>
+#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
@@ -17,6 +18,10 @@
#include "device/gamepad/gamepad_data_fetcher.h"
#include "ui/aura/client/focus_change_observer.h"
+#if defined(USE_OZONE_GAMEPAD)
+#include "ui/events/ozone/gamepad/gamepad_observer.h"
+#endif
+
namespace exo {
class GamingSeatDelegate;
class GamepadDelegate;
@@ -24,29 +29,43 @@ class GamepadDelegate;
using CreateGamepadDataFetcherCallback =
base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>;
-// This class represents one gaming seat, it uses a background thread
-// for polling gamepad devices and notifies the corresponding GampadDelegate of
-// any changes.
-class GamingSeat : public WMHelper::FocusObserver {
+// TODO(jkwang): always use ozone_gamepad when ozone is default for all Chrome
+// OS builds. https://crbug.com/717246
+// This class represents one gaming seat. It uses /device/gamepad or
+// ozone/gamepad as backend and notifies corresponding GamepadDelegate of any
+// gamepad changes.
+class GamingSeat : public WMHelper::FocusObserver
+#if defined(USE_OZONE_GAMEPAD)
+ ,
+ public ui::GamepadObserver
+#endif
+{
public:
- // This class will post tasks to invoke the delegate on the thread runner
- // which is associated with the thread that is creating this instance.
+ // This class will monitor gamepad connection changes and manage gamepad
+ // returned by gaming_seat_delegate.
GamingSeat(GamingSeatDelegate* gaming_seat_delegate,
base::SingleThreadTaskRunner* polling_task_runner);
- // Allows test cases to specify a CreateGamepadDataFetcherCallback that
- // overrides the default GamepadPlatformDataFetcher.
- GamingSeat(GamingSeatDelegate* gaming_seat_delegate,
- base::SingleThreadTaskRunner* polling_task_runner,
- CreateGamepadDataFetcherCallback create_fetcher_callback);
-
~GamingSeat() override;
- // Overridden WMHelper::FocusObserver:
+ // Overridden from WMHelper::FocusObserver:
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override;
+#if defined(USE_OZONE_GAMEPAD)
+ // Overridden from ui::GamepadObserver:
+ void OnGamepadDevicesUpdated() override;
+ void OnGamepadEvent(const ui::GamepadEvent& event) override;
+#endif
+
private:
+ // The delegate that handles gamepad_added.
+ GamingSeatDelegate* const delegate_;
+
+#if defined(USE_OZONE_GAMEPAD)
+ // Contains the delegate for each gamepad device.
+ base::flat_map<int, GamepadDelegate*> gamepads_;
+#else
class ThreadSafeGamepadChangeFetcher;
// Processes updates of gamepad data and passes changes on to delegate.
@@ -56,9 +75,6 @@ class GamingSeat : public WMHelper::FocusObserver {
// polling thread.
scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_;
- // The delegate that handles gamepad_added.
- GamingSeatDelegate* const delegate_;
-
// The delegate instances that all other events are dispatched to.
GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap];
@@ -66,9 +82,10 @@ class GamingSeat : public WMHelper::FocusObserver {
device::Gamepads pad_state_;
// ThreadChecker for the origin thread.
- base::ThreadChecker thread_checker_;
+ THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<GamingSeat> weak_ptr_factory_;
+#endif
DISALLOW_COPY_AND_ASSIGN(GamingSeat);
};
« no previous file with comments | « components/exo/BUILD.gn ('k') | components/exo/gaming_seat.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698