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

Side by Side Diff: third_party/WebKit/Source/modules/sensor/SensorProxy.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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorProxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/SensorProxy.h" 5 #include "modules/sensor/SensorProxy.h"
6 6
7 #include "core/dom/TaskRunnerHelper.h" 7 #include "core/dom/TaskRunnerHelper.h"
8 #include "core/frame/LocalFrame.h" 8 #include "core/frame/LocalFrame.h"
9 #include "modules/sensor/SensorProviderProxy.h" 9 #include "modules/sensor/SensorProviderProxy.h"
10 #include "platform/mojo/MojoHelper.h" 10 #include "platform/mojo/MojoHelper.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 const int kMaxReadAttemptsCount = 10; 116 const int kMaxReadAttemptsCount = 10;
117 device::SensorReading reading_data; 117 device::SensorReading reading_data;
118 while (!TryReadFromBuffer(reading_data)) { 118 while (!TryReadFromBuffer(reading_data)) {
119 if (++read_attempts == kMaxReadAttemptsCount) { 119 if (++read_attempts == kMaxReadAttemptsCount) {
120 HandleSensorError(); 120 HandleSensorError();
121 return; 121 return;
122 } 122 }
123 } 123 }
124 124
125 if (reading_.timestamp != reading_data.timestamp) { 125 if (reading_.timestamp != reading_data.timestamp) {
126 DCHECK_GT(reading_data.timestamp, reading_.timestamp)
127 << "Timestamps must increase monotonically";
126 reading_ = reading_data; 128 reading_ = reading_data;
127 double now = WTF::MonotonicallyIncreasingTime();
128 for (Observer* observer : observers_) 129 for (Observer* observer : observers_)
129 observer->OnSensorReadingChanged(now); 130 observer->OnSensorReadingChanged();
130 } 131 }
131 } 132 }
132 133
133 void SensorProxy::RaiseError() { 134 void SensorProxy::RaiseError() {
134 HandleSensorError(); 135 HandleSensorError();
135 } 136 }
136 137
137 void SensorProxy::SensorReadingChanged() { 138 void SensorProxy::SensorReadingChanged() {
138 DCHECK_EQ(ReportingMode::ON_CHANGE, mode_); 139 DCHECK_EQ(ReportingMode::ON_CHANGE, mode_);
139 UpdateSensorReading(); 140 UpdateSensorReading();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // TODO(crbug/721297) : We need to find out an algorithm for resulting 274 // TODO(crbug/721297) : We need to find out an algorithm for resulting
274 // polling frequency. 275 // polling frequency.
275 polling_timer_.StartRepeating(1 / frequencies_used_.back(), 276 polling_timer_.StartRepeating(1 / frequencies_used_.back(),
276 BLINK_FROM_HERE); 277 BLINK_FROM_HERE);
277 } else { 278 } else {
278 polling_timer_.Stop(); 279 polling_timer_.Stop();
279 } 280 }
280 } 281 }
281 282
282 } // namespace blink 283 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorProxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698