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() {
void DeviceOrientationController::UnregisterWithDispatcher() {
if (orientation_event_pump_)
orientation_event_pump_->RemoveController(this);
orientation_event_pump_->RemoveController();
}
Event* DeviceOrientationController::LastEvent() const {
......@@ -166,7 +166,7 @@ void DeviceOrientationController::RegisterWithOrientationEventPump(
MakeGarbageCollected<DeviceOrientationEventPump>(task_runner, absolute);
}
// TODO(crbug.com/850619): Ensure a valid frame is passed.
orientation_event_pump_->AddController(this, frame);
orientation_event_pump_->SetController(this);
}
// static
......
......@@ -9,7 +9,9 @@
#include "services/device/public/cpp/generic_sensor/sensor_reading.h"
#include "services/device/public/mojom/sensor.mojom-blink.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/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_sensor_entry.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
......@@ -56,6 +58,22 @@ DeviceOrientationEventPump::DeviceOrientationEventPump(
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*
DeviceOrientationEventPump::LatestDeviceOrientationData() {
return data_.Get();
......@@ -65,7 +83,7 @@ void DeviceOrientationEventPump::Trace(blink::Visitor* visitor) {
visitor->Trace(relative_orientation_sensor_);
visitor->Trace(absolute_orientation_sensor_);
visitor->Trace(data_);
PlatformEventDispatcher::Trace(visitor);
visitor->Trace(controller_);
}
void DeviceOrientationEventPump::StartListening(LocalFrame* frame) {
......@@ -130,12 +148,17 @@ void DeviceOrientationEventPump::SendStopMessage() {
data_ = nullptr;
}
void DeviceOrientationEventPump::NotifyController() {
DCHECK(controller_);
controller_->DidUpdateData();
}
void DeviceOrientationEventPump::FireEvent(TimerBase*) {
DeviceOrientationData* data = GetDataFromSharedMemory();
if (ShouldFireEvent(data)) {
data_ = data;
NotifyControllers();
NotifyController();
}
}
......
......@@ -6,7 +6,6 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_ORIENTATION_EVENT_PUMP_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/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
......@@ -15,11 +14,11 @@ namespace blink {
class DeviceOrientationData;
class DeviceSensorEntry;
class PlatformEventController;
class MODULES_EXPORT DeviceOrientationEventPump
: public GarbageCollectedFinalized<DeviceOrientationEventPump>,
public DeviceSensorEventPump,
public PlatformEventDispatcher {
public DeviceSensorEventPump {
USING_GARBAGE_COLLECTED_MIXIN(DeviceOrientationEventPump);
public:
......@@ -32,6 +31,9 @@ class MODULES_EXPORT DeviceOrientationEventPump
bool absolute);
~DeviceOrientationEventPump() override;
void SetController(PlatformEventController*);
void RemoveController();
// Note that the returned object is owned by this class.
DeviceOrientationData* LatestDeviceOrientationData();
......@@ -53,9 +55,9 @@ class MODULES_EXPORT DeviceOrientationEventPump
friend class DeviceOrientationEventPumpTest;
friend class DeviceAbsoluteOrientationEventPumpTest;
// Inherited from PlatformEventDispatcher.
void StartListening(LocalFrame*) override;
void StopListening() override;
void StartListening(LocalFrame*);
void StopListening();
void NotifyController();
// DeviceSensorEventPump:
bool SensorsReadyOrErrored() const override;
......@@ -68,6 +70,7 @@ class MODULES_EXPORT DeviceOrientationEventPump
bool fall_back_to_absolute_orientation_sensor_;
bool should_suspend_absolute_orientation_sensor_ = false;
Member<DeviceOrientationData> data_;
Member<PlatformEventController> controller_;
DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPump);
};
......
......@@ -59,8 +59,8 @@ class MockDeviceOrientationController final
// before DeviceOrientationEventPump::Start is called. As a workaround,
// Start is called manually by each test case.
// TODO(crbug.com/850619): Ensure a non-null LocalFrame is passed, and use
// AddController/RemoveController to start and stop the event pump.
orientation_pump_->AddController(this, /*frame=*/nullptr);
// SetController/RemoveController to start and stop the event pump.
orientation_pump_->SetController(this);
}
bool HasLastData() override {
......@@ -68,7 +68,7 @@ class MockDeviceOrientationController final
}
void UnregisterWithDispatcher() override {
orientation_pump_->RemoveController(this);
orientation_pump_->RemoveController();
}
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