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..8d10982004abd2494250b08278783e44e98a93ac 100644 |
| --- a/content/renderer/device_sensors/device_sensor_event_pump.h |
| +++ b/content/renderer/device_sensors/device_sensor_event_pump.h |
| @@ -9,10 +9,53 @@ |
| #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, |
|
dcheng
2016/07/04 03:39:49
Please include bind.h and bind_helpers.h.
Sam McNally
2016/07/04 08:31:39
Done.
|
| + base::Unretained(this))); |
| + } |
| + void SendStopMessage() override { GetMojoInterface().StopPolling(); } |
| + |
| + protected: |
| + MojoInterface& GetMojoInterface() { |
|
dcheng
2016/07/04 03:39:49
Why does this happen in a GetMojoInterface() helpe
Sam McNally
2016/07/04 08:31:39
Done.
|
| + if (!mojo_interface_) { |
| + mojo::InterfaceRequest<MojoInterface> request = |
| + mojo::GetProxy(&mojo_interface_); |
| + |
| + // When running layout tests, those observers should not listen to the |
| + // actual hardware changes. In order to make that happen, don't connect |
| + // the other end of the mojo pipe to anything. |
| + if (!RenderThreadImpl::current() || |
| + !RenderThreadImpl::current()->layout_test_mode()) { |
|
dcheng
2016/07/04 03:39:50
Is this check still needed with Mojo? My understan
Sam McNally
2016/07/04 08:31:38
Yes, the layout tests haven't been converted to th
|
| + RenderThread::Get()->GetRemoteInterfaces()->GetInterface( |
| + std::move(request)); |
| + } |
| + } |
| + return *mojo_interface_; |
| + } |
| + |
| + void DidStart(mojo::ScopedSharedBufferHandle buffer_handle) { |
| + 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 +114,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 +122,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_), |