Index: components/exo/gamepad.h |
diff --git a/components/exo/gamepad.h b/components/exo/gamepad.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f37cde07c0eec672f32840b6de859c696b75a305 |
--- /dev/null |
+++ b/components/exo/gamepad.h |
@@ -0,0 +1,76 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_EXO_GAMEPAD_H_ |
+#define COMPONENTS_EXO_GAMEPAD_H_ |
+ |
+#include <memory> |
+ |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/sequenced_task_runner.h" |
+#include "base/synchronization/lock.h" |
+#include "base/threading/thread.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "device/gamepad/gamepad_data_fetcher.h" |
+#include "ui/aura/client/focus_change_observer.h" |
+ |
+namespace exo { |
+class GamepadDelegate; |
+ |
+typedef base::Callback<std::unique_ptr<device::GamepadDataFetcher>()> |
reveman
2016/07/11 10:50:44
nit: using CreateGamepadDataFetcherCallback = base
denniskempin
2016/07/11 17:43:28
Done.
|
+ GamepadDataFetcherFactory; |
+ |
+// This class represents one or more gamepads, it implements a background thread |
+// for polling gamepad devices and notifies the GamepadDelegate of any |
+// changes. |
+class Gamepad : public aura::client::FocusChangeObserver { |
+ 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. |
+ Gamepad(GamepadDelegate* delegate, |
+ scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner); |
reveman
2016/07/11 10:50:44
nit: this will result in unnecessary ref-count chu
denniskempin
2016/07/11 17:43:28
Done.
|
+ // Allows test cases to specify a GamepadDataFetcherFactory that overrides |
+ // the default PlatformGamepadDataFetcher. |
+ Gamepad(GamepadDelegate* delegate, |
+ scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner, |
reveman
2016/07/11 10:50:44
nit: "base::SingleThreadTaskRunner* polling_task_r
denniskempin
2016/07/11 17:43:28
Done.
|
+ GamepadDataFetcherFactory fetcher_factory); |
+ ~Gamepad() override; |
+ |
+ // Overridden aura::client::FocusChangeObserver: |
+ void OnWindowFocused(aura::Window* gained_focus, |
+ aura::Window* lost_focus) override; |
+ |
+ private: |
+ // Private implementation of methods and resources that are used on the |
+ // polling thread. |
+ class PollingThreadResources; |
+ scoped_refptr<PollingThreadResources> polling_thread_resources_; |
reveman
2016/07/11 10:50:44
nit: member variables below types and functions
denniskempin
2016/07/11 17:43:28
Done.
|
+ |
+ // Posts updates of gamepad data to delegate. Can only be called on the |
+ // origin thread. |
+ void PostGamepadChanges(const blink::WebGamepad new_pad); |
reveman
2016/07/11 10:50:44
nit: "Handle" or "Process" instead of "Post" as po
denniskempin
2016/07/11 17:43:28
Done.
|
+ |
+ // Method implementing the default GamepadDataFetcherFactory, returning |
+ // ownership of an instance of GamepadPlatformDataFetcher. |
+ static std::unique_ptr<device::GamepadDataFetcher> |
+ GamepadPlatformDataFetcherFactory(); |
reveman
2016/07/11 10:50:44
nit: either move this into anonymouse namespace in
denniskempin
2016/07/11 17:43:28
Done.
|
+ |
+ // The delegate instance that all events are dispatched to. |
+ GamepadDelegate* const delegate_; |
+ |
+ // The current state of the gamepad represented by this instance. |
+ blink::WebGamepad pad_state_; |
+ |
+ // ThreadChecker for the origin thread. |
+ base::ThreadChecker thread_checker_; |
+ |
+ base::WeakPtrFactory<Gamepad> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Gamepad); |
+}; |
+ |
+} // namespace exo |
+ |
+#endif // COMPONENTS_EXO_GAMEPAD_H_ |