| 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/renderer/platform_event_observer.h" | 15 #include "content/public/renderer/platform_event_observer.h" |
| 15 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
| 16 #include "mojo/public/cpp/system/platform_handle.h" | 17 #include "mojo/public/cpp/system/platform_handle.h" |
| 17 #include "services/service_manager/public/cpp/interface_provider.h" | 18 #include "services/service_manager/public/cpp/connector.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 template <typename Base, typename MojoInterface> | 22 template <typename Base, typename MojoInterface> |
| 22 class CONTENT_EXPORT DeviceSensorMojoClientMixin : public Base { | 23 class CONTENT_EXPORT DeviceSensorMojoClientMixin : public Base { |
| 23 public: | 24 public: |
| 24 template <typename... Args> | 25 template <typename... Args> |
| 25 explicit DeviceSensorMojoClientMixin(Args&&... args) | 26 explicit DeviceSensorMojoClientMixin(Args&&... args) |
| 26 : Base(std::forward<Args>(args)...) { | 27 : Base(std::forward<Args>(args)...) { |
| 27 mojo::InterfaceRequest<MojoInterface> request(&mojo_interface_); | 28 mojo::InterfaceRequest<MojoInterface> request(&mojo_interface_); |
| 28 | 29 |
| 29 // When running layout tests, those observers should not listen to the | 30 // When running layout tests, those observers should not listen to the |
| 30 // actual hardware changes. In order to make that happen, don't connect | 31 // actual hardware changes. In order to make that happen, don't connect |
| 31 // the other end of the mojo pipe to anything. | 32 // the other end of the mojo pipe to anything. |
| 32 // | 33 // |
| 33 // TODO(sammc): Remove this when JS layout test support for shared buffers | 34 // TODO(sammc): Remove this when JS layout test support for shared buffers |
| 34 // is ready and the layout tests are converted to use that for mocking. | 35 // is ready and the layout tests are converted to use that for mocking. |
| 35 if (RenderThreadImpl::current() && | 36 if (RenderThreadImpl::current() && |
| 36 !RenderThreadImpl::current()->layout_test_mode()) { | 37 !RenderThreadImpl::current()->layout_test_mode()) { |
| 37 RenderThread::Get()->GetRemoteInterfaces()->GetInterface( | 38 RenderThread::Get()->GetConnector()->BindInterface( |
| 38 std::move(request)); | 39 mojom::kBrowserServiceName, std::move(request)); |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 | 42 |
| 42 void SendStartMessage() override { | 43 void SendStartMessage() override { |
| 43 mojo_interface_->StartPolling( | 44 mojo_interface_->StartPolling( |
| 44 base::Bind(&DeviceSensorMojoClientMixin<Base, MojoInterface>::DidStart, | 45 base::Bind(&DeviceSensorMojoClientMixin<Base, MojoInterface>::DidStart, |
| 45 base::Unretained(this))); | 46 base::Unretained(this))); |
| 46 } | 47 } |
| 47 void SendStopMessage() override { mojo_interface_->StopPolling(); } | 48 void SendStopMessage() override { mojo_interface_->StopPolling(); } |
| 48 | 49 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 int pump_delay_microseconds_; | 142 int pump_delay_microseconds_; |
| 142 PumpState state_; | 143 PumpState state_; |
| 143 base::RepeatingTimer timer_; | 144 base::RepeatingTimer timer_; |
| 144 | 145 |
| 145 DISALLOW_COPY_AND_ASSIGN(DeviceSensorEventPump); | 146 DISALLOW_COPY_AND_ASSIGN(DeviceSensorEventPump); |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 } // namespace content | 149 } // namespace content |
| 149 | 150 |
| 150 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ | 151 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
| OLD | NEW |