Commit 79b2f499 authored by Arnaud Mandy's avatar Arnaud Mandy Committed by Commit Bot

Decouple DeviceOrientationEventPump from PlatformEventDispatcher

This change implements the controller management logic in
DeviceOrientationEventPump and removes the dependency on
PlatformEventDispatcher.

Bug: 873761
Change-Id: I4546ad799160b5c941aac07d278ec74e81d98bb3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1607807
Commit-Queue: Arnaud Mandy <arnaud.mandy@intel.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663044}
parent 06584f2c
...@@ -115,7 +115,7 @@ void DeviceOrientationController::RegisterWithDispatcher() { ...@@ -115,7 +115,7 @@ void DeviceOrientationController::RegisterWithDispatcher() {
void DeviceOrientationController::UnregisterWithDispatcher() { void DeviceOrientationController::UnregisterWithDispatcher() {
if (orientation_event_pump_) if (orientation_event_pump_)
orientation_event_pump_->RemoveController(this); orientation_event_pump_->RemoveController();
} }
Event* DeviceOrientationController::LastEvent() const { Event* DeviceOrientationController::LastEvent() const {
...@@ -166,7 +166,7 @@ void DeviceOrientationController::RegisterWithOrientationEventPump( ...@@ -166,7 +166,7 @@ void DeviceOrientationController::RegisterWithOrientationEventPump(
MakeGarbageCollected<DeviceOrientationEventPump>(task_runner, absolute); MakeGarbageCollected<DeviceOrientationEventPump>(task_runner, absolute);
} }
// TODO(crbug.com/850619): Ensure a valid frame is passed. // TODO(crbug.com/850619): Ensure a valid frame is passed.
orientation_event_pump_->AddController(this, frame); orientation_event_pump_->SetController(this);
} }
// static // static
......
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#include "services/device/public/cpp/generic_sensor/sensor_reading.h" #include "services/device/public/cpp/generic_sensor/sensor_reading.h"
#include "services/device/public/mojom/sensor.mojom-blink.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/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/platform_event_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_sensor_entry.h" #include "third_party/blink/renderer/modules/device_orientation/device_sensor_entry.h"
#include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/heap/persistent.h"
...@@ -56,6 +58,22 @@ DeviceOrientationEventPump::DeviceOrientationEventPump( ...@@ -56,6 +58,22 @@ DeviceOrientationEventPump::DeviceOrientationEventPump(
DeviceOrientationEventPump::~DeviceOrientationEventPump() = default; DeviceOrientationEventPump::~DeviceOrientationEventPump() = default;
void DeviceOrientationEventPump::SetController(
PlatformEventController* controller) {
DCHECK(controller);
DCHECK(!controller_);
controller_ = controller;
StartListening(controller_->GetDocument()
? controller_->GetDocument()->GetFrame()
: nullptr);
}
void DeviceOrientationEventPump::RemoveController() {
controller_ = nullptr;
StopListening();
}
DeviceOrientationData* DeviceOrientationData*
DeviceOrientationEventPump::LatestDeviceOrientationData() { DeviceOrientationEventPump::LatestDeviceOrientationData() {
return data_.Get(); return data_.Get();
...@@ -65,7 +83,7 @@ void DeviceOrientationEventPump::Trace(blink::Visitor* visitor) { ...@@ -65,7 +83,7 @@ void DeviceOrientationEventPump::Trace(blink::Visitor* visitor) {
visitor->Trace(relative_orientation_sensor_); visitor->Trace(relative_orientation_sensor_);
visitor->Trace(absolute_orientation_sensor_); visitor->Trace(absolute_orientation_sensor_);
visitor->Trace(data_); visitor->Trace(data_);
PlatformEventDispatcher::Trace(visitor); visitor->Trace(controller_);
} }
void DeviceOrientationEventPump::StartListening(LocalFrame* frame) { void DeviceOrientationEventPump::StartListening(LocalFrame* frame) {
...@@ -130,12 +148,17 @@ void DeviceOrientationEventPump::SendStopMessage() { ...@@ -130,12 +148,17 @@ void DeviceOrientationEventPump::SendStopMessage() {
data_ = nullptr; data_ = nullptr;
} }
void DeviceOrientationEventPump::NotifyController() {
DCHECK(controller_);
controller_->DidUpdateData();
}
void DeviceOrientationEventPump::FireEvent(TimerBase*) { void DeviceOrientationEventPump::FireEvent(TimerBase*) {
DeviceOrientationData* data = GetDataFromSharedMemory(); DeviceOrientationData* data = GetDataFromSharedMemory();
if (ShouldFireEvent(data)) { if (ShouldFireEvent(data)) {
data_ = data; data_ = data;
NotifyControllers(); NotifyController();
} }
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_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 "third_party/blink/renderer/core/frame/platform_event_dispatcher.h"
#include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h" #include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
...@@ -15,11 +14,11 @@ namespace blink { ...@@ -15,11 +14,11 @@ namespace blink {
class DeviceOrientationData; class DeviceOrientationData;
class DeviceSensorEntry; class DeviceSensorEntry;
class PlatformEventController;
class MODULES_EXPORT DeviceOrientationEventPump class MODULES_EXPORT DeviceOrientationEventPump
: public GarbageCollectedFinalized<DeviceOrientationEventPump>, : public GarbageCollectedFinalized<DeviceOrientationEventPump>,
public DeviceSensorEventPump, public DeviceSensorEventPump {
public PlatformEventDispatcher {
USING_GARBAGE_COLLECTED_MIXIN(DeviceOrientationEventPump); USING_GARBAGE_COLLECTED_MIXIN(DeviceOrientationEventPump);
public: public:
...@@ -32,6 +31,9 @@ class MODULES_EXPORT DeviceOrientationEventPump ...@@ -32,6 +31,9 @@ class MODULES_EXPORT DeviceOrientationEventPump
bool absolute); bool absolute);
~DeviceOrientationEventPump() override; ~DeviceOrientationEventPump() override;
void SetController(PlatformEventController*);
void RemoveController();
// Note that the returned object is owned by this class. // Note that the returned object is owned by this class.
DeviceOrientationData* LatestDeviceOrientationData(); DeviceOrientationData* LatestDeviceOrientationData();
...@@ -53,9 +55,9 @@ class MODULES_EXPORT DeviceOrientationEventPump ...@@ -53,9 +55,9 @@ class MODULES_EXPORT DeviceOrientationEventPump
friend class DeviceOrientationEventPumpTest; friend class DeviceOrientationEventPumpTest;
friend class DeviceAbsoluteOrientationEventPumpTest; friend class DeviceAbsoluteOrientationEventPumpTest;
// Inherited from PlatformEventDispatcher. void StartListening(LocalFrame*);
void StartListening(LocalFrame*) override; void StopListening();
void StopListening() override; void NotifyController();
// DeviceSensorEventPump: // DeviceSensorEventPump:
bool SensorsReadyOrErrored() const override; bool SensorsReadyOrErrored() const override;
...@@ -68,6 +70,7 @@ class MODULES_EXPORT DeviceOrientationEventPump ...@@ -68,6 +70,7 @@ class MODULES_EXPORT DeviceOrientationEventPump
bool fall_back_to_absolute_orientation_sensor_; bool fall_back_to_absolute_orientation_sensor_;
bool should_suspend_absolute_orientation_sensor_ = false; bool should_suspend_absolute_orientation_sensor_ = false;
Member<DeviceOrientationData> data_; Member<DeviceOrientationData> data_;
Member<PlatformEventController> controller_;
DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPump); DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPump);
}; };
......
...@@ -59,8 +59,8 @@ class MockDeviceOrientationController final ...@@ -59,8 +59,8 @@ class MockDeviceOrientationController final
// before DeviceOrientationEventPump::Start is called. As a workaround, // before DeviceOrientationEventPump::Start is called. As a workaround,
// Start is called manually by each test case. // Start is called manually by each test case.
// TODO(crbug.com/850619): Ensure a non-null LocalFrame is passed, and use // TODO(crbug.com/850619): Ensure a non-null LocalFrame is passed, and use
// AddController/RemoveController to start and stop the event pump. // SetController/RemoveController to start and stop the event pump.
orientation_pump_->AddController(this, /*frame=*/nullptr); orientation_pump_->SetController(this);
} }
bool HasLastData() override { bool HasLastData() override {
...@@ -68,7 +68,7 @@ class MockDeviceOrientationController final ...@@ -68,7 +68,7 @@ class MockDeviceOrientationController final
} }
void UnregisterWithDispatcher() override { void UnregisterWithDispatcher() override {
orientation_pump_->RemoveController(this); orientation_pump_->RemoveController();
} }
const DeviceOrientationData* data() { const DeviceOrientationData* data() {
......
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