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

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

Issue 2699673002: [Sensors] Fix error type and message used (Closed)
Patch Set: Created 3 years, 10 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (!isInitialized()) 155 if (!isInitialized())
156 return; 156 return;
157 157
158 if (page()->visibilityState() != PageVisibilityStateVisible) { 158 if (page()->visibilityState() != PageVisibilityStateVisible) {
159 suspend(); 159 suspend();
160 } else { 160 } else {
161 resume(); 161 resume();
162 } 162 }
163 } 163 }
164 164
165 void SensorProxy::handleSensorError(ExceptionCode code, 165 void SensorProxy::handleSensorError() {
166 String sanitizedMessage,
167 String unsanitizedMessage) {
168 m_state = Uninitialized; 166 m_state = Uninitialized;
169 m_frequenciesUsed.clear(); 167 m_frequenciesUsed.clear();
170 m_reading = device::SensorReading(); 168 m_reading = device::SensorReading();
171 169
172 // The m_sensor.reset() will release all callbacks and its bound parameters, 170 // The m_sensor.reset() will release all callbacks and its bound parameters,
173 // therefore, handleSensorError accepts messages by value. 171 // therefore, handleSensorError accepts messages by value.
174 m_sensor.reset(); 172 m_sensor.reset();
175 m_sharedBuffer.reset(); 173 m_sharedBuffer.reset();
176 m_sharedBufferHandle.reset(); 174 m_sharedBufferHandle.reset();
177 m_defaultConfig.reset(); 175 m_defaultConfig.reset();
178 m_clientBinding.Close(); 176 m_clientBinding.Close();
179 177
180 for (Observer* observer : m_observers) 178 for (Observer* observer : m_observers) {
181 observer->onSensorError(code, sanitizedMessage, unsanitizedMessage); 179 observer->onSensorError(NotReadableError, "Could not connect to a sensor",
180 String());
181 }
182 } 182 }
183 183
184 void SensorProxy::onSensorCreated(SensorInitParamsPtr params, 184 void SensorProxy::onSensorCreated(SensorInitParamsPtr params,
185 SensorClientRequest clientRequest) { 185 SensorClientRequest clientRequest) {
186 DCHECK_EQ(Initializing, m_state); 186 DCHECK_EQ(Initializing, m_state);
187 if (!params) { 187 if (!params) {
188 handleSensorError(NotReadableError, 188 handleSensorError();
189 "Sensor is not present on the platform.");
190 return; 189 return;
191 } 190 }
192 const size_t kReadBufferSize = sizeof(ReadingBuffer); 191 const size_t kReadBufferSize = sizeof(ReadingBuffer);
193 192
194 DCHECK_EQ(0u, params->buffer_offset % kReadBufferSize); 193 DCHECK_EQ(0u, params->buffer_offset % kReadBufferSize);
195 194
196 m_mode = params->mode; 195 m_mode = params->mode;
197 m_defaultConfig = std::move(params->default_configuration); 196 m_defaultConfig = std::move(params->default_configuration);
198 if (!m_defaultConfig) { 197 if (!m_defaultConfig) {
199 handleSensorError(); 198 handleSensorError();
(...skipping 10 matching lines...) Expand all
210 209
211 if (!m_sharedBuffer) { 210 if (!m_sharedBuffer) {
212 handleSensorError(); 211 handleSensorError();
213 return; 212 return;
214 } 213 }
215 214
216 m_maximumFrequency = params->maximum_frequency; 215 m_maximumFrequency = params->maximum_frequency;
217 DCHECK(m_maximumFrequency <= SensorConfiguration::kMaxAllowedFrequency); 216 DCHECK(m_maximumFrequency <= SensorConfiguration::kMaxAllowedFrequency);
218 217
219 auto errorCallback = 218 auto errorCallback =
220 WTF::bind(&SensorProxy::handleSensorError, wrapWeakPersistent(this), 219 WTF::bind(&SensorProxy::handleSensorError, wrapWeakPersistent(this));
221 UnknownError, String("Internal error"), String());
222 m_sensor.set_connection_error_handler( 220 m_sensor.set_connection_error_handler(
223 convertToBaseCallback(std::move(errorCallback))); 221 convertToBaseCallback(std::move(errorCallback)));
224 222
225 m_readingUpdater = SensorReadingUpdater::create(this, m_mode); 223 m_readingUpdater = SensorReadingUpdater::create(this, m_mode);
226 224
227 m_state = Initialized; 225 m_state = Initialized;
228 226
229 for (Observer* observer : m_observers) 227 for (Observer* observer : m_observers)
230 observer->onSensorInitialized(); 228 observer->onSensorInitialized();
231 } 229 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 const device::OneWriterSeqLock& seqlock = buffer->seqlock.value(); 263 const device::OneWriterSeqLock& seqlock = buffer->seqlock.value();
266 auto version = seqlock.ReadBegin(); 264 auto version = seqlock.ReadBegin();
267 auto readingData = buffer->reading; 265 auto readingData = buffer->reading;
268 if (seqlock.ReadRetry(version)) 266 if (seqlock.ReadRetry(version))
269 return false; 267 return false;
270 result = readingData; 268 result = readingData;
271 return true; 269 return true;
272 } 270 }
273 271
274 } // namespace blink 272 } // 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