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..9ede1b10f4f448400d2d0c22fce013c774e42d6c 100644 |
--- a/content/renderer/device_sensors/device_sensor_event_pump.h |
+++ b/content/renderer/device_sensors/device_sensor_event_pump.h |
@@ -5,14 +5,58 @@ |
#ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
#define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
#include "base/macros.h" |
#include "base/memory/shared_memory.h" |
#include "base/time/time.h" |
#include "base/timer/timer.h" |
#include "content/public/renderer/platform_event_observer.h" |
+#include "content/renderer/render_thread_impl.h" |
+#include "mojo/public/cpp/system/platform_handle.h" |
+#include "services/shell/public/cpp/interface_provider.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)...) { |
+ 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. |
dcheng
2016/07/05 02:51:54
Nit: annotate with a TODO to remove once we have t
Sam McNally
2016/07/05 03:03:36
Done.
|
+ if (RenderThreadImpl::current() && |
+ !RenderThreadImpl::current()->layout_test_mode()) { |
+ RenderThread::Get()->GetRemoteInterfaces()->GetInterface( |
+ std::move(request)); |
+ } |
+ } |
+ |
+ void SendStartMessage() override { |
+ GetMojoInterface().StartPolling( |
+ base::Bind(&DeviceSensorMojoClientMixin<Base, MojoInterface>::DidStart, |
+ base::Unretained(this))); |
+ } |
+ void SendStopMessage() override { GetMojoInterface().StopPolling(); } |
+ |
+ protected: |
+ MojoInterface& GetMojoInterface() { |
dcheng
2016/07/05 02:51:54
I think this is now unnecessary: it might be a bit
Sam McNally
2016/07/05 03:03:36
Done.
|
+ 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 +115,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 +123,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_), |