Chromium Code Reviews| Index: components/exo/gamepad.h |
| diff --git a/components/exo/gamepad.h b/components/exo/gamepad.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b11d9141610460b41649082c640d7c0d5a1b0b99 |
| --- /dev/null |
| +++ b/components/exo/gamepad.h |
| @@ -0,0 +1,84 @@ |
| +// 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/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; |
| + |
| +// 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. |
| + explicit Gamepad(GamepadDelegate* delegate); |
| + // Allows test cases to specify a GamepadDataFetcher to provide mock gamepad |
| + // data. |
| + Gamepad(GamepadDelegate* delegate, |
| + std::unique_ptr<device::GamepadDataFetcher> fetcher); |
| + virtual ~Gamepad(); |
| + |
| + // Overridden aura::client::FocusChangeObserver: |
| + void OnWindowFocused(aura::Window* gained_focus, |
| + aura::Window* lost_focus) override; |
| + |
| + private: |
| + // Schedules a poll on the polling thread. Can be called from any thread. |
| + void ScheduleOnPoll(); |
| + |
| + // Polls devices for new data and posts delegate updates. |
| + // Can only be called on the polling thread. |
| + void OnPoll(); |
| + |
| + // Posts updates of gamepad data to delegate. |
| + // Can only be called on the polling thread. |
| + void PostGamepadChanges(const blink::WebGamepads new_state); |
| + |
| + // Initializes the underlying gamepad data fetcher. |
| + // Can only be called on the polling thread. |
| + void InitializePollingThread(); |
| + |
| + // The delegate instance that all events are dispatched to. |
| + GamepadDelegate* const delegate_; |
| + |
| + // Implements the logic to fetch gamepad information from connected devices. |
| + // Only used by polling thread. |
| + std::unique_ptr<device::GamepadDataFetcher> fetcher_; |
| + |
| + // The current state of gamepad. Only used by polling thread. |
| + blink::WebGamepads state_; |
| + |
| + // The thread on which the polling is executed. |
| + std::unique_ptr<base::Thread> polling_thread_; |
| + |
| + // True if an exosphere window is currently focused. |
| + bool exo_focused_; |
|
reveman
2016/06/30 01:19:05
I don't think this is enough. How do we know that
denniskempin
2016/06/30 03:23:43
I can do the CanAcceptKeyboardEventsForSurface equ
denniskempin
2016/06/30 17:08:29
Done.
|
| + |
| + // Locks internal state |
| + base::Lock lock_; |
| + |
| + // Reference to the task runner of the thread that created this instance. |
| + scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; |
| + |
| + base::ThreadChecker thread_checker_; |
|
reveman
2016/06/30 01:19:05
I think a thread checker is a good idea but I'm no
denniskempin
2016/06/30 17:08:29
I used to. With the latest update I changed it to
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(Gamepad); |
| +}; |
| + |
| +} // namespace exo |
| + |
| +#endif // COMPONENTS_EXO_GAMEPAD_H_ |