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

Side by Side Diff: content/browser/device_orientation/data_fetcher_impl_android.cc

Issue 59403004: Android: remove device_data.h from browser/device_orientation/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed extra line Created 6 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/device_orientation/data_fetcher_impl_android.h" 5 #include "content/browser/device_orientation/data_fetcher_impl_android.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 device_motion_buffer_->data.rotationRateGamma = gamma; 128 device_motion_buffer_->data.rotationRateGamma = gamma;
129 device_motion_buffer_->data.hasRotationRateGamma = true; 129 device_motion_buffer_->data.hasRotationRateGamma = true;
130 device_motion_buffer_->seqlock.WriteEnd(); 130 device_motion_buffer_->seqlock.WriteEnd();
131 131
132 if (!is_motion_buffer_ready_) { 132 if (!is_motion_buffer_ready_) {
133 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1; 133 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1;
134 CheckMotionBufferReadyToRead(); 134 CheckMotionBufferReadyToRead();
135 } 135 }
136 } 136 }
137 137
138 bool DataFetcherImplAndroid::Start(DeviceData::Type event_type) { 138 bool DataFetcherImplAndroid::Start(EventType event_type) {
139 DCHECK(!device_orientation_.is_null()); 139 DCHECK(!device_orientation_.is_null());
140 return Java_DeviceMotionAndOrientation_start( 140 return Java_DeviceMotionAndOrientation_start(
141 AttachCurrentThread(), device_orientation_.obj(), 141 AttachCurrentThread(), device_orientation_.obj(),
142 reinterpret_cast<intptr_t>(this), static_cast<jint>(event_type), 142 reinterpret_cast<intptr_t>(this), static_cast<jint>(event_type),
143 kInertialSensorIntervalMillis); 143 kInertialSensorIntervalMillis);
144 } 144 }
145 145
146 void DataFetcherImplAndroid::Stop(DeviceData::Type event_type) { 146 void DataFetcherImplAndroid::Stop(EventType event_type) {
147 DCHECK(!device_orientation_.is_null()); 147 DCHECK(!device_orientation_.is_null());
148 Java_DeviceMotionAndOrientation_stop( 148 Java_DeviceMotionAndOrientation_stop(
149 AttachCurrentThread(), device_orientation_.obj(), 149 AttachCurrentThread(), device_orientation_.obj(),
150 static_cast<jint>(event_type)); 150 static_cast<jint>(event_type));
151 } 151 }
152 152
153 int DataFetcherImplAndroid::GetNumberActiveDeviceMotionSensors() { 153 int DataFetcherImplAndroid::GetNumberActiveDeviceMotionSensors() {
154 DCHECK(!device_orientation_.is_null()); 154 DCHECK(!device_orientation_.is_null());
155 return Java_DeviceMotionAndOrientation_getNumberActiveDeviceMotionSensors( 155 return Java_DeviceMotionAndOrientation_getNumberActiveDeviceMotionSensors(
156 AttachCurrentThread(), device_orientation_.obj()); 156 AttachCurrentThread(), device_orientation_.obj());
157 } 157 }
158 158
159 159
160 // ----- Shared memory API methods 160 // ----- Shared memory API methods
161 161
162 // --- Device Motion 162 // --- Device Motion
163 163
164 bool DataFetcherImplAndroid::StartFetchingDeviceMotionData( 164 bool DataFetcherImplAndroid::StartFetchingDeviceMotionData(
165 DeviceMotionHardwareBuffer* buffer) { 165 DeviceMotionHardwareBuffer* buffer) {
166 DCHECK(buffer); 166 DCHECK(buffer);
167 { 167 {
168 base::AutoLock autolock(motion_buffer_lock_); 168 base::AutoLock autolock(motion_buffer_lock_);
169 device_motion_buffer_ = buffer; 169 device_motion_buffer_ = buffer;
170 ClearInternalMotionBuffers(); 170 ClearInternalMotionBuffers();
171 } 171 }
172 bool success = Start(DeviceData::kTypeMotion); 172 bool success = Start(kTypeMotion);
173 173
174 // If no motion data can ever be provided, the number of active device motion 174 // If no motion data can ever be provided, the number of active device motion
175 // sensors will be zero. In that case flag the shared memory buffer 175 // sensors will be zero. In that case flag the shared memory buffer
176 // as ready to read, as it will not change anyway. 176 // as ready to read, as it will not change anyway.
177 number_active_device_motion_sensors_ = GetNumberActiveDeviceMotionSensors(); 177 number_active_device_motion_sensors_ = GetNumberActiveDeviceMotionSensors();
178 { 178 {
179 base::AutoLock autolock(motion_buffer_lock_); 179 base::AutoLock autolock(motion_buffer_lock_);
180 CheckMotionBufferReadyToRead(); 180 CheckMotionBufferReadyToRead();
181 } 181 }
182 return success; 182 return success;
183 } 183 }
184 184
185 void DataFetcherImplAndroid::StopFetchingDeviceMotionData() { 185 void DataFetcherImplAndroid::StopFetchingDeviceMotionData() {
186 Stop(DeviceData::kTypeMotion); 186 Stop(kTypeMotion);
187 { 187 {
188 base::AutoLock autolock(motion_buffer_lock_); 188 base::AutoLock autolock(motion_buffer_lock_);
189 if (device_motion_buffer_) { 189 if (device_motion_buffer_) {
190 ClearInternalMotionBuffers(); 190 ClearInternalMotionBuffers();
191 device_motion_buffer_ = NULL; 191 device_motion_buffer_ = NULL;
192 } 192 }
193 } 193 }
194 } 194 }
195 195
196 void DataFetcherImplAndroid::CheckMotionBufferReadyToRead() { 196 void DataFetcherImplAndroid::CheckMotionBufferReadyToRead() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 is_orientation_buffer_ready_ = ready; 238 is_orientation_buffer_ready_ = ready;
239 } 239 }
240 240
241 bool DataFetcherImplAndroid::StartFetchingDeviceOrientationData( 241 bool DataFetcherImplAndroid::StartFetchingDeviceOrientationData(
242 DeviceOrientationHardwareBuffer* buffer) { 242 DeviceOrientationHardwareBuffer* buffer) {
243 DCHECK(buffer); 243 DCHECK(buffer);
244 { 244 {
245 base::AutoLock autolock(orientation_buffer_lock_); 245 base::AutoLock autolock(orientation_buffer_lock_);
246 device_orientation_buffer_ = buffer; 246 device_orientation_buffer_ = buffer;
247 } 247 }
248 bool success = Start(DeviceData::kTypeOrientation); 248 bool success = Start(kTypeOrientation);
249 249
250 { 250 {
251 base::AutoLock autolock(orientation_buffer_lock_); 251 base::AutoLock autolock(orientation_buffer_lock_);
252 // If Start() was unsuccessful then set the buffer ready flag to true 252 // If Start() was unsuccessful then set the buffer ready flag to true
253 // to start firing all-null events. 253 // to start firing all-null events.
254 SetOrientationBufferReadyStatus(!success); 254 SetOrientationBufferReadyStatus(!success);
255 } 255 }
256 256
257 if (!success) 257 if (!success)
258 updateRotationVectorHistogram(false); 258 updateRotationVectorHistogram(false);
259 259
260 return success; 260 return success;
261 } 261 }
262 262
263 void DataFetcherImplAndroid::StopFetchingDeviceOrientationData() { 263 void DataFetcherImplAndroid::StopFetchingDeviceOrientationData() {
264 Stop(DeviceData::kTypeOrientation); 264 Stop(kTypeOrientation);
265 { 265 {
266 base::AutoLock autolock(orientation_buffer_lock_); 266 base::AutoLock autolock(orientation_buffer_lock_);
267 if (device_orientation_buffer_) { 267 if (device_orientation_buffer_) {
268 SetOrientationBufferReadyStatus(false); 268 SetOrientationBufferReadyStatus(false);
269 device_orientation_buffer_ = NULL; 269 device_orientation_buffer_ = NULL;
270 } 270 }
271 } 271 }
272 } 272 }
273 273
274 } // namespace content 274 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698