Chromium Code Reviews| Index: content/renderer/device_sensors/device_sensor_event_pump.h |
| diff --git a/content/renderer/device_sensors/device_sensor_event_pump.h b/content/renderer/device_sensors/device_sensor_event_pump.h |
| index 46252a7cc120a74b72efa1da43a769c71d4b1929..1b2944e523552b29063881acddca0b5af55cd8b0 100644 |
| --- a/content/renderer/device_sensors/device_sensor_event_pump.h |
| +++ b/content/renderer/device_sensors/device_sensor_event_pump.h |
| @@ -9,10 +9,52 @@ |
| #include "base/memory/shared_memory.h" |
| #include "base/time/time.h" |
| #include "base/timer/timer.h" |
| +#include "content/public/common/service_registry.h" |
| #include "content/public/renderer/platform_event_observer.h" |
| +#include "content/renderer/render_thread_impl.h" |
| +#include "mojo/public/cpp/system/platform_handle.h" |
| namespace content { |
| +template <typename Base, typename MojoInterface> |
| +class CONTENT_EXPORT DeviceSensorMojoClientMixin : public Base { |
| + public: |
| + template <typename... Args> |
| + explicit DeviceSensorMojoClientMixin(Args&&... args) |
| + : Base(std::forward<Args>(args)...) {} |
| + |
| + void SendStartMessage() override { |
| + GetMojoInterface().StartPolling( |
| + base::Bind(&DeviceSensorMojoClientMixin<Base, MojoInterface>::DidStart, |
| + base::Unretained(this))); |
| + } |
| + void SendStopMessage() override { GetMojoInterface().StopPolling(); } |
| + |
| + protected: |
| + MojoInterface& GetMojoInterface() { |
| + if (!mojo_interface_) { |
| + RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService( |
| + mojo::GetProxy(&mojo_interface_)); |
| + } |
| + return *mojo_interface_; |
| + } |
| + |
| + void DidStart(mojo::ScopedSharedBufferHandle buffer_handle) { |
| + // When running layout tests, those observers should not listen to the |
| + // actual hardware changes. In order to make that happen, discard start |
| + // responses. |
| + if (RenderThreadImpl::current() && |
| + RenderThreadImpl::current()->layout_test_mode()) { |
|
timvolodine
2016/06/15 15:54:47
Probably even better to put this in SendStartMessa
Sam McNally
2016/06/16 00:51:03
Done.
|
| + return; |
| + } |
| + |
| + Base::DidStart(std::move(buffer_handle)); |
| + } |
| + |
| + private: |
| + mojo::InterfacePtr<MojoInterface> mojo_interface_; |
| +}; |
| + |
| template <typename ListenerType> |
| class CONTENT_EXPORT DeviceSensorEventPump |
| : NON_EXPORTED_BASE(public PlatformEventObserver<ListenerType>) { |
| @@ -71,7 +113,7 @@ class CONTENT_EXPORT DeviceSensorEventPump |
| PENDING_START |
| }; |
| - void OnDidStart(base::SharedMemoryHandle handle) { |
| + void DidStart(mojo::ScopedSharedBufferHandle buffer_handle) { |
| DVLOG(2) << "did start sensor event pump"; |
| if (state_ != PENDING_START) |
| @@ -79,6 +121,11 @@ class CONTENT_EXPORT DeviceSensorEventPump |
| DCHECK(!timer_.IsRunning()); |
| + base::SharedMemoryHandle handle; |
| + MojoResult result = mojo::UnwrapSharedMemoryHandle( |
| + std::move(buffer_handle), &handle, nullptr, nullptr); |
| + DCHECK_EQ(MOJO_RESULT_OK, result); |
| + |
| if (InitializeReader(handle)) { |
| timer_.Start(FROM_HERE, |
| base::TimeDelta::FromMicroseconds(pump_delay_microseconds_), |