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

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

Issue 2885373002: [Sensors] Simplify calculation of the reporting period (Closed)
Patch Set: 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
Index: third_party/WebKit/Source/modules/sensor/Sensor.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/Sensor.cpp b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
index 130162ef5af0ef77819f71bd9df52c889947e7cb..0c87fb79916d8c4823ea98966ee38dcd07053b56 100644
--- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
@@ -33,7 +33,6 @@ Sensor::Sensor(ExecutionContext* execution_context,
sensor_options_(sensor_options),
type_(type),
state_(SensorState::kIdle),
- last_update_timestamp_(0.0),
pending_reading_update_(false) {
// Check secure context.
String error_message;
@@ -170,19 +169,19 @@ void Sensor::OnSensorInitialized() {
RequestAddConfiguration();
}
-void Sensor::OnSensorReadingChanged(double timestamp) {
+void Sensor::OnSensorReadingChanged() {
if (state_ != Sensor::SensorState::kActivated)
return;
// Return if reading update is already scheduled or the cached
// reading is up-to-date.
- if (pending_reading_update_ ||
- sensor_proxy_->reading().timestamp == reading_.timestamp)
+ if (pending_reading_update_)
return;
pending_reading_update_ = true;
- double elapsedTime = timestamp - last_update_timestamp_;
+ double elapsedTime = sensor_proxy_->reading().timestamp - reading_.timestamp;
+ DCHECK_GT(elapsedTime, 0.0);
DCHECK_GT(configuration_->frequency, 0.0);
double waitingTime = 1 / configuration_->frequency - elapsedTime;
@@ -220,11 +219,6 @@ void Sensor::OnAddConfigurationRequestCompleted(bool result) {
return;
}
- // The initial value for m_lastUpdateTimestamp is set to current time,
- // so that the first reading update will be notified considering the given
- // frequency hint.
- last_update_timestamp_ = WTF::MonotonicallyIncreasingTime();
-
UpdateState(Sensor::SensorState::kActivated);
if (GetExecutionContext()) {
@@ -304,7 +298,6 @@ void Sensor::HandleError(ExceptionCode code,
}
void Sensor::UpdateReading() {
- last_update_timestamp_ = WTF::MonotonicallyIncreasingTime();
reading_ = sensor_proxy_->reading();
pending_reading_update_ = false;
DispatchEvent(Event::Create(EventTypeNames::change));
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Sensor.h ('k') | third_party/WebKit/Source/modules/sensor/SensorProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698