| 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..6ea5407597d27d5cfc23e23f06acb60497159451 100644
|
| --- a/content/renderer/device_sensors/device_sensor_event_pump.h
|
| +++ b/content/renderer/device_sensors/device_sensor_event_pump.h
|
| @@ -5,14 +5,57 @@
|
| #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.
|
| + //
|
| + // TODO(sammc): Remove this when JS layout test support for shared buffers
|
| + // is ready and the layout tests are converted to use that for mocking.
|
| + if (RenderThreadImpl::current() &&
|
| + !RenderThreadImpl::current()->layout_test_mode()) {
|
| + RenderThread::Get()->GetRemoteInterfaces()->GetInterface(
|
| + std::move(request));
|
| + }
|
| + }
|
| +
|
| + void SendStartMessage() override {
|
| + mojo_interface_->StartPolling(
|
| + base::Bind(&DeviceSensorMojoClientMixin<Base, MojoInterface>::DidStart,
|
| + base::Unretained(this)));
|
| + }
|
| + void SendStopMessage() override { mojo_interface_->StopPolling(); }
|
| +
|
| + protected:
|
| + 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_),
|
|
|