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..f4572f00d568f3d1cdac5fadf02c54c6cebb458d 100644 |
--- a/content/renderer/device_sensors/device_sensor_event_pump.h |
+++ b/content/renderer/device_sensors/device_sensor_event_pump.h |
@@ -9,10 +9,43 @@ |
#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 "mojo/public/cpp/system/platform_handle.h" |
namespace content { |
+template <typename Base, typename MojoInterface> |
+class CONTENT_EXPORT DeviceMojoClientMixin : public Base { |
+ public: |
+ template <typename... Args> |
+ explicit DeviceMojoClientMixin(Args&&... args) |
+ : Base(std::forward<Args>(args)...) {} |
+ |
+ void SendStartMessage() override { |
+ GetMojoInterface().StartPolling( |
+ base::Bind(&DeviceMojoClientMixin<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) { |
+ 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 +104,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 +112,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_), |