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

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

Issue 2644873002: [Sensors] Fix reading updates after page refresh (Closed)
Patch Set: Comments from haraken@. Rebased. Created 3 years, 11 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
index 3d35f7da1f8c0a31755ddbe5f2056c1113818b68..a56b12342178253286749adb63ecd03427d728eb 100644
--- a/third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.cpp
+++ b/third_party/WebKit/Source/modules/sensor/SensorReadingUpdater.cpp
@@ -14,15 +14,26 @@ using device::mojom::blink::ReportingMode;
namespace blink {
SensorReadingUpdater::SensorReadingUpdater(SensorProxy* sensorProxy)
- : m_sensorProxy(sensorProxy), m_hasPendingAnimationFrameTask(false) {}
+ : m_sensorProxy(sensorProxy),
+ m_document(m_sensorProxy->document()),
+ m_hasPendingAnimationFrameTask(false) {}
void SensorReadingUpdater::enqueueAnimationFrameTask() {
+ if (!m_document || m_document->isDetached()) {
+ // If the document has detached the scheduled callbacks
+ // will never be called.
+ m_hasPendingAnimationFrameTask = false;
+ m_document = m_sensorProxy->document();
+ if (!m_document || m_document->isDetached())
+ return;
+ }
+
if (m_hasPendingAnimationFrameTask)
return;
auto callback = WTF::bind(&SensorReadingUpdater::onAnimationFrame,
wrapWeakPersistent(this));
- m_sensorProxy->document()->enqueueAnimationFrameTask(std::move(callback));
+ m_document->enqueueAnimationFrameTask(std::move(callback));
m_hasPendingAnimationFrameTask = true;
}
@@ -36,6 +47,7 @@ void SensorReadingUpdater::onAnimationFrame() {
}
DEFINE_TRACE(SensorReadingUpdater) {
+ visitor->trace(m_document);
visitor->trace(m_sensorProxy);
}
« 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