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

Unified Diff: content/renderer/gamepad_shared_memory_reader.cc

Issue 446603002: Refactor code listening to platform events in content/renderer/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webkitplatform_impl_start_stop
Patch Set: rebase 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 e74f02581864cff2d5c4dc4b4f44081826a3ccdb..5f8d31aa5705d988c76c1535da6acfaf26bad1d3 100644
--- a/content/renderer/gamepad_shared_memory_reader.cc
+++ b/content/renderer/gamepad_shared_memory_reader.cc
@@ -12,24 +12,28 @@
#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(
- RendererWebKitPlatformSupportImpl* webkit_platform_support)
- : gamepad_hardware_buffer_(NULL),
- gamepad_listener_(NULL),
- is_polling_(false),
+GamepadSharedMemoryReader::GamepadSharedMemoryReader(RenderThread* thread)
+ : RendererGamepadProvider(thread),
+ gamepad_hardware_buffer_(NULL),
ever_interacted_with_(false) {
- webkit_platform_support->set_gamepad_provider(this);
}
-void GamepadSharedMemoryReader::StartPollingIfNecessary() {
- if (is_polling_)
- return;
-
+void GamepadSharedMemoryReader::SendStartMessage() {
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).
@@ -46,24 +50,11 @@ void GamepadSharedMemoryReader::StartPollingIfNecessary() {
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 set the listener before start sampling.
- CHECK(gamepad_listener_);
-
- StartPollingIfNecessary();
- if (!is_polling_)
- return;
+ // Blink should have started observing at that point.
+ CHECK(is_observing());
// ==========
// DANGER
@@ -113,20 +104,7 @@ 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(
@@ -146,15 +124,15 @@ void GamepadSharedMemoryReader::OnGamepadConnected(
// The browser already checks if the user actually interacted with a device.
ever_interacted_with_ = true;
- if (gamepad_listener_)
- gamepad_listener_->didConnectGamepad(index, gamepad);
+ if (listener())
+ listener()->didConnectGamepad(index, gamepad);
}
void GamepadSharedMemoryReader::OnGamepadDisconnected(
int index,
const blink::WebGamepad& gamepad) {
- if (gamepad_listener_)
- gamepad_listener_->didDisconnectGamepad(index, gamepad);
+ if (listener())
+ 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