| Index: content/browser/gamepad/gamepad_service.h
|
| diff --git a/content/browser/gamepad/gamepad_service.h b/content/browser/gamepad/gamepad_service.h
|
| index 94620b34b60f901c8b1bfb4865d3092eeb313ee8..b66b0204ef4c922a7cb9d76477d9c8f3611983f0 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);
|
| };
|
|
|
|
|