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

Unified Diff: content/renderer/device_orientation/device_motion_event_pump.cc

Issue 20707002: Implement Device Orientation using shared memory in content/renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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/renderer/device_orientation/device_motion_event_pump.cc
diff --git a/content/renderer/device_orientation/device_motion_event_pump.cc b/content/renderer/device_orientation/device_motion_event_pump.cc
index 0cfd774339f39d42ab6a376a0068037070c70634..50862f453fac4c085f105098bb826d6061baefef 100644
--- a/content/renderer/device_orientation/device_motion_event_pump.cc
+++ b/content/renderer/device_orientation/device_motion_event_pump.cc
@@ -4,25 +4,18 @@
#include "device_motion_event_pump.h"
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/shared_memory.h"
-#include "base/message_loop/message_loop.h"
#include "content/common/device_motion_messages.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/WebKit/public/platform/WebDeviceMotionListener.h"
namespace content {
-const double DeviceMotionEventPump::kPumpDelayMillis = 40;
-
-double DeviceMotionEventPump::GetDelayMillis() {
- return kPumpDelayMillis;
+DeviceMotionEventPump::DeviceMotionEventPump()
+ : DeviceSensorEventPump(), listener_(0) {
}
-DeviceMotionEventPump::DeviceMotionEventPump()
- : listener_(0), state_(STOPPED) {
+DeviceMotionEventPump::DeviceMotionEventPump(int pump_delay_millis)
+ : DeviceSensorEventPump(pump_delay_millis), listener_(0) {
}
DeviceMotionEventPump::~DeviceMotionEventPump() {
@@ -31,45 +24,17 @@ DeviceMotionEventPump::~DeviceMotionEventPump() {
bool DeviceMotionEventPump::SetListener(
WebKit::WebDeviceMotionListener* listener) {
listener_ = listener;
- if (listener_)
- return StartFetchingDeviceMotion();
- return StopFetchingDeviceMotion();
-}
-
-void DeviceMotionEventPump::SetDeviceMotionReader(
- scoped_ptr<DeviceMotionSharedMemoryReader> reader) {
- reader_.reset(reader.release());
+ return listener_ ? RequestStart() : Stop();
}
-bool DeviceMotionEventPump::StartFetchingDeviceMotion() {
- DVLOG(2) << "start fetching device motion";
-
- if (state_ != STOPPED)
- return false;
-
- DCHECK(!timer_.IsRunning());
-
- if (RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling())) {
- state_ = PENDING_START;
- return true;
- }
- return false;
-}
-
-bool DeviceMotionEventPump::StopFetchingDeviceMotion() {
- DVLOG(2) << "stop fetching device motion";
-
- if (state_ == STOPPED)
- return true;
-
- DCHECK((state_ == PENDING_START && !timer_.IsRunning()) ||
- (state_ == RUNNING && timer_.IsRunning()));
-
- if (timer_.IsRunning())
- timer_.Stop();
- RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
- state_ = STOPPED;
- return true;
+bool DeviceMotionEventPump::OnControlMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message)
+ IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling, OnDidStart)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
}
void DeviceMotionEventPump::FireEvent() {
@@ -79,39 +44,19 @@ void DeviceMotionEventPump::FireEvent() {
listener_->didChangeDeviceMotion(data);
}
-void DeviceMotionEventPump::Attach(RenderThread* thread) {
- if (!thread)
- return;
- thread->AddObserver(this);
-}
-
-void DeviceMotionEventPump::OnDidStartDeviceMotion(
- base::SharedMemoryHandle renderer_handle) {
- DVLOG(2) << "did start fetching device motion";
-
- if (state_ != PENDING_START)
- return;
-
- DCHECK(!timer_.IsRunning());
+bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) {
if (!reader_)
reader_.reset(new DeviceMotionSharedMemoryReader());
+ return reader_->Initialize(handle);
+}
- if (reader_->Initialize(renderer_handle)) {
- timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kPumpDelayMillis),
- this, &DeviceMotionEventPump::FireEvent);
- state_ = RUNNING;
- }
+bool DeviceMotionEventPump::SendStartMessage() {
+ return RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling());
}
-bool DeviceMotionEventPump::OnControlMessageReceived(
- const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message)
- IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling,
- OnDidStartDeviceMotion)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
+
+bool DeviceMotionEventPump::SendStopMessage() {
+ return RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698