 Chromium Code Reviews
 Chromium Code Reviews Issue 2644873002:
  [Sensors] Fix reading updates after page refresh  (Closed)
    
  
    Issue 2644873002:
  [Sensors] Fix reading updates after page refresh  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "modules/sensor/SensorReadingUpdater.h" | 5 #include "modules/sensor/SensorReadingUpdater.h" | 
| 6 | 6 | 
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" | 
| 8 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 8 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 
| 9 #include "modules/sensor/SensorProxy.h" | 9 #include "modules/sensor/SensorProxy.h" | 
| 10 #include "wtf/CurrentTime.h" | 10 #include "wtf/CurrentTime.h" | 
| 11 | 11 | 
| 12 using device::mojom::blink::ReportingMode; | 12 using device::mojom::blink::ReportingMode; | 
| 13 | 13 | 
| 14 namespace blink { | 14 namespace blink { | 
| 15 | 15 | 
| 16 SensorReadingUpdater::SensorReadingUpdater(SensorProxy* sensorProxy) | 16 SensorReadingUpdater::SensorReadingUpdater(SensorProxy* sensorProxy) | 
| 17 : m_sensorProxy(sensorProxy), m_hasPendingAnimationFrameTask(false) {} | 17 : m_sensorProxy(sensorProxy), m_hasPendingAnimationFrameTask(false) {} | 
| 18 | 18 | 
| 19 void SensorReadingUpdater::enqueueAnimationFrameTask() { | 19 void SensorReadingUpdater::enqueueAnimationFrameTask() { | 
| 20 if (m_hasPendingAnimationFrameTask) | 20 if (m_hasPendingAnimationFrameTask) | 
| 21 return; | 21 return; | 
| 22 | 22 | 
| 23 auto callback = WTF::bind(&SensorReadingUpdater::onAnimationFrame, | 23 auto callback = WTF::bind(&SensorReadingUpdater::onAnimationFrame, | 
| 
shalamov
2017/01/20 09:25:32
can be moved inside if (...)
 
Mikhail
2017/01/24 12:00:18
Done.
 | |
| 24 wrapWeakPersistent(this)); | 24 wrapWeakPersistent(this)); | 
| 25 m_sensorProxy->document()->enqueueAnimationFrameTask(std::move(callback)); | 25 auto document = m_sensorProxy->document(); | 
| 26 m_hasPendingAnimationFrameTask = true; | 26 if (document) { | 
| 27 document->enqueueAnimationFrameTask(std::move(callback)); | |
| 28 m_hasPendingAnimationFrameTask = true; | |
| 29 } | |
| 27 } | 30 } | 
| 28 | 31 | 
| 29 void SensorReadingUpdater::start() { | 32 void SensorReadingUpdater::start() { | 
| 30 enqueueAnimationFrameTask(); | 33 enqueueAnimationFrameTask(); | 
| 31 } | 34 } | 
| 32 | 35 | 
| 36 void SensorReadingUpdater::reset() { | |
| 37 m_hasPendingAnimationFrameTask = false; | |
| 
haraken
2017/01/19 13:57:28
Would you help me understand why you need to set i
 
shalamov
2017/01/20 09:25:33
haraken@ is right, looks like if task was enqueued
 
Mikhail
2017/01/24 12:00:18
I thought it as just a "reset" of the internal sta
 | |
| 38 } | |
| 39 | |
| 33 void SensorReadingUpdater::onAnimationFrame() { | 40 void SensorReadingUpdater::onAnimationFrame() { | 
| 34 m_hasPendingAnimationFrameTask = false; | 41 m_hasPendingAnimationFrameTask = false; | 
| 35 onAnimationFrameInternal(); | 42 onAnimationFrameInternal(); | 
| 36 } | 43 } | 
| 37 | 44 | 
| 38 DEFINE_TRACE(SensorReadingUpdater) { | 45 DEFINE_TRACE(SensorReadingUpdater) { | 
| 39 visitor->trace(m_sensorProxy); | 46 visitor->trace(m_sensorProxy); | 
| 40 } | 47 } | 
| 41 | 48 | 
| 42 class SensorReadingUpdaterContinuous : public SensorReadingUpdater { | 49 class SensorReadingUpdaterContinuous : public SensorReadingUpdater { | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 | 110 | 
| 104 // static | 111 // static | 
| 105 SensorReadingUpdater* SensorReadingUpdater::create(SensorProxy* proxy, | 112 SensorReadingUpdater* SensorReadingUpdater::create(SensorProxy* proxy, | 
| 106 ReportingMode mode) { | 113 ReportingMode mode) { | 
| 107 if (mode == ReportingMode::CONTINUOUS) | 114 if (mode == ReportingMode::CONTINUOUS) | 
| 108 return new SensorReadingUpdaterContinuous(proxy); | 115 return new SensorReadingUpdaterContinuous(proxy); | 
| 109 return new SensorReadingUpdaterOnChange(proxy); | 116 return new SensorReadingUpdaterOnChange(proxy); | 
| 110 } | 117 } | 
| 111 | 118 | 
| 112 } // namespace blink | 119 } // namespace blink | 
| OLD | NEW |