| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ | 5 #ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
| 6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ | 6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "content/public/common/service_names.mojom.h" | 14 #include "content/public/common/service_names.mojom.h" |
| 15 #include "content/public/renderer/platform_event_observer.h" | 15 #include "content/public/renderer/platform_event_observer.h" |
| 16 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
| 17 #include "mojo/public/cpp/system/platform_handle.h" | 17 #include "mojo/public/cpp/system/platform_handle.h" |
| 18 #include "services/device/public/interfaces/constants.mojom.h" |
| 18 #include "services/service_manager/public/cpp/connector.h" | 19 #include "services/service_manager/public/cpp/connector.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 template <typename Base, typename MojoInterface> | 23 template <typename Base, typename MojoInterface> |
| 23 class CONTENT_EXPORT DeviceSensorMojoClientMixin : public Base { | 24 class CONTENT_EXPORT DeviceSensorMojoClientMixin : public Base { |
| 24 public: | 25 public: |
| 25 template <typename... Args> | 26 template <typename... Args> |
| 26 explicit DeviceSensorMojoClientMixin(Args&&... args) | 27 explicit DeviceSensorMojoClientMixin(Args&&... args) |
| 27 : Base(std::forward<Args>(args)...) { | 28 : Base(std::forward<Args>(args)...) { |
| 28 mojo::InterfaceRequest<MojoInterface> request(&mojo_interface_); | 29 mojo::InterfaceRequest<MojoInterface> request(&mojo_interface_); |
| 29 | 30 |
| 30 // When running layout tests, those observers should not listen to the | 31 // When running layout tests, those observers should not listen to the |
| 31 // actual hardware changes. In order to make that happen, don't connect | 32 // actual hardware changes. In order to make that happen, don't connect |
| 32 // the other end of the mojo pipe to anything. | 33 // the other end of the mojo pipe to anything. |
| 33 // | 34 // |
| 34 // TODO(sammc): Remove this when JS layout test support for shared buffers | 35 // TODO(sammc): Remove this when JS layout test support for shared buffers |
| 35 // is ready and the layout tests are converted to use that for mocking. | 36 // is ready and the layout tests are converted to use that for mocking. |
| 36 if (RenderThreadImpl::current() && | 37 if (RenderThreadImpl::current() && |
| 37 !RenderThreadImpl::current()->layout_test_mode()) { | 38 !RenderThreadImpl::current()->layout_test_mode()) { |
| 38 RenderThread::Get()->GetConnector()->BindInterface( | 39 RenderThread::Get()->GetConnector()->BindInterface( |
| 39 mojom::kBrowserServiceName, std::move(request)); | 40 device::mojom::kServiceName, std::move(request)); |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 | 43 |
| 43 void SendStartMessage() override { | 44 void SendStartMessage() override { |
| 44 mojo_interface_->StartPolling( | 45 mojo_interface_->StartPolling( |
| 45 base::Bind(&DeviceSensorMojoClientMixin<Base, MojoInterface>::DidStart, | 46 base::Bind(&DeviceSensorMojoClientMixin<Base, MojoInterface>::DidStart, |
| 46 base::Unretained(this))); | 47 base::Unretained(this))); |
| 47 } | 48 } |
| 48 void SendStopMessage() override { mojo_interface_->StopPolling(); } | 49 void SendStopMessage() override { mojo_interface_->StopPolling(); } |
| 49 | 50 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 int pump_delay_microseconds_; | 143 int pump_delay_microseconds_; |
| 143 PumpState state_; | 144 PumpState state_; |
| 144 base::RepeatingTimer timer_; | 145 base::RepeatingTimer timer_; |
| 145 | 146 |
| 146 DISALLOW_COPY_AND_ASSIGN(DeviceSensorEventPump); | 147 DISALLOW_COPY_AND_ASSIGN(DeviceSensorEventPump); |
| 147 }; | 148 }; |
| 148 | 149 |
| 149 } // namespace content | 150 } // namespace content |
| 150 | 151 |
| 151 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ | 152 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
| OLD | NEW |