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

Unified Diff: components/exo/gamepad.h

Issue 2076013002: exo: Implement wayland gamepad support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serv
Patch Set: fixed nits and smaller issues Created 4 years, 5 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
Index: components/exo/gamepad.h
diff --git a/components/exo/gamepad.h b/components/exo/gamepad.h
new file mode 100644
index 0000000000000000000000000000000000000000..f254db79c0f029b69a3b72cabb05eb06d7543656
--- /dev/null
+++ b/components/exo/gamepad.h
@@ -0,0 +1,71 @@
+// 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;
+
+using CreateGamepadDataFetcherCallback =
+ base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>;
+
+// This class represents one or more gamepads, it implements a background thread
reveman 2016/07/11 18:45:01 nit: s/implements/uses/
denniskempin 2016/07/12 19:54:12 Done.
+// 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,
+ base::SingleThreadTaskRunner* polling_task_runner);
+ // Allows test cases to specify a CreateGamepadDataFetcherCallback that
+ // overrides the default GamepadPlatformDataFetcher.
+ Gamepad(GamepadDelegate* delegate,
+ base::SingleThreadTaskRunner* polling_task_runner,
+ CreateGamepadDataFetcherCallback create_fetcher_callback);
+ ~Gamepad() override;
+
+ // Overridden aura::client::FocusChangeObserver:
+ void OnWindowFocused(aura::Window* gained_focus,
+ aura::Window* lost_focus) override;
+
+ private:
+ class ThreadSafeGamepadChangeFetcher;
+
+ // Processes updates of gamepad data and passes changes on to delegate.
+ void ProcessGamepadChanges(const blink::WebGamepad new_pad);
+
+ // Private implementation of methods and resources that are used on the
+ // polling thread.
+ scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_;
+
+ // 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_
« no previous file with comments | « components/exo/DEPS ('k') | components/exo/gamepad.cc » ('j') | components/exo/gamepad.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698