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

Side by Side Diff: third_party/WebKit/Source/modules/sensor/SensorProxy.cpp

Issue 2746573002: [Sensors] Implement bindings for AbsoluteOrientationSensor (Closed)
Patch Set: Comments from Reilly Created 3 years, 8 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/Document.h" 7 #include "core/dom/Document.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 "modules/sensor/SensorReadingUpdater.h" 10 #include "modules/sensor/SensorReadingUpdater.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 int readAttempts = 0; 122 int readAttempts = 0;
123 const int kMaxReadAttemptsCount = 10; 123 const int kMaxReadAttemptsCount = 10;
124 device::SensorReading readingData; 124 device::SensorReading readingData;
125 while (!tryReadFromBuffer(readingData)) { 125 while (!tryReadFromBuffer(readingData)) {
126 if (++readAttempts == kMaxReadAttemptsCount) { 126 if (++readAttempts == kMaxReadAttemptsCount) {
127 handleSensorError(); 127 handleSensorError();
128 return; 128 return;
129 } 129 }
130 } 130 }
131 131
132 m_reading = readingData; 132 if (m_reading.timestamp != readingData.timestamp) {
133 m_reading = readingData;
134 for (Observer* observer : m_observers)
haraken 2017/03/27 09:59:38 Don't you need to copy the observers before starti
Mikhail 2017/03/27 10:04:01 This callback will not cause invokes of JS handler
135 observer->onSensorReadingChanged();
136 }
133 } 137 }
134 138
135 void SensorProxy::notifySensorChanged(double timestamp) { 139 void SensorProxy::notifySensorChanged(double timestamp) {
136 // This notification leads to sync 'onchange' event sending, so 140 // This notification leads to sync 'onchange' event sending, so
137 // we must cache m_observers as it can be modified within event handlers. 141 // we must cache m_observers as it can be modified within event handlers.
138 auto copy = m_observers; 142 auto copy = m_observers;
139 for (Observer* observer : copy) 143 for (Observer* observer : copy)
140 observer->onSensorReadingChanged(timestamp); 144 observer->notifySensorChanged(timestamp);
141 } 145 }
142 146
143 void SensorProxy::RaiseError() { 147 void SensorProxy::RaiseError() {
144 handleSensorError(); 148 handleSensorError();
145 } 149 }
146 150
147 void SensorProxy::SensorReadingChanged() { 151 void SensorProxy::SensorReadingChanged() {
148 DCHECK_EQ(ReportingMode::ON_CHANGE, m_mode); 152 DCHECK_EQ(ReportingMode::ON_CHANGE, m_mode);
149 if (isActive()) 153 if (isActive())
150 m_readingUpdater->start(); 154 m_readingUpdater->start();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 const device::OneWriterSeqLock& seqlock = buffer->seqlock.value(); 271 const device::OneWriterSeqLock& seqlock = buffer->seqlock.value();
268 auto version = seqlock.ReadBegin(); 272 auto version = seqlock.ReadBegin();
269 auto readingData = buffer->reading; 273 auto readingData = buffer->reading;
270 if (seqlock.ReadRetry(version)) 274 if (seqlock.ReadRetry(version))
271 return false; 275 return false;
272 result = readingData; 276 result = readingData;
273 return true; 277 return true;
274 } 278 }
275 279
276 } // namespace blink 280 } // 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