Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.cpp

Issue 2870073002: [Sensors] Decouple sensor readings update from rAF (Closed)
Patch Set: [Sensors] Decouple sensor readings update from rAF Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.cpp b/third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.cpp
deleted file mode 100644
index 8904912cbf9326f4b0518def7d74fb4fb43eb545..0000000000000000000000000000000000000000
--- a/third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "modules/sensor/SensorReadingUpdater.h"
-
-#include "core/dom/Document.h"
-#include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
-#include "modules/sensor/SensorProxy.h"
-#include "platform/wtf/CurrentTime.h"
-
-using device::mojom::blink::ReportingMode;
-
-namespace blink {
-
-SensorReadingUpdater::SensorReadingUpdater(SensorProxy* sensor_proxy)
- : sensor_proxy_(sensor_proxy),
- document_(sensor_proxy_->GetDocument()),
- has_pending_animation_frame_task_(false) {}
-
-void SensorReadingUpdater::EnqueueAnimationFrameTask() {
- if (!document_ || document_->IsDetached()) {
- // If the document has detached the scheduled callbacks
- // will never be called.
- has_pending_animation_frame_task_ = false;
- document_ = sensor_proxy_->GetDocument();
- if (!document_ || document_->IsDetached())
- return;
- }
-
- if (has_pending_animation_frame_task_)
- return;
-
- auto callback = WTF::Bind(&SensorReadingUpdater::OnAnimationFrame,
- WrapWeakPersistent(this));
- document_->EnqueueAnimationFrameTask(std::move(callback));
- has_pending_animation_frame_task_ = true;
-}
-
-void SensorReadingUpdater::Start() {
- EnqueueAnimationFrameTask();
-}
-
-void SensorReadingUpdater::OnAnimationFrame() {
- has_pending_animation_frame_task_ = false;
- OnAnimationFrameInternal();
-}
-
-DEFINE_TRACE(SensorReadingUpdater) {
- visitor->Trace(document_);
- visitor->Trace(sensor_proxy_);
-}
-
-class SensorReadingUpdaterContinuous : public SensorReadingUpdater {
- public:
- explicit SensorReadingUpdaterContinuous(SensorProxy* sensor_proxy)
- : SensorReadingUpdater(sensor_proxy) {}
-
- DEFINE_INLINE_VIRTUAL_TRACE() { SensorReadingUpdater::Trace(visitor); }
-
- protected:
- void OnAnimationFrameInternal() override {
- if (!sensor_proxy_->IsActive())
- return;
-
- sensor_proxy_->UpdateSensorReading();
- sensor_proxy_->NotifySensorChanged(WTF::MonotonicallyIncreasingTime());
- EnqueueAnimationFrameTask();
- }
-};
-
-// New data is fetched from shared buffer only once after 'start()'
-// call. Further, notification is send until every client is updated
-// (i.e. until longest notification period elapses) rAF stops after that.
-class SensorReadingUpdaterOnChange : public SensorReadingUpdater {
- public:
- explicit SensorReadingUpdaterOnChange(SensorProxy* sensor_proxy)
- : SensorReadingUpdater(sensor_proxy),
- new_data_arrived_time_(0.0),
- new_data_arrived_(false) {}
-
- DEFINE_INLINE_VIRTUAL_TRACE() { SensorReadingUpdater::Trace(visitor); }
-
- void Start() override {
- new_data_arrived_ = true;
- SensorReadingUpdater::Start();
- }
-
- protected:
- void OnAnimationFrameInternal() override {
- if (!sensor_proxy_->IsActive())
- return;
-
- double timestamp = WTF::MonotonicallyIncreasingTime();
-
- if (new_data_arrived_) {
- new_data_arrived_ = false;
- sensor_proxy_->UpdateSensorReading();
- new_data_arrived_time_ = timestamp;
- }
- sensor_proxy_->NotifySensorChanged(timestamp);
-
- DCHECK_GT(sensor_proxy_->FrequenciesUsed().front(), 0.0);
- double longest_notification_period =
- 1 / sensor_proxy_->FrequenciesUsed().front();
-
- if (timestamp - new_data_arrived_time_ <= longest_notification_period)
- EnqueueAnimationFrameTask();
- }
-
- private:
- double new_data_arrived_time_;
- bool new_data_arrived_;
-};
-
-// static
-SensorReadingUpdater* SensorReadingUpdater::Create(SensorProxy* proxy,
- ReportingMode mode) {
- if (mode == ReportingMode::CONTINUOUS)
- return new SensorReadingUpdaterContinuous(proxy);
- return new SensorReadingUpdaterOnChange(proxy);
-}
-
-} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698