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

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

Issue 2330943002: [Sensors] Handle default sensor configuration (Closed)
Patch Set: Rebased Created 4 years, 3 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/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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 void SensorProxy::resume() 90 void SensorProxy::resume()
91 { 91 {
92 DCHECK(isInitialized()); 92 DCHECK(isInitialized());
93 if (!m_suspended) 93 if (!m_suspended)
94 return; 94 return;
95 95
96 m_sensor->Resume(); 96 m_sensor->Resume();
97 m_suspended = false; 97 m_suspended = false;
98 } 98 }
99 99
100 const device::mojom::blink::SensorConfiguration* SensorProxy::defaultConfig() co nst
101 {
102 DCHECK(isInitialized());
103 return m_defaultConfig.get();
104 }
105
100 void SensorProxy::updateInternalReading() 106 void SensorProxy::updateInternalReading()
101 { 107 {
102 DCHECK(isInitialized()); 108 DCHECK(isInitialized());
103 Reading* reading = static_cast<Reading*>(m_sharedBuffer.get()); 109 Reading* reading = static_cast<Reading*>(m_sharedBuffer.get());
104 m_reading = *reading; 110 m_reading = *reading;
105 } 111 }
106 112
107 void SensorProxy::RaiseError() 113 void SensorProxy::RaiseError()
108 { 114 {
109 handleSensorError(); 115 handleSensorError();
110 } 116 }
111 117
112 void SensorProxy::SensorReadingChanged() 118 void SensorProxy::SensorReadingChanged()
113 { 119 {
114 for (Observer* observer : m_observers) 120 for (Observer* observer : m_observers)
115 observer->onSensorReadingChanged(); 121 observer->onSensorReadingChanged();
116 } 122 }
117 123
118 void SensorProxy::handleSensorError() 124 void SensorProxy::handleSensorError()
119 { 125 {
120 m_state = Uninitialized; 126 m_state = Uninitialized;
121 m_sensor.reset(); 127 m_sensor.reset();
128 m_sharedBuffer.reset();
129 m_sharedBufferHandle.reset();
130 m_defaultConfig.reset();
131 m_clientBinding.Close();
132
122 for (Observer* observer : m_observers) 133 for (Observer* observer : m_observers)
123 observer->onSensorError(); 134 observer->onSensorError();
124 } 135 }
125 136
126 void SensorProxy::onSensorCreated(SensorReadBufferPtr buffer, SensorClientReques t clientRequest) 137 void SensorProxy::onSensorCreated(SensorInitParamsPtr params, SensorClientReques t clientRequest)
127 { 138 {
128 DCHECK_EQ(Initializing, m_state); 139 DCHECK_EQ(Initializing, m_state);
129 if (!buffer) { 140 if (!params) {
130 handleSensorError(); 141 handleSensorError();
131 return; 142 return;
132 } 143 }
133 144
134 DCHECK_EQ(0u, buffer->offset % SensorReadBuffer::kReadBufferSize); 145 DCHECK_EQ(0u, params->buffer_offset % SensorInitParams::kReadBufferSize);
135 146
136 m_mode = buffer->mode; 147 m_mode = params->mode;
148 m_defaultConfig = std::move(params->default_configuration);
149 if (!m_defaultConfig) {
150 handleSensorError();
151 return;
152 }
137 153
138 DCHECK(m_sensor.is_bound()); 154 DCHECK(m_sensor.is_bound());
139 m_clientBinding.Bind(std::move(clientRequest)); 155 m_clientBinding.Bind(std::move(clientRequest));
140 156
141 m_sharedBufferHandle = std::move(buffer->memory); 157 m_sharedBufferHandle = std::move(params->memory);
142 DCHECK(!m_sharedBuffer); 158 DCHECK(!m_sharedBuffer);
143 m_sharedBuffer = m_sharedBufferHandle->MapAtOffset(buffer->offset, SensorRea dBuffer::kReadBufferSize); 159 m_sharedBuffer = m_sharedBufferHandle->MapAtOffset(SensorInitParams::kReadBu fferSize, params->buffer_offset);
144 160
145 if (!m_sharedBuffer) { 161 if (!m_sharedBuffer) {
146 handleSensorError(); 162 handleSensorError();
147 return; 163 return;
148 } 164 }
149 165
150 m_state = Initialized; 166 m_state = Initialized;
151 for (Observer* observer : m_observers) 167 for (Observer* observer : m_observers)
152 observer->onSensorInitialized(); 168 observer->onSensorInitialized();
153 } 169 }
154 170
155 } // namespace blink 171 } // 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