summaryrefslogtreecommitdiffstats
path: root/content/browser/gamepad/gamepad_service.h
diff options
context:
space:
mode:
authorb.kelemen@samsung.com <b.kelemen@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-09 09:09:47 +0000
committerb.kelemen@samsung.com <b.kelemen@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-09 09:09:47 +0000
commit0ff7365690e19be1f20fe83ab9001205989ae13f (patch)
tree5781167bec440aeaec1be61d65010b17f91bdc45 /content/browser/gamepad/gamepad_service.h
parent32080c3798792f0f2a46b3da88971a4125690a08 (diff)
downloadchromium_src-0ff7365690e19be1f20fe83ab9001205989ae13f.zip
chromium_src-0ff7365690e19be1f20fe83ab9001205989ae13f.tar.gz
chromium_src-0ff7365690e19be1f20fe83ab9001205989ae13f.tar.bz2
Gamepad API: add support for connection events
Co-authored with Brandon Jones. This CL continues the work of updating the Gamepad API to latest spec. IPC's added for connected and disconnected events. The connection state is observed by GamepadProvider together with polling. The other option would be to add logic to each platform fetcher. Doing it in GamepadProvider avoids duplicated logic and I think it is a bit simpler and more consistent with the polling base nature of the gamepad implementation. Extra care has been taken to make it consistent with the policy of not exposing gamepad data to the page before a user gesture is observed. When a new page starts listening it will not get any events until we see a user gesture. When we see it we notify it about all the connected pads. Now we stop polling as soon as blink is no more interested in gamepad data. BUG=344556 Review URL: https://codereview.chromium.org/195873019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/gamepad/gamepad_service.h')
-rw-r--r--content/browser/gamepad/gamepad_service.h58
1 files changed, 54 insertions, 4 deletions
diff --git a/content/browser/gamepad/gamepad_service.h b/content/browser/gamepad/gamepad_service.h
index 94620b34..6008188 100644
--- a/content/browser/gamepad/gamepad_service.h
+++ b/content/browser/gamepad/gamepad_service.h
@@ -5,6 +5,8 @@
#ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
#define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
+#include <set>
+
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
@@ -13,8 +15,13 @@
#include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
+namespace blink {
+class WebGamepad;
+}
+
namespace content {
+class GamepadConsumer;
class GamepadDataFetcher;
class GamepadProvider;
class GamepadServiceTestConstructor;
@@ -30,14 +37,28 @@ class CONTENT_EXPORT GamepadService {
// Increments the number of users of the provider. The Provider is running
// when there's > 0 users, and is paused when the count drops to 0.
+ // consumer is registered to listen for gamepad connections. If this is the
+ // first time it is added to the set of consumers it will be treated
+ // specially: it will not be informed about connections before a new user
+ // gesture is observed at which point it will be notified for every connected
+ // gamepads.
//
// Must be called on the I/O thread.
- void AddConsumer();
+ void ConsumerBecameActive(GamepadConsumer* consumer);
- // Removes a consumer. Should be matched with an AddConsumer call.
+ // Decrements the number of users of the provider. consumer will not be
+ // informed about connections until it's added back via ConsumerBecameActive.
+ // Must be matched with a ConsumerBecameActive call.
//
// Must be called on the I/O thread.
- void RemoveConsumer();
+ void ConsumerBecameInactive(GamepadConsumer* consumer);
+
+ // Decrements the number of users of the provider and removes consumer from
+ // the set of consumers. Should be matched with a a ConsumerBecameActive
+ // call.
+ //
+ // Must be called on the I/O thread.
+ void RemoveConsumer(GamepadConsumer* consumer);
// Registers the given closure for calling when the user has interacted with
// the device. This callback will only be issued once. Should only be called
@@ -52,6 +73,12 @@ class CONTENT_EXPORT GamepadService {
// Stop/join with the background thread in GamepadProvider |provider_|.
void Terminate();
+ // Called on IO thread when a gamepad is connected.
+ void OnGamepadConnected(int index, const blink::WebGamepad& pad);
+
+ // Called on IO thread when a gamepad is disconnected.
+ void OnGamepadDisconnected(int index, const blink::WebGamepad& pad);
+
private:
friend struct DefaultSingletonTraits<GamepadService>;
friend class GamepadServiceTestConstructor;
@@ -64,11 +91,34 @@ class CONTENT_EXPORT GamepadService {
virtual ~GamepadService();
- int num_readers_;
+ void OnUserGesture();
+
+ struct ConsumerInfo {
+ ConsumerInfo(GamepadConsumer* consumer)
+ : consumer(consumer),
+ did_observe_user_gesture(false) {
+ }
+
+ bool operator<(const ConsumerInfo& other) const {
+ return consumer < other.consumer;
+ }
+
+ GamepadConsumer* consumer;
+ mutable bool is_active;
+ mutable bool did_observe_user_gesture;
+ };
+
scoped_ptr<GamepadProvider> provider_;
base::ThreadChecker thread_checker_;
+ typedef std::set<ConsumerInfo> ConsumerSet;
+ ConsumerSet consumers_;
+
+ int num_active_consumers_;
+
+ bool gesture_callback_pending_;
+
DISALLOW_COPY_AND_ASSIGN(GamepadService);
};