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

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

Issue 2684743003: [Sensors] start() and stop() methods do not throw (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
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/Sensor.h" 5 #include "modules/sensor/Sensor.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "core/dom/ExecutionContextTask.h" 9 #include "core/dom/ExecutionContextTask.h"
10 #include "core/dom/TaskRunnerHelper.h" 10 #include "core/dom/TaskRunnerHelper.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 m_sensorOptions.setFrequency(SensorConfiguration::kMaxAllowedFrequency); 55 m_sensorOptions.setFrequency(SensorConfiguration::kMaxAllowedFrequency);
56 ConsoleMessage* consoleMessage = ConsoleMessage::create( 56 ConsoleMessage* consoleMessage = ConsoleMessage::create(
57 JSMessageSource, InfoMessageLevel, "Frequency is limited to 60 Hz."); 57 JSMessageSource, InfoMessageLevel, "Frequency is limited to 60 Hz.");
58 executionContext->addConsoleMessage(consoleMessage); 58 executionContext->addConsoleMessage(consoleMessage);
59 } 59 }
60 } 60 }
61 } 61 }
62 62
63 Sensor::~Sensor() = default; 63 Sensor::~Sensor() = default;
64 64
65 void Sensor::start(ScriptState* scriptState, ExceptionState& exceptionState) { 65 void Sensor::start() {
66 if (m_state != Sensor::SensorState::Unconnected && 66 if (m_state != Sensor::SensorState::Unconnected &&
67 m_state != Sensor::SensorState::Idle && 67 m_state != Sensor::SensorState::Idle &&
68 m_state != Sensor::SensorState::Errored) 68 m_state != Sensor::SensorState::Errored)
69 return; 69 return;
70 70
71 initSensorProxyIfNeeded(); 71 initSensorProxyIfNeeded();
72
73 if (!m_sensorProxy) { 72 if (!m_sensorProxy) {
74 exceptionState.throwDOMException( 73 reportError(InvalidStateError,
75 InvalidStateError, "The Sensor is no longer associated to a frame."); 74 "The Sensor is no longer associated to a frame.");
76 return; 75 return;
77 } 76 }
77
78 m_lastUpdateTimestamp = WTF::monotonicallyIncreasingTime(); 78 m_lastUpdateTimestamp = WTF::monotonicallyIncreasingTime();
79 startListening(); 79 startListening();
80 } 80 }
81 81
82 void Sensor::stop(ScriptState*, ExceptionState& exceptionState) { 82 void Sensor::stop() {
83 if (m_state == Sensor::SensorState::Unconnected || 83 if (m_state == Sensor::SensorState::Unconnected ||
84 m_state == Sensor::SensorState::Idle || 84 m_state == Sensor::SensorState::Idle ||
85 m_state == Sensor::SensorState::Errored) 85 m_state == Sensor::SensorState::Errored)
86 return; 86 return;
87 87
88 stopListening(); 88 stopListening();
89 } 89 }
90 90
91 static String ToString(Sensor::SensorState state) { 91 static String ToString(Sensor::SensorState state) {
92 switch (state) { 92 switch (state) {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 322
323 bool Sensor::canReturnReadings() const { 323 bool Sensor::canReturnReadings() const {
324 if (m_state != Sensor::SensorState::Activated) 324 if (m_state != Sensor::SensorState::Activated)
325 return false; 325 return false;
326 DCHECK(m_sensorProxy); 326 DCHECK(m_sensorProxy);
327 return m_sensorProxy->reading().timestamp != 0.0; 327 return m_sensorProxy->reading().timestamp != 0.0;
328 } 328 }
329 329
330 } // namespace blink 330 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Sensor.h ('k') | third_party/WebKit/Source/modules/sensor/Sensor.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698