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

Unified Diff: content/renderer/gamepad_shared_memory_reader.cc

Issue 470683002: Revert "Refactor code listening to platform events in content/renderer/." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« no previous file with comments | « content/renderer/gamepad_shared_memory_reader.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/gamepad_shared_memory_reader.cc
diff --git a/content/renderer/gamepad_shared_memory_reader.cc b/content/renderer/gamepad_shared_memory_reader.cc
index 5f8d31aa5705d988c76c1535da6acfaf26bad1d3..e74f02581864cff2d5c4dc4b4f44081826a3ccdb 100644
--- a/content/renderer/gamepad_shared_memory_reader.cc
+++ b/content/renderer/gamepad_shared_memory_reader.cc
@@ -12,28 +12,24 @@
#include "content/renderer/renderer_webkitplatformsupport_impl.h"
#include "ipc/ipc_sync_message_filter.h"
#include "third_party/WebKit/public/platform/WebGamepadListener.h"
-#include "third_party/WebKit/public/platform/WebPlatformEventListener.h"
namespace content {
-GamepadSharedMemoryReader::GamepadSharedMemoryReader(RenderThread* thread)
- : RendererGamepadProvider(thread),
- gamepad_hardware_buffer_(NULL),
+GamepadSharedMemoryReader::GamepadSharedMemoryReader(
+ RendererWebKitPlatformSupportImpl* webkit_platform_support)
+ : gamepad_hardware_buffer_(NULL),
+ gamepad_listener_(NULL),
+ is_polling_(false),
ever_interacted_with_(false) {
+ webkit_platform_support->set_gamepad_provider(this);
}
-void GamepadSharedMemoryReader::SendStartMessage() {
+void GamepadSharedMemoryReader::StartPollingIfNecessary() {
+ if (is_polling_)
+ return;
+
CHECK(RenderThread::Get()->Send(new GamepadHostMsg_StartPolling(
&renderer_shared_memory_handle_)));
-}
-
-void GamepadSharedMemoryReader::SendStopMessage() {
- RenderThread::Get()->Send(new GamepadHostMsg_StopPolling());
-}
-
-void GamepadSharedMemoryReader::Start(
- blink::WebPlatformEventListener* listener) {
- PlatformEventObserver::Start(listener);
// If we don't get a valid handle from the browser, don't try to Map (we're
// probably out of memory or file handles).
@@ -50,11 +46,24 @@ void GamepadSharedMemoryReader::Start(
CHECK(memory);
gamepad_hardware_buffer_ =
static_cast<GamepadHardwareBuffer*>(memory);
+
+ is_polling_ = true;
+}
+
+void GamepadSharedMemoryReader::StopPollingIfNecessary() {
+ if (is_polling_) {
+ RenderThread::Get()->Send(new GamepadHostMsg_StopPolling());
+ is_polling_ = false;
+ }
}
void GamepadSharedMemoryReader::SampleGamepads(blink::WebGamepads& gamepads) {
- // Blink should have started observing at that point.
- CHECK(is_observing());
+ // Blink should set the listener before start sampling.
+ CHECK(gamepad_listener_);
+
+ StartPollingIfNecessary();
+ if (!is_polling_)
+ return;
// ==========
// DANGER
@@ -104,7 +113,20 @@ void GamepadSharedMemoryReader::SampleGamepads(blink::WebGamepads& gamepads) {
}
}
+void GamepadSharedMemoryReader::SetGamepadListener(
+ blink::WebGamepadListener* listener) {
+ gamepad_listener_ = listener;
+ if (gamepad_listener_) {
+ // Polling has to be started rigth now and not just on the first sampling
+ // because want to get connection events from now.
+ StartPollingIfNecessary();
+ } else {
+ StopPollingIfNecessary();
+ }
+}
+
GamepadSharedMemoryReader::~GamepadSharedMemoryReader() {
+ StopPollingIfNecessary();
}
bool GamepadSharedMemoryReader::OnControlMessageReceived(
@@ -124,15 +146,15 @@ void GamepadSharedMemoryReader::OnGamepadConnected(
// The browser already checks if the user actually interacted with a device.
ever_interacted_with_ = true;
- if (listener())
- listener()->didConnectGamepad(index, gamepad);
+ if (gamepad_listener_)
+ gamepad_listener_->didConnectGamepad(index, gamepad);
}
void GamepadSharedMemoryReader::OnGamepadDisconnected(
int index,
const blink::WebGamepad& gamepad) {
- if (listener())
- listener()->didDisconnectGamepad(index, gamepad);
+ if (gamepad_listener_)
+ gamepad_listener_->didDisconnectGamepad(index, gamepad);
}
} // namespace content
« no previous file with comments | « content/renderer/gamepad_shared_memory_reader.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698