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

Unified Diff: content/browser/gamepad/gamepad_provider.h

Issue 10912062: Implement the gamepad API in the IPC proxy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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: content/browser/gamepad/gamepad_provider.h
diff --git a/content/browser/gamepad/gamepad_provider.h b/content/browser/gamepad/gamepad_provider.h
index 22c39c58495f740e4f06478f8dca6d1f16d554cb..60a1ebb05c4dbb7d265f2004e31e5e582cdd522a 100644
--- a/content/browser/gamepad/gamepad_provider.h
+++ b/content/browser/gamepad/gamepad_provider.h
@@ -5,6 +5,11 @@
#ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_
#define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_
+#include <utility>
+#include <vector>
+
+#include "base/callback_forward.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop_proxy.h"
@@ -14,6 +19,7 @@
#include "content/common/content_export.h"
namespace base {
+class MessageLoopProxy;
class Thread;
}
@@ -25,13 +31,16 @@ struct GamepadHardwareBuffer;
class CONTENT_EXPORT GamepadProvider :
public base::SystemMonitor::DevicesChangedObserver {
public:
- explicit GamepadProvider();
- virtual ~GamepadProvider();
+ GamepadProvider();
- // Set the platform-specific data fetcher. Mostly used for testing.
- void SetDataFetcher(GamepadDataFetcher* fetcher);
+ // Manually specifies the data fetcher. Used for testing.
+ explicit GamepadProvider(scoped_ptr<GamepadDataFetcher> fetcher);
scottmg 2012/09/05 16:42:05 We pass scoped_ptr by value? ... Ah, apparently th
brettw 2012/09/05 21:25:51 Yes, this is teh new hotness.
+
+ virtual ~GamepadProvider();
- base::SharedMemoryHandle GetRendererSharedMemoryHandle(
+ // Returns the shared memory handle of the gamepad data duplicated into the
+ // given process.
+ base::SharedMemoryHandle GetSharedMemoryHandleForProcess(
base::ProcessHandle renderer_process);
// Pause and resume the background polling thread. Can be called from any
@@ -39,14 +48,19 @@ class CONTENT_EXPORT GamepadProvider :
void Pause();
void Resume();
+ // Registers the given closure for calling when the user has interacted with
+ // the device. This callback will only be issued once.
+ void RegisterForUserGesture(const base::Closure& closure);
+
// base::SystemMonitor::DevicesChangedObserver implementation.
virtual void OnDevicesChanged(base::SystemMonitor::DeviceType type) OVERRIDE;
private:
+ void Initialize(scoped_ptr<GamepadDataFetcher> fetcher);
// Method for setting up the platform-specific data fetcher. Takes ownership
// of |fetcher|.
- void DoInitializePollingThread(GamepadDataFetcher* fetcher);
+ void DoInitializePollingThread(scoped_ptr<GamepadDataFetcher> fetcher);
// Method for sending pause hints to the low-level data fetcher. Runs on
// polling_thread_.
@@ -58,6 +72,9 @@ class CONTENT_EXPORT GamepadProvider :
GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer();
+ // Checks the gamepad state to see if the user has interacted with it.
+ void CheckForUserGesture();
+
enum { kDesiredSamplingIntervalMs = 16 };
// Keeps track of when the background thread is paused. Access to is_paused_
@@ -70,6 +87,17 @@ class CONTENT_EXPORT GamepadProvider :
// |is_paused_|.
bool have_scheduled_do_poll_;
+ // Lists all observers registered for user gestures, and the thread which
+ // to issue the callbacks on. Since we always issue the callback on the
+ // thread which the registration happened, and this class lives on the I/O
+ // thread, the message loop proxies will normally just be the I/O thread.
+ // However, this will be the main thread for unit testing.
+ base::Lock user_gesture_lock_;
+ typedef std::vector<std::pair<base::Closure,
+ scoped_refptr<base::MessageLoopProxy> > >
scottmg 2012/09/05 16:42:05 nit: Maybe a struct instead of pair.
brettw 2012/09/05 21:25:51 Done.
+ UserGestureObserverVector;
+ UserGestureObserverVector user_gesture_observers_;
+
// Updated based on notification from SystemMonitor when the system devices
// have been updated, and this notification is passed on to the data fetcher
// to enable it to avoid redundant (and possibly expensive) is-connected

Powered by Google App Engine
This is Rietveld 408576698