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

Side by Side Diff: device/generic_sensor/platform_sensor_android.cc

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Created 4 years, 2 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 "device/generic_sensor/platform_sensor_android.h" 5 #include "device/generic_sensor/platform_sensor_android.h"
6 6
7 #include "base/android/context_utils.h" 7 #include "base/android/context_utils.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "jni/PlatformSensor_jni.h" 10 #include "jni/PlatformSensor_jni.h"
11 11
12 using base::android::AttachCurrentThread; 12 using base::android::AttachCurrentThread;
13 using base::android::JavaRef; 13 using base::android::JavaRef;
14 14
15 namespace device { 15 namespace device {
16 16
17 // static 17 // static
18 bool PlatformSensorAndroid::RegisterJNI(JNIEnv* env) { 18 bool PlatformSensorAndroid::RegisterJNI(JNIEnv* env) {
19 return RegisterNativesImpl(env); 19 return RegisterNativesImpl(env);
20 } 20 }
21 21
22 PlatformSensorAndroid::PlatformSensorAndroid( 22 PlatformSensorAndroid::PlatformSensorAndroid(
23 mojom::SensorType type, 23 mojom::SensorType type,
24 mojo::ScopedSharedBufferMapping mapping, 24 mojo::ScopedSharedBufferMapping mapping,
25 uint64_t buffer_size,
26 PlatformSensorProvider* provider, 25 PlatformSensorProvider* provider,
27 const JavaRef<jobject>& java_sensor) 26 const JavaRef<jobject>& java_sensor)
28 : PlatformSensor(type, std::move(mapping), provider), 27 : PlatformSensor(type, std::move(mapping), provider),
29 task_runner_(base::ThreadTaskRunnerHandle::Get()) { 28 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
30 JNIEnv* env = AttachCurrentThread(); 29 JNIEnv* env = AttachCurrentThread();
31 j_object_.Reset(java_sensor); 30 j_object_.Reset(java_sensor);
32 31
33 jobject byte_buffer = 32 Java_PlatformSensor_initPlatformSensorAndroid(env, j_object_.obj(),
34 env->NewDirectByteBuffer(shared_buffer_mapping_.get(), buffer_size); 33 reinterpret_cast<jlong>(this));
35 Java_PlatformSensor_initPlatformSensorAndroid(
36 env, j_object_.obj(), reinterpret_cast<jlong>(this), byte_buffer);
37 } 34 }
38 35
39 PlatformSensorAndroid::~PlatformSensorAndroid() { 36 PlatformSensorAndroid::~PlatformSensorAndroid() {
40 StopSensor(); 37 StopSensor();
41 } 38 }
42 39
43 mojom::ReportingMode PlatformSensorAndroid::GetReportingMode() { 40 mojom::ReportingMode PlatformSensorAndroid::GetReportingMode() {
44 JNIEnv* env = AttachCurrentThread(); 41 JNIEnv* env = AttachCurrentThread();
45 return static_cast<mojom::ReportingMode>( 42 return static_cast<mojom::ReportingMode>(
46 Java_PlatformSensor_getReportingMode(env, j_object_.obj())); 43 Java_PlatformSensor_getReportingMode(env, j_object_.obj()));
(...skipping 18 matching lines...) Expand all
65 Java_PlatformSensor_stopSensor(env, j_object_.obj()); 62 Java_PlatformSensor_stopSensor(env, j_object_.obj());
66 } 63 }
67 64
68 bool PlatformSensorAndroid::CheckSensorConfiguration( 65 bool PlatformSensorAndroid::CheckSensorConfiguration(
69 const PlatformSensorConfiguration& configuration) { 66 const PlatformSensorConfiguration& configuration) {
70 JNIEnv* env = AttachCurrentThread(); 67 JNIEnv* env = AttachCurrentThread();
71 return Java_PlatformSensor_checkSensorConfiguration( 68 return Java_PlatformSensor_checkSensorConfiguration(
72 env, j_object_.obj(), configuration.frequency()); 69 env, j_object_.obj(), configuration.frequency());
73 } 70 }
74 71
75 void PlatformSensorAndroid::NotifyPlatformSensorReadingChanged(
76 JNIEnv*,
77 const JavaRef<jobject>& caller) {
78 task_runner_->PostTask(
79 FROM_HERE,
80 base::Bind(&PlatformSensorAndroid::NotifySensorReadingChanged, this));
81 }
82
83 void PlatformSensorAndroid::NotifyPlatformSensorError( 72 void PlatformSensorAndroid::NotifyPlatformSensorError(
84 JNIEnv*, 73 JNIEnv*,
85 const JavaRef<jobject>& caller) { 74 const JavaRef<jobject>& caller) {
86 task_runner_->PostTask( 75 task_runner_->PostTask(
87 FROM_HERE, base::Bind(&PlatformSensorAndroid::NotifySensorError, this)); 76 FROM_HERE, base::Bind(&PlatformSensorAndroid::NotifySensorError, this));
88 } 77 }
89 78
79 void PlatformSensorAndroid::UpdatePlatformSensorReading(
80 JNIEnv*,
81 const base::android::JavaRef<jobject>& caller,
82 jdouble timestamp,
83 jdouble value1,
84 jdouble value2,
85 jdouble value3) {
86 mojom::SensorReading reading;
87 reading.timestamp = timestamp;
88 reading.value1 = value1;
89 reading.value2 = value2;
90 reading.value3 = value3;
91
92 UpdateSensorReading(reading);
93
94 if (GetReportingMode() == mojom::ReportingMode::ON_CHANGE)
95 task_runner_->PostTask(
96 FROM_HERE,
97 base::Bind(&PlatformSensorAndroid::NotifySensorReadingChanged, this));
98 }
99
90 } // namespace device 100 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698