Commit 4540438b authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

device_sensors in content -> device_orientation in blink

This change moves Device*EventPump classes and appropriate unit tests to
third_party/blink/renderer/modules/device_orientation. Their instances
are now created in relevant Device*Dispatcher methods with a LocalFrame*
passed to be used for Mojo interface creation.
Some updates were required to satisfy blink dependencies limitations
and for consistency:
- base::RepeatingTimer was replaced by TaskRunnerTimer which has to be
initialized with a base::SingleThreadTaskRunner, so the constructors
were extended with a new parameter;
- base::Time -> WTF::Time;
- base::BindOnce -> WTF::Bind, base::Unretained -> WTF::Unretained;
- device::mojom:: -> device::mojom::blink::;
- in the unit tests, device::mojom::SensorProviderPtrInfo is wrapped
into device::mojom::blink::SensorProviderPtr since FakeSensorProvider
implements device::mojom::SensorProvider

Bug: 850997
Change-Id: I440b9379f50ab42fc50b9d92490c2615ef8c3cc9
Reviewed-on: https://chromium-review.googlesource.com/1099492
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569659}
parent 5c603095
...@@ -77,11 +77,6 @@ target(link_target_type, "renderer") { ...@@ -77,11 +77,6 @@ target(link_target_type, "renderer") {
"crash_helpers.h", "crash_helpers.h",
"cursor_utils.cc", "cursor_utils.cc",
"cursor_utils.h", "cursor_utils.h",
"device_sensors/device_motion_event_pump.cc",
"device_sensors/device_motion_event_pump.h",
"device_sensors/device_orientation_event_pump.cc",
"device_sensors/device_orientation_event_pump.h",
"device_sensors/device_sensor_event_pump.h",
"devtools/render_widget_screen_metrics_emulator.cc", "devtools/render_widget_screen_metrics_emulator.cc",
"devtools/render_widget_screen_metrics_emulator.h", "devtools/render_widget_screen_metrics_emulator.h",
"devtools/render_widget_screen_metrics_emulator_delegate.h", "devtools/render_widget_screen_metrics_emulator_delegate.h",
......
timvolodine@chromium.org
# COMPONENT: Blink>Sensor>DeviceOrientation
# TEAM: device-dev@chromium.org
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
#include "content/public/common/webplugininfo.h" #include "content/public/common/webplugininfo.h"
#include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/media_stream_utils.h" #include "content/public/renderer/media_stream_utils.h"
...@@ -85,7 +86,6 @@ ...@@ -85,7 +86,6 @@
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
#include "ppapi/buildflags/buildflags.h" #include "ppapi/buildflags/buildflags.h"
#include "services/device/public/cpp/generic_sensor/motion_data.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h" #include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
...@@ -96,8 +96,6 @@ ...@@ -96,8 +96,6 @@
#include "third_party/blink/public/common/origin_trials/trial_token_validator.h" #include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
#include "third_party/blink/public/platform/blame_context.h" #include "third_party/blink/public/platform/blame_context.h"
#include "third_party/blink/public/platform/file_path_conversion.h" #include "third_party/blink/public/platform/file_path_conversion.h"
#include "third_party/blink/public/platform/modules/device_orientation/web_device_motion_listener.h"
#include "third_party/blink/public/platform/modules/device_orientation/web_device_orientation_listener.h"
#include "third_party/blink/public/platform/modules/webmidi/web_midi_accessor.h" #include "third_party/blink/public/platform/modules/webmidi/web_midi_accessor.h"
#include "third_party/blink/public/platform/scheduler/child/webthread_base.h" #include "third_party/blink/public/platform/scheduler/child/webthread_base.h"
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h" #include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
...@@ -1093,68 +1091,10 @@ blink::InterfaceProvider* RendererBlinkPlatformImpl::GetInterfaceProvider() { ...@@ -1093,68 +1091,10 @@ blink::InterfaceProvider* RendererBlinkPlatformImpl::GetInterfaceProvider() {
return blink_interface_provider_.get(); return blink_interface_provider_.get();
} }
void RendererBlinkPlatformImpl::InitDeviceSensorEventPump(
blink::WebPlatformEventType type,
blink::WebPlatformEventListener* listener) {
switch (type) {
case blink::kWebPlatformEventTypeDeviceMotion:
if (!motion_event_pump_)
motion_event_pump_ = std::make_unique<DeviceMotionEventPump>();
motion_event_pump_->Start(listener);
break;
case blink::kWebPlatformEventTypeDeviceOrientation:
if (!orientation_event_pump_) {
orientation_event_pump_ =
std::make_unique<DeviceOrientationEventPump>(false /* absolute */);
}
orientation_event_pump_->Start(listener);
break;
case blink::kWebPlatformEventTypeDeviceOrientationAbsolute:
if (!absolute_orientation_event_pump_) {
absolute_orientation_event_pump_ =
std::make_unique<DeviceOrientationEventPump>(true /* absolute */);
}
absolute_orientation_event_pump_->Start(listener);
break;
default:
DVLOG(1) << "RendererBlinkPlatformImpl::InitDeviceSensorEventPump() "
"with unknown type.";
}
}
void RendererBlinkPlatformImpl::StopDeviceSensorEventPump(
blink::WebPlatformEventType type) {
switch (type) {
case blink::kWebPlatformEventTypeDeviceMotion: {
if (motion_event_pump_)
motion_event_pump_->Stop();
break;
}
case blink::kWebPlatformEventTypeDeviceOrientation: {
if (orientation_event_pump_)
orientation_event_pump_->Stop();
break;
}
case blink::kWebPlatformEventTypeDeviceOrientationAbsolute: {
if (absolute_orientation_event_pump_)
absolute_orientation_event_pump_->Stop();
break;
}
default:
DVLOG(1) << "RendererBlinkPlatformImpl::StopDeviceSensorEventPump() "
"with unknown type.";
}
}
void RendererBlinkPlatformImpl::StartListening( void RendererBlinkPlatformImpl::StartListening(
blink::WebPlatformEventType type, blink::WebPlatformEventType type,
blink::WebPlatformEventListener* listener) { blink::WebPlatformEventListener* listener) {
if (type == blink::kWebPlatformEventTypeDeviceMotion || if (type == blink::kWebPlatformEventTypeGamepad) {
type == blink::kWebPlatformEventTypeDeviceOrientation ||
type == blink::kWebPlatformEventTypeDeviceOrientationAbsolute) {
// this method creates DeviceSensorEventPump instances if necessary and
// calls Start() on them
InitDeviceSensorEventPump(type, listener);
} else if (type == blink::kWebPlatformEventTypeGamepad) {
if (!gamepad_shared_memory_reader_) { if (!gamepad_shared_memory_reader_) {
gamepad_shared_memory_reader_ = gamepad_shared_memory_reader_ =
std::make_unique<GamepadSharedMemoryReader>(); std::make_unique<GamepadSharedMemoryReader>();
...@@ -1169,11 +1109,7 @@ void RendererBlinkPlatformImpl::StartListening( ...@@ -1169,11 +1109,7 @@ void RendererBlinkPlatformImpl::StartListening(
void RendererBlinkPlatformImpl::StopListening( void RendererBlinkPlatformImpl::StopListening(
blink::WebPlatformEventType type) { blink::WebPlatformEventType type) {
if (type == blink::kWebPlatformEventTypeDeviceMotion || if (type == blink::kWebPlatformEventTypeGamepad) {
type == blink::kWebPlatformEventTypeDeviceOrientation ||
type == blink::kWebPlatformEventTypeDeviceOrientationAbsolute) {
StopDeviceSensorEventPump(type);
} else if (type == blink::kWebPlatformEventTypeGamepad) {
if (gamepad_shared_memory_reader_) if (gamepad_shared_memory_reader_)
gamepad_shared_memory_reader_->Stop(); gamepad_shared_memory_reader_->Stop();
} }
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#include "content/child/blink_platform_impl.h" #include "content/child/blink_platform_impl.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/possibly_associated_interface_ptr.h" #include "content/common/possibly_associated_interface_ptr.h"
#include "content/renderer/device_sensors/device_motion_event_pump.h"
#include "content/renderer/device_sensors/device_orientation_event_pump.h"
#include "content/renderer/top_level_blame_context.h" #include "content/renderer/top_level_blame_context.h"
#include "content/renderer/webpublicsuffixlist_impl.h" #include "content/renderer/webpublicsuffixlist_impl.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h" #include "services/network/public/mojom/url_loader_factory.mojom.h"
...@@ -312,12 +310,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { ...@@ -312,12 +310,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
base::IDMap<std::unique_ptr<PlatformEventObserverBase>> base::IDMap<std::unique_ptr<PlatformEventObserverBase>>
platform_event_observers_; platform_event_observers_;
// TODO(crbug.com/850997): Remove when Device*EventPump classes are
// moved to blink
std::unique_ptr<DeviceMotionEventPump> motion_event_pump_;
std::unique_ptr<DeviceOrientationEventPump> orientation_event_pump_;
std::unique_ptr<DeviceOrientationEventPump> absolute_orientation_event_pump_;
// TODO(crbug.com/612330): Remove when GamepadSharedMemoryReader class is // TODO(crbug.com/612330): Remove when GamepadSharedMemoryReader class is
// moved to blink // moved to blink
std::unique_ptr<GamepadSharedMemoryReader> gamepad_shared_memory_reader_; std::unique_ptr<GamepadSharedMemoryReader> gamepad_shared_memory_reader_;
......
...@@ -1614,8 +1614,6 @@ test("content_unittests") { ...@@ -1614,8 +1614,6 @@ test("content_unittests") {
"../renderer/bmp_image_decoder_unittest.cc", "../renderer/bmp_image_decoder_unittest.cc",
"../renderer/categorized_worker_pool_unittest.cc", "../renderer/categorized_worker_pool_unittest.cc",
"../renderer/child_frame_compositing_helper_unittest.cc", "../renderer/child_frame_compositing_helper_unittest.cc",
"../renderer/device_sensors/device_motion_event_pump_unittest.cc",
"../renderer/device_sensors/device_orientation_event_pump_unittest.cc",
"../renderer/dom_storage/dom_storage_cached_area_unittest.cc", "../renderer/dom_storage/dom_storage_cached_area_unittest.cc",
"../renderer/dom_storage/local_storage_cached_area_unittest.cc", "../renderer/dom_storage/local_storage_cached_area_unittest.cc",
"../renderer/dom_storage/local_storage_cached_areas_unittest.cc", "../renderer/dom_storage/local_storage_cached_areas_unittest.cc",
......
...@@ -250,6 +250,8 @@ jumbo_source_set("unit_tests") { ...@@ -250,6 +250,8 @@ jumbo_source_set("unit_tests") {
"credentialmanager/password_credential_test.cc", "credentialmanager/password_credential_test.cc",
"csspaint/paint_rendering_context_2d_test.cc", "csspaint/paint_rendering_context_2d_test.cc",
"csspaint/paint_worklet_test.cc", "csspaint/paint_worklet_test.cc",
"device_orientation/device_motion_event_pump_unittest.cc",
"device_orientation/device_orientation_event_pump_unittest.cc",
"document_metadata/copyless_paste_extractor_test.cc", "document_metadata/copyless_paste_extractor_test.cc",
"eventsource/event_source_parser_test.cc", "eventsource/event_source_parser_test.cc",
"filesystem/dom_file_system_base_test.cc", "filesystem/dom_file_system_base_test.cc",
...@@ -328,6 +330,7 @@ jumbo_source_set("unit_tests") { ...@@ -328,6 +330,7 @@ jumbo_source_set("unit_tests") {
deps = [ deps = [
":modules", ":modules",
":modules_testing", ":modules_testing",
"//services/device/public/cpp/test:test_support",
"//skia", "//skia",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
......
...@@ -16,6 +16,8 @@ blink_modules_sources("device_orientation") { ...@@ -16,6 +16,8 @@ blink_modules_sources("device_orientation") {
"device_motion_dispatcher.h", "device_motion_dispatcher.h",
"device_motion_event.cc", "device_motion_event.cc",
"device_motion_event.h", "device_motion_event.h",
"device_motion_event_pump.cc",
"device_motion_event_pump.h",
"device_orientation_absolute_controller.cc", "device_orientation_absolute_controller.cc",
"device_orientation_absolute_controller.h", "device_orientation_absolute_controller.h",
"device_orientation_controller.cc", "device_orientation_controller.cc",
...@@ -26,10 +28,13 @@ blink_modules_sources("device_orientation") { ...@@ -26,10 +28,13 @@ blink_modules_sources("device_orientation") {
"device_orientation_dispatcher.h", "device_orientation_dispatcher.h",
"device_orientation_event.cc", "device_orientation_event.cc",
"device_orientation_event.h", "device_orientation_event.h",
"device_orientation_event_pump.cc",
"device_orientation_event_pump.h",
"device_orientation_inspector_agent.cc", "device_orientation_inspector_agent.cc",
"device_orientation_inspector_agent.h", "device_orientation_inspector_agent.h",
"device_rotation_rate.cc", "device_rotation_rate.cc",
"device_rotation_rate.h", "device_rotation_rate.h",
"device_sensor_event_pump.h",
"dom_window_device_motion.h", "dom_window_device_motion.h",
"dom_window_device_orientation.h", "dom_window_device_orientation.h",
] ]
......
include_rules = [ include_rules = [
"+base/run_loop.h",
"+mojo/public/cpp/bindings/binding.h",
# NOTE: These files are POD structs used to interpret shared memory across # NOTE: These files are POD structs used to interpret shared memory across
# the Device Sensors implementation and the Blink client. # the Device Sensors implementation and the Blink client.
"+services/device/public/cpp/generic_sensor/motion_data.h", "+services/device/public/cpp/generic_sensor/motion_data.h",
"+services/device/public/cpp/generic_sensor/orientation_data.h", "+services/device/public/cpp/generic_sensor/orientation_data.h",
"+services/device/public/mojom/sensor.mojom-blink.h",
"+services/device/public/mojom/sensor_provider.mojom-blink.h",
"+services/device/public/cpp/test/fake_sensor_and_provider.h",
"+services/device/public/cpp/generic_sensor/sensor_reading.h",
"+services/device/public/cpp/generic_sensor/sensor_reading_shared_buffer_reader.h",
"+ui/gfx/geometry/angle_conversions.h",
"-third_party/blink/renderer/modules", "-third_party/blink/renderer/modules",
"+third_party/blink/renderer/modules/device_orientation", "+third_party/blink/renderer/modules/device_orientation",
"+third_party/blink/renderer/modules/event_modules.h", "+third_party/blink/renderer/modules/event_modules.h",
......
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#include "third_party/blink/renderer/modules/device_orientation/device_motion_dispatcher.h" #include "third_party/blink/renderer/modules/device_orientation/device_motion_dispatcher.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/modules/device_orientation/device_motion_controller.h" #include "third_party/blink/renderer/modules/device_orientation/device_motion_controller.h"
#include "third_party/blink/renderer/modules/device_orientation/device_motion_data.h" #include "third_party/blink/renderer/modules/device_orientation/device_motion_data.h"
#include "third_party/blink/renderer/modules/device_orientation/device_motion_event_pump.h"
namespace blink { namespace blink {
...@@ -52,11 +52,19 @@ void DeviceMotionDispatcher::Trace(blink::Visitor* visitor) { ...@@ -52,11 +52,19 @@ void DeviceMotionDispatcher::Trace(blink::Visitor* visitor) {
} }
void DeviceMotionDispatcher::StartListening(LocalFrame* frame) { void DeviceMotionDispatcher::StartListening(LocalFrame* frame) {
Platform::Current()->StartListening(kWebPlatformEventTypeDeviceMotion, this); // TODO(crbug.com/850619): ensure a valid frame is passed
if (!frame)
return;
if (!event_pump_) {
event_pump_ = std::make_unique<DeviceMotionEventPump>(
frame->GetTaskRunner(TaskType::kSensor));
}
event_pump_->Start(frame, this);
} }
void DeviceMotionDispatcher::StopListening() { void DeviceMotionDispatcher::StopListening() {
Platform::Current()->StopListening(kWebPlatformEventTypeDeviceMotion); if (event_pump_)
event_pump_->Stop();
last_device_motion_data_.Clear(); last_device_motion_data_.Clear();
} }
......
...@@ -43,6 +43,7 @@ class MotionData; ...@@ -43,6 +43,7 @@ class MotionData;
namespace blink { namespace blink {
class DeviceMotionData; class DeviceMotionData;
class DeviceMotionEventPump;
// This class listens to device motion data and notifies all registered // This class listens to device motion data and notifies all registered
// controllers. // controllers.
...@@ -72,6 +73,7 @@ class DeviceMotionDispatcher final ...@@ -72,6 +73,7 @@ class DeviceMotionDispatcher final
void StopListening() override; void StopListening() override;
Member<DeviceMotionData> last_device_motion_data_; Member<DeviceMotionData> last_device_motion_data_;
std::unique_ptr<DeviceMotionEventPump> event_pump_;
}; };
} // namespace blink } // namespace blink
......
...@@ -2,43 +2,41 @@ ...@@ -2,43 +2,41 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/device_sensors/device_motion_event_pump.h"
#include <cmath> #include <cmath>
#include "base/logging.h"
#include "content/public/renderer/render_frame.h"
#include "services/device/public/cpp/generic_sensor/motion_data.h" #include "services/device/public/cpp/generic_sensor/motion_data.h"
#include "services/device/public/mojom/sensor.mojom.h" #include "services/device/public/mojom/sensor.mojom-blink.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/device_orientation/device_motion_event_pump.h"
#include "ui/gfx/geometry/angle_conversions.h" #include "ui/gfx/geometry/angle_conversions.h"
namespace content { namespace blink {
template class DeviceSensorEventPump<blink::WebDeviceMotionListener>; template class DeviceSensorEventPump<blink::WebDeviceMotionListener>;
DeviceMotionEventPump::DeviceMotionEventPump() DeviceMotionEventPump::DeviceMotionEventPump(
: accelerometer_(this, device::mojom::SensorType::ACCELEROMETER), scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: DeviceSensorEventPump<blink::WebDeviceMotionListener>(task_runner),
accelerometer_(this, device::mojom::blink::SensorType::ACCELEROMETER),
linear_acceleration_sensor_( linear_acceleration_sensor_(
this, this,
device::mojom::SensorType::LINEAR_ACCELERATION), device::mojom::blink::SensorType::LINEAR_ACCELERATION),
gyroscope_(this, device::mojom::SensorType::GYROSCOPE) {} gyroscope_(this, device::mojom::blink::SensorType::GYROSCOPE) {}
DeviceMotionEventPump::~DeviceMotionEventPump() { DeviceMotionEventPump::~DeviceMotionEventPump() {
StopIfObserving(); StopIfObserving();
} }
void DeviceMotionEventPump::SendStartMessage() { void DeviceMotionEventPump::SendStartMessage(LocalFrame* frame) {
if (!sensor_provider_) { if (!sensor_provider_) {
RenderFrame* const render_frame = GetRenderFrame(); DCHECK(frame);
if (!render_frame)
return;
render_frame->GetRemoteInterfaces()->GetInterface( frame->GetInterfaceProvider().GetInterface(
mojo::MakeRequest(&sensor_provider_)); mojo::MakeRequest(&sensor_provider_));
sensor_provider_.set_connection_error_handler( sensor_provider_.set_connection_error_handler(
base::BindOnce(&DeviceSensorEventPump::HandleSensorProviderError, WTF::Bind(&DeviceSensorEventPump::HandleSensorProviderError,
base::Unretained(this))); WTF::Unretained(this)));
} }
accelerometer_.Start(sensor_provider_.get()); accelerometer_.Start(sensor_provider_.get());
...@@ -57,7 +55,7 @@ void DeviceMotionEventPump::SendStopMessage() { ...@@ -57,7 +55,7 @@ void DeviceMotionEventPump::SendStopMessage() {
gyroscope_.Stop(); gyroscope_.Stop();
} }
void DeviceMotionEventPump::FireEvent() { void DeviceMotionEventPump::FireEvent(TimerBase*) {
device::MotionData data; device::MotionData data;
// The device orientation spec states that interval should be in milliseconds. // The device orientation spec states that interval should be in milliseconds.
// https://w3c.github.io/deviceorientation/spec-source-orientation.html#devicemotion // https://w3c.github.io/deviceorientation/spec-source-orientation.html#devicemotion
...@@ -127,11 +125,11 @@ void DeviceMotionEventPump::GetDataFromSharedMemory(device::MotionData* data) { ...@@ -127,11 +125,11 @@ void DeviceMotionEventPump::GetDataFromSharedMemory(device::MotionData* data) {
data->all_available_sensors_are_active = accelerometer_active && data->all_available_sensors_are_active = accelerometer_active &&
linear_acceleration_sensor_active && linear_acceleration_sensor_active &&
gyroscope_active; gyroscope_active;
} // namespace content }
bool DeviceMotionEventPump::ShouldFireEvent( bool DeviceMotionEventPump::ShouldFireEvent(
const device::MotionData& data) const { const device::MotionData& data) const {
return data.all_available_sensors_are_active; return data.all_available_sensors_are_active;
} }
} // namespace content } // namespace blink
...@@ -2,32 +2,33 @@ ...@@ -2,32 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_EVENT_PUMP_H_
#define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_EVENT_PUMP_H_
#include "base/macros.h" #include "base/macros.h"
#include "content/renderer/device_sensors/device_sensor_event_pump.h"
#include "third_party/blink/public/platform/modules/device_orientation/web_device_motion_listener.h" #include "third_party/blink/public/platform/modules/device_orientation/web_device_motion_listener.h"
#include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h"
#include "third_party/blink/renderer/modules/modules_export.h"
namespace device { namespace device {
class MotionData; class MotionData;
} }
namespace content { namespace blink {
class CONTENT_EXPORT DeviceMotionEventPump class MODULES_EXPORT DeviceMotionEventPump
: public DeviceSensorEventPump<blink::WebDeviceMotionListener> { : public DeviceSensorEventPump<blink::WebDeviceMotionListener> {
public: public:
DeviceMotionEventPump(); explicit DeviceMotionEventPump(scoped_refptr<base::SingleThreadTaskRunner>);
~DeviceMotionEventPump() override; ~DeviceMotionEventPump() override;
// PlatformEventObserver: // DeviceSensorEventPump:
void SendStartMessage() override; void SendStartMessage(LocalFrame* frame) override;
void SendStopMessage() override; void SendStopMessage() override;
protected: protected:
// DeviceSensorEventPump: // DeviceSensorEventPump:
void FireEvent() override; void FireEvent(TimerBase*) override;
SensorEntry accelerometer_; SensorEntry accelerometer_;
SensorEntry linear_acceleration_sensor_; SensorEntry linear_acceleration_sensor_;
...@@ -46,6 +47,6 @@ class CONTENT_EXPORT DeviceMotionEventPump ...@@ -46,6 +47,6 @@ class CONTENT_EXPORT DeviceMotionEventPump
DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump); DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump);
}; };
} // namespace content } // namespace blink
#endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_ #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_EVENT_PUMP_H_
...@@ -2,30 +2,20 @@ ...@@ -2,30 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/device_sensors/device_motion_event_pump.h"
#include <string.h> #include <string.h>
#include <memory> #include <memory>
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "services/device/public/cpp/generic_sensor/motion_data.h" #include "services/device/public/cpp/generic_sensor/motion_data.h"
#include "services/device/public/cpp/test/fake_sensor_and_provider.h" #include "services/device/public/cpp/test/fake_sensor_and_provider.h"
#include "services/device/public/mojom/sensor.mojom.h"
#include "services/device/public/mojom/sensor_provider.mojom.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/modules/device_orientation/web_device_motion_listener.h" #include "third_party/blink/public/platform/modules/device_orientation/web_device_motion_listener.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h" #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/renderer/modules/device_orientation/device_motion_event_pump.h"
#include "ui/gfx/geometry/angle_conversions.h" #include "ui/gfx/geometry/angle_conversions.h"
namespace content { namespace blink {
using device::FakeSensorProvider; using device::FakeSensorProvider;
...@@ -43,9 +33,7 @@ class MockDeviceMotionListener : public blink::WebDeviceMotionListener { ...@@ -43,9 +33,7 @@ class MockDeviceMotionListener : public blink::WebDeviceMotionListener {
++number_of_events_; ++number_of_events_;
} }
bool did_change_device_motion() const { bool did_change_device_motion() const { return did_change_device_motion_; }
return did_change_device_motion_;
}
int number_of_events() const { return number_of_events_; } int number_of_events() const { return number_of_events_; }
...@@ -61,7 +49,9 @@ class MockDeviceMotionListener : public blink::WebDeviceMotionListener { ...@@ -61,7 +49,9 @@ class MockDeviceMotionListener : public blink::WebDeviceMotionListener {
class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump { class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump {
public: public:
DeviceMotionEventPumpForTesting() {} explicit DeviceMotionEventPumpForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: DeviceMotionEventPump(task_runner) {}
~DeviceMotionEventPumpForTesting() override {} ~DeviceMotionEventPumpForTesting() override {}
int pump_delay_microseconds() const { return kDefaultPumpDelayMicroseconds; } int pump_delay_microseconds() const { return kDefaultPumpDelayMicroseconds; }
...@@ -76,10 +66,15 @@ class DeviceMotionEventPumpTest : public testing::Test { ...@@ -76,10 +66,15 @@ class DeviceMotionEventPumpTest : public testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
motion_pump_.reset(new DeviceMotionEventPumpForTesting()); motion_pump_.reset(new DeviceMotionEventPumpForTesting(
device::mojom::SensorProviderPtr sensor_provider_ptr; base::ThreadTaskRunnerHandle::Get()));
sensor_provider_.Bind(mojo::MakeRequest(&sensor_provider_ptr)); device::mojom::SensorProviderPtrInfo sensor_provider_ptr_info;
motion_pump_->SetSensorProviderForTesting(std::move(sensor_provider_ptr)); sensor_provider_.Bind(mojo::MakeRequest(&sensor_provider_ptr_info));
motion_pump_->SetSensorProviderForTesting(
device::mojom::blink::SensorProviderPtr(
device::mojom::blink::SensorProviderPtrInfo(
sensor_provider_ptr_info.PassHandle(),
device::mojom::SensorProvider::Version_)));
listener_.reset(new MockDeviceMotionListener); listener_.reset(new MockDeviceMotionListener);
...@@ -89,7 +84,7 @@ class DeviceMotionEventPumpTest : public testing::Test { ...@@ -89,7 +84,7 @@ class DeviceMotionEventPumpTest : public testing::Test {
motion_pump()->GetPumpStateForTesting()); motion_pump()->GetPumpStateForTesting());
} }
void FireEvent() { motion_pump_->FireEvent(); } void FireEvent() { motion_pump_->FireEvent(nullptr); }
void ExpectAccelerometerStateToBe( void ExpectAccelerometerStateToBe(
DeviceMotionEventPump::SensorState expected_sensor_state) { DeviceMotionEventPump::SensorState expected_sensor_state) {
...@@ -121,7 +116,6 @@ class DeviceMotionEventPumpTest : public testing::Test { ...@@ -121,7 +116,6 @@ class DeviceMotionEventPumpTest : public testing::Test {
FakeSensorProvider* sensor_provider() { return &sensor_provider_; } FakeSensorProvider* sensor_provider() { return &sensor_provider_; }
private: private:
base::MessageLoop loop_;
std::unique_ptr<DeviceMotionEventPumpForTesting> motion_pump_; std::unique_ptr<DeviceMotionEventPumpForTesting> motion_pump_;
std::unique_ptr<MockDeviceMotionListener> listener_; std::unique_ptr<MockDeviceMotionListener> listener_;
FakeSensorProvider sensor_provider_; FakeSensorProvider sensor_provider_;
...@@ -130,7 +124,7 @@ class DeviceMotionEventPumpTest : public testing::Test { ...@@ -130,7 +124,7 @@ class DeviceMotionEventPumpTest : public testing::Test {
}; };
TEST_F(DeviceMotionEventPumpTest, MultipleStartAndStopWithWait) { TEST_F(DeviceMotionEventPumpTest, MultipleStartAndStopWithWait) {
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE); ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE);
...@@ -144,7 +138,7 @@ TEST_F(DeviceMotionEventPumpTest, MultipleStartAndStopWithWait) { ...@@ -144,7 +138,7 @@ TEST_F(DeviceMotionEventPumpTest, MultipleStartAndStopWithWait) {
EXPECT_EQ(DeviceMotionEventPump::PumpState::STOPPED, EXPECT_EQ(DeviceMotionEventPump::PumpState::STOPPED,
motion_pump()->GetPumpStateForTesting()); motion_pump()->GetPumpStateForTesting());
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE); ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE);
...@@ -168,7 +162,7 @@ TEST_F(DeviceMotionEventPumpTest, CallStop) { ...@@ -168,7 +162,7 @@ TEST_F(DeviceMotionEventPumpTest, CallStop) {
} }
TEST_F(DeviceMotionEventPumpTest, CallStartAndStop) { TEST_F(DeviceMotionEventPumpTest, CallStartAndStop) {
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
motion_pump()->Stop(); motion_pump()->Stop();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -176,8 +170,8 @@ TEST_F(DeviceMotionEventPumpTest, CallStartAndStop) { ...@@ -176,8 +170,8 @@ TEST_F(DeviceMotionEventPumpTest, CallStartAndStop) {
} }
TEST_F(DeviceMotionEventPumpTest, CallStartMultipleTimes) { TEST_F(DeviceMotionEventPumpTest, CallStartMultipleTimes) {
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
motion_pump()->Stop(); motion_pump()->Stop();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -185,7 +179,7 @@ TEST_F(DeviceMotionEventPumpTest, CallStartMultipleTimes) { ...@@ -185,7 +179,7 @@ TEST_F(DeviceMotionEventPumpTest, CallStartMultipleTimes) {
} }
TEST_F(DeviceMotionEventPumpTest, CallStopMultipleTimes) { TEST_F(DeviceMotionEventPumpTest, CallStopMultipleTimes) {
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
motion_pump()->Stop(); motion_pump()->Stop();
motion_pump()->Stop(); motion_pump()->Stop();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -195,9 +189,9 @@ TEST_F(DeviceMotionEventPumpTest, CallStopMultipleTimes) { ...@@ -195,9 +189,9 @@ TEST_F(DeviceMotionEventPumpTest, CallStopMultipleTimes) {
// Test multiple DeviceSensorEventPump::Start() calls only bind sensor once. // Test multiple DeviceSensorEventPump::Start() calls only bind sensor once.
TEST_F(DeviceMotionEventPumpTest, SensorOnlyBindOnce) { TEST_F(DeviceMotionEventPumpTest, SensorOnlyBindOnce) {
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
motion_pump()->Stop(); motion_pump()->Stop();
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE); ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE);
...@@ -208,7 +202,7 @@ TEST_F(DeviceMotionEventPumpTest, SensorOnlyBindOnce) { ...@@ -208,7 +202,7 @@ TEST_F(DeviceMotionEventPumpTest, SensorOnlyBindOnce) {
} }
TEST_F(DeviceMotionEventPumpTest, AllSensorsAreActive) { TEST_F(DeviceMotionEventPumpTest, AllSensorsAreActive) {
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE); ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE);
...@@ -251,7 +245,7 @@ TEST_F(DeviceMotionEventPumpTest, AllSensorsAreActive) { ...@@ -251,7 +245,7 @@ TEST_F(DeviceMotionEventPumpTest, AllSensorsAreActive) {
TEST_F(DeviceMotionEventPumpTest, TwoSensorsAreActive) { TEST_F(DeviceMotionEventPumpTest, TwoSensorsAreActive) {
sensor_provider()->set_linear_acceleration_sensor_is_available(false); sensor_provider()->set_linear_acceleration_sensor_is_available(false);
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAccelerometerStateToBe(DeviceMotionEventPump::SensorState::ACTIVE); ExpectAccelerometerStateToBe(DeviceMotionEventPump::SensorState::ACTIVE);
...@@ -294,7 +288,7 @@ TEST_F(DeviceMotionEventPumpTest, TwoSensorsAreActive) { ...@@ -294,7 +288,7 @@ TEST_F(DeviceMotionEventPumpTest, TwoSensorsAreActive) {
} }
TEST_F(DeviceMotionEventPumpTest, SomeSensorDataFieldsNotAvailable) { TEST_F(DeviceMotionEventPumpTest, SomeSensorDataFieldsNotAvailable) {
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE); ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE);
...@@ -337,7 +331,7 @@ TEST_F(DeviceMotionEventPumpTest, FireAllNullEvent) { ...@@ -337,7 +331,7 @@ TEST_F(DeviceMotionEventPumpTest, FireAllNullEvent) {
sensor_provider()->set_linear_acceleration_sensor_is_available(false); sensor_provider()->set_linear_acceleration_sensor_is_available(false);
sensor_provider()->set_gyroscope_is_available(false); sensor_provider()->set_gyroscope_is_available(false);
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe( ExpectAllThreeSensorsStateToBe(
...@@ -368,7 +362,7 @@ TEST_F(DeviceMotionEventPumpTest, FireAllNullEvent) { ...@@ -368,7 +362,7 @@ TEST_F(DeviceMotionEventPumpTest, FireAllNullEvent) {
TEST_F(DeviceMotionEventPumpTest, TEST_F(DeviceMotionEventPumpTest,
NotFireEventWhenSensorReadingTimeStampIsZero) { NotFireEventWhenSensorReadingTimeStampIsZero) {
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE); ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE);
...@@ -399,10 +393,10 @@ TEST_F(DeviceMotionEventPumpTest, ...@@ -399,10 +393,10 @@ TEST_F(DeviceMotionEventPumpTest,
// (crbug.com/421691) // (crbug.com/421691)
TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) { TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) {
// Confirm that the delay for pumping events is 60 Hz. // Confirm that the delay for pumping events is 60 Hz.
EXPECT_GE(60, base::Time::kMicrosecondsPerSecond / EXPECT_GE(60, WTF::Time::kMicrosecondsPerSecond /
motion_pump()->pump_delay_microseconds()); motion_pump()->pump_delay_microseconds());
motion_pump()->Start(listener()); motion_pump()->Start(nullptr, listener());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE); ExpectAllThreeSensorsStateToBe(DeviceMotionEventPump::SensorState::ACTIVE);
...@@ -414,7 +408,7 @@ TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) { ...@@ -414,7 +408,7 @@ TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) {
base::RunLoop loop; base::RunLoop loop;
blink::scheduler::GetSingleThreadTaskRunnerForTesting()->PostDelayedTask( blink::scheduler::GetSingleThreadTaskRunnerForTesting()->PostDelayedTask(
FROM_HERE, loop.QuitWhenIdleClosure(), FROM_HERE, loop.QuitWhenIdleClosure(),
base::TimeDelta::FromMilliseconds(100)); WTF::TimeDelta::FromMilliseconds(100));
loop.Run(); loop.Run();
motion_pump()->Stop(); motion_pump()->Stop();
...@@ -426,4 +420,4 @@ TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) { ...@@ -426,4 +420,4 @@ TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) {
EXPECT_GE(6, listener()->number_of_events()); EXPECT_GE(6, listener()->number_of_events());
} }
} // namespace content } // namespace blink
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_dispatcher.h" #include "third_party/blink/renderer/modules/device_orientation/device_orientation_dispatcher.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_controller.h" #include "third_party/blink/renderer/modules/device_orientation/device_orientation_controller.h"
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_data.h" #include "third_party/blink/renderer/modules/device_orientation/device_orientation_data.h"
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_event_pump.h"
namespace blink { namespace blink {
...@@ -61,11 +61,19 @@ void DeviceOrientationDispatcher::Trace(blink::Visitor* visitor) { ...@@ -61,11 +61,19 @@ void DeviceOrientationDispatcher::Trace(blink::Visitor* visitor) {
} }
void DeviceOrientationDispatcher::StartListening(LocalFrame* frame) { void DeviceOrientationDispatcher::StartListening(LocalFrame* frame) {
Platform::Current()->StartListening(GetWebPlatformEventType(), this); // TODO(crbug.com/850619): ensure a valid frame is passed
if (!frame)
return;
if (!event_pump_) {
event_pump_ = std::make_unique<DeviceOrientationEventPump>(
frame->GetTaskRunner(TaskType::kSensor), absolute_);
}
event_pump_->Start(frame, this);
} }
void DeviceOrientationDispatcher::StopListening() { void DeviceOrientationDispatcher::StopListening() {
Platform::Current()->StopListening(GetWebPlatformEventType()); if (event_pump_)
event_pump_->Stop();
last_device_orientation_data_.Clear(); last_device_orientation_data_.Clear();
} }
......
...@@ -44,6 +44,7 @@ class OrientationData; ...@@ -44,6 +44,7 @@ class OrientationData;
namespace blink { namespace blink {
class DeviceOrientationData; class DeviceOrientationData;
class DeviceOrientationEventPump;
// This class listens to device orientation data and notifies all registered // This class listens to device orientation data and notifies all registered
// controllers. // controllers.
...@@ -77,6 +78,7 @@ class DeviceOrientationDispatcher final ...@@ -77,6 +78,7 @@ class DeviceOrientationDispatcher final
const bool absolute_; const bool absolute_;
Member<DeviceOrientationData> last_device_orientation_data_; Member<DeviceOrientationData> last_device_orientation_data_;
std::unique_ptr<DeviceOrientationEventPump> event_pump_;
}; };
} // namespace blink } // namespace blink
......
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/device_sensors/device_orientation_event_pump.h"
#include <cmath> #include <cmath>
#include "base/logging.h" #include "services/device/public/mojom/sensor.mojom-blink.h"
#include "content/public/renderer/render_frame.h"
#include "services/device/public/mojom/sensor.mojom.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_event_pump.h"
namespace { namespace {
...@@ -22,7 +20,7 @@ bool IsAngleDifferentThreshold(bool has_angle1, ...@@ -22,7 +20,7 @@ bool IsAngleDifferentThreshold(bool has_angle1,
return (has_angle1 && return (has_angle1 &&
std::fabs(angle1 - angle2) >= std::fabs(angle1 - angle2) >=
content::DeviceOrientationEventPump::kOrientationThreshold); blink::DeviceOrientationEventPump::kOrientationThreshold);
} }
bool IsSignificantlyDifferent(const device::OrientationData& data1, bool IsSignificantlyDifferent(const device::OrientationData& data1,
...@@ -37,14 +35,17 @@ bool IsSignificantlyDifferent(const device::OrientationData& data1, ...@@ -37,14 +35,17 @@ bool IsSignificantlyDifferent(const device::OrientationData& data1,
} // namespace } // namespace
namespace content { namespace blink {
template class DeviceSensorEventPump<blink::WebDeviceOrientationListener>; template class DeviceSensorEventPump<blink::WebDeviceOrientationListener>;
const double DeviceOrientationEventPump::kOrientationThreshold = 0.1; const double DeviceOrientationEventPump::kOrientationThreshold = 0.1;
DeviceOrientationEventPump::DeviceOrientationEventPump(bool absolute) DeviceOrientationEventPump::DeviceOrientationEventPump(
: relative_orientation_sensor_( scoped_refptr<base::SingleThreadTaskRunner> task_runner,
bool absolute)
: DeviceSensorEventPump<blink::WebDeviceOrientationListener>(task_runner),
relative_orientation_sensor_(
this, this,
device::mojom::SensorType::RELATIVE_ORIENTATION_EULER_ANGLES), device::mojom::SensorType::RELATIVE_ORIENTATION_EULER_ANGLES),
absolute_orientation_sensor_( absolute_orientation_sensor_(
...@@ -57,17 +58,15 @@ DeviceOrientationEventPump::~DeviceOrientationEventPump() { ...@@ -57,17 +58,15 @@ DeviceOrientationEventPump::~DeviceOrientationEventPump() {
StopIfObserving(); StopIfObserving();
} }
void DeviceOrientationEventPump::SendStartMessage() { void DeviceOrientationEventPump::SendStartMessage(LocalFrame* frame) {
if (!sensor_provider_) { if (!sensor_provider_) {
RenderFrame* const render_frame = GetRenderFrame(); DCHECK(frame);
if (!render_frame)
return;
render_frame->GetRemoteInterfaces()->GetInterface( frame->GetInterfaceProvider().GetInterface(
mojo::MakeRequest(&sensor_provider_)); mojo::MakeRequest(&sensor_provider_));
sensor_provider_.set_connection_error_handler( sensor_provider_.set_connection_error_handler(
base::BindOnce(&DeviceSensorEventPump::HandleSensorProviderError, WTF::Bind(&DeviceSensorEventPump::HandleSensorProviderError,
base::Unretained(this))); WTF::Unretained(this)));
} }
if (absolute_) { if (absolute_) {
...@@ -109,7 +108,7 @@ void DeviceOrientationEventPump::SendStopMessage() { ...@@ -109,7 +108,7 @@ void DeviceOrientationEventPump::SendStopMessage() {
data_ = device::OrientationData(); data_ = device::OrientationData();
} }
void DeviceOrientationEventPump::FireEvent() { void DeviceOrientationEventPump::FireEvent(TimerBase*) {
device::OrientationData data; device::OrientationData data;
DCHECK(listener()); DCHECK(listener());
...@@ -211,4 +210,4 @@ bool DeviceOrientationEventPump::ShouldFireEvent( ...@@ -211,4 +210,4 @@ bool DeviceOrientationEventPump::ShouldFireEvent(
return IsSignificantlyDifferent(data_, data); return IsSignificantlyDifferent(data_, data);
} }
} // namespace content } // namespace blink
...@@ -2,33 +2,36 @@ ...@@ -2,33 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_ORIENTATION_EVENT_PUMP_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_ORIENTATION_EVENT_PUMP_H_
#define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_ORIENTATION_EVENT_PUMP_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_ORIENTATION_EVENT_PUMP_H_
#include "base/macros.h" #include "base/macros.h"
#include "content/renderer/device_sensors/device_sensor_event_pump.h"
#include "services/device/public/cpp/generic_sensor/orientation_data.h" #include "services/device/public/cpp/generic_sensor/orientation_data.h"
#include "third_party/blink/public/platform/modules/device_orientation/web_device_orientation_listener.h" #include "third_party/blink/public/platform/modules/device_orientation/web_device_orientation_listener.h"
#include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h"
#include "third_party/blink/renderer/modules/modules_export.h"
namespace content { namespace blink {
class CONTENT_EXPORT DeviceOrientationEventPump class MODULES_EXPORT DeviceOrientationEventPump
: public DeviceSensorEventPump<blink::WebDeviceOrientationListener> { : public DeviceSensorEventPump<blink::WebDeviceOrientationListener> {
public: public:
// Angle threshold beyond which two orientation events are considered // Angle threshold beyond which two orientation events are considered
// sufficiently different. // sufficiently different.
static const double kOrientationThreshold; static const double kOrientationThreshold;
explicit DeviceOrientationEventPump(bool absolute); explicit DeviceOrientationEventPump(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
bool absolute);
~DeviceOrientationEventPump() override; ~DeviceOrientationEventPump() override;
// PlatformEventObserver: // DeviceSensorEventPump:
void SendStartMessage() override; void SendStartMessage(LocalFrame* frame) override;
void SendStopMessage() override; void SendStopMessage() override;
protected: protected:
// DeviceSensorEventPump: // DeviceSensorEventPump:
void FireEvent() override; void FireEvent(TimerBase*) override;
void DidStartIfPossible() override; void DidStartIfPossible() override;
SensorEntry relative_orientation_sensor_; SensorEntry relative_orientation_sensor_;
...@@ -53,6 +56,6 @@ class CONTENT_EXPORT DeviceOrientationEventPump ...@@ -53,6 +56,6 @@ class CONTENT_EXPORT DeviceOrientationEventPump
DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPump); DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPump);
}; };
} // namespace content } // namespace blink
#endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_ORIENTATION_EVENT_PUMP_H_ #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_ORIENTATION_EVENT_PUMP_H_
...@@ -27,6 +27,7 @@ _CONFIG = [ ...@@ -27,6 +27,7 @@ _CONFIG = [
'gfx::ColorSpace', 'gfx::ColorSpace',
'gfx::CubicBezier', 'gfx::CubicBezier',
'gfx::ICCProfile', 'gfx::ICCProfile',
'gfx::RadToDeg',
'gfx::ScrollOffset', 'gfx::ScrollOffset',
# //base constructs that are allowed everywhere # //base constructs that are allowed everywhere
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment