OLD | NEW |
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/frame/LocalFrame.h" | 7 #include "core/frame/LocalFrame.h" |
8 #include "modules/sensor/SensorProviderProxy.h" | 8 #include "modules/sensor/SensorProviderProxy.h" |
9 #include "platform/mojo/MojoHelper.h" | 9 #include "platform/mojo/MojoHelper.h" |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 if (!m_provider->sensorProvider()) { | 48 if (!m_provider->sensorProvider()) { |
49 handleSensorError(); | 49 handleSensorError(); |
50 return; | 50 return; |
51 } | 51 } |
52 | 52 |
53 m_state = Initializing; | 53 m_state = Initializing; |
54 auto callback = convertToBaseCallback( | 54 auto callback = convertToBaseCallback( |
55 WTF::bind(&SensorProxy::onSensorCreated, wrapWeakPersistent(this))); | 55 WTF::bind(&SensorProxy::onSensorCreated, wrapWeakPersistent(this))); |
56 m_provider->sensorProvider()->GetSensor(m_type, mojo::GetProxy(&m_sensor), | 56 m_provider->sensorProvider()->GetSensor(m_type, mojo::GetProxy(&m_sensor), |
57 callback); | 57 callback); |
58 m_sensor.set_connection_error_handler(convertToBaseCallback( | |
59 WTF::bind(&SensorProxy::handleSensorError, wrapWeakPersistent(this)))); | |
60 } | 58 } |
61 | 59 |
62 void SensorProxy::addConfiguration( | 60 void SensorProxy::addConfiguration( |
63 SensorConfigurationPtr configuration, | 61 SensorConfigurationPtr configuration, |
64 std::unique_ptr<Function<void(bool)>> callback) { | 62 std::unique_ptr<Function<void(bool)>> callback) { |
65 DCHECK(isInitialized()); | 63 DCHECK(isInitialized()); |
66 m_sensor->AddConfiguration(std::move(configuration), | 64 m_sensor->AddConfiguration(std::move(configuration), |
67 convertToBaseCallback(std::move(callback))); | 65 convertToBaseCallback(std::move(callback))); |
68 } | 66 } |
69 | 67 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 105 |
108 void SensorProxy::RaiseError() { | 106 void SensorProxy::RaiseError() { |
109 handleSensorError(); | 107 handleSensorError(); |
110 } | 108 } |
111 | 109 |
112 void SensorProxy::SensorReadingChanged() { | 110 void SensorProxy::SensorReadingChanged() { |
113 for (Observer* observer : m_observers) | 111 for (Observer* observer : m_observers) |
114 observer->onSensorReadingChanged(); | 112 observer->onSensorReadingChanged(); |
115 } | 113 } |
116 | 114 |
117 void SensorProxy::handleSensorError() { | 115 void SensorProxy::handleSensorError(ExceptionCode code, |
| 116 const String& sanitizedMessage, |
| 117 const String& unsanitizedMessage) { |
118 m_state = Uninitialized; | 118 m_state = Uninitialized; |
119 m_sensor.reset(); | 119 m_sensor.reset(); |
120 m_sharedBuffer.reset(); | 120 m_sharedBuffer.reset(); |
121 m_sharedBufferHandle.reset(); | 121 m_sharedBufferHandle.reset(); |
122 m_defaultConfig.reset(); | 122 m_defaultConfig.reset(); |
123 m_clientBinding.Close(); | 123 m_clientBinding.Close(); |
124 | 124 |
125 for (Observer* observer : m_observers) | 125 for (Observer* observer : m_observers) |
126 observer->onSensorError(); | 126 observer->onSensorError(code, sanitizedMessage, unsanitizedMessage); |
127 } | 127 } |
128 | 128 |
129 void SensorProxy::onSensorCreated(SensorInitParamsPtr params, | 129 void SensorProxy::onSensorCreated(SensorInitParamsPtr params, |
130 SensorClientRequest clientRequest) { | 130 SensorClientRequest clientRequest) { |
131 DCHECK_EQ(Initializing, m_state); | 131 DCHECK_EQ(Initializing, m_state); |
132 if (!params) { | 132 if (!params) { |
133 handleSensorError(); | 133 handleSensorError(NotFoundError, "Sensor is not present on the platform."); |
134 return; | 134 return; |
135 } | 135 } |
136 | 136 |
137 DCHECK_EQ(0u, params->buffer_offset % SensorInitParams::kReadBufferSize); | 137 DCHECK_EQ(0u, params->buffer_offset % SensorInitParams::kReadBufferSize); |
138 | 138 |
139 m_mode = params->mode; | 139 m_mode = params->mode; |
140 m_defaultConfig = std::move(params->default_configuration); | 140 m_defaultConfig = std::move(params->default_configuration); |
141 if (!m_defaultConfig) { | 141 if (!m_defaultConfig) { |
142 handleSensorError(); | 142 handleSensorError(); |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 DCHECK(m_sensor.is_bound()); | 146 DCHECK(m_sensor.is_bound()); |
147 m_clientBinding.Bind(std::move(clientRequest)); | 147 m_clientBinding.Bind(std::move(clientRequest)); |
148 | 148 |
149 m_sharedBufferHandle = std::move(params->memory); | 149 m_sharedBufferHandle = std::move(params->memory); |
150 DCHECK(!m_sharedBuffer); | 150 DCHECK(!m_sharedBuffer); |
151 m_sharedBuffer = m_sharedBufferHandle->MapAtOffset( | 151 m_sharedBuffer = m_sharedBufferHandle->MapAtOffset( |
152 SensorInitParams::kReadBufferSize, params->buffer_offset); | 152 SensorInitParams::kReadBufferSize, params->buffer_offset); |
153 | 153 |
154 if (!m_sharedBuffer) { | 154 if (!m_sharedBuffer) { |
155 handleSensorError(); | 155 handleSensorError(); |
156 return; | 156 return; |
157 } | 157 } |
158 | 158 |
| 159 auto errorCallback = |
| 160 WTF::bind(&SensorProxy::handleSensorError, wrapWeakPersistent(this), |
| 161 UnknownError, String("Internal error"), String()); |
| 162 m_sensor.set_connection_error_handler( |
| 163 convertToBaseCallback(std::move(errorCallback))); |
| 164 |
159 m_state = Initialized; | 165 m_state = Initialized; |
160 for (Observer* observer : m_observers) | 166 for (Observer* observer : m_observers) |
161 observer->onSensorInitialized(); | 167 observer->onSensorInitialized(); |
162 } | 168 } |
163 | 169 |
164 } // namespace blink | 170 } // namespace blink |
OLD | NEW |