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

Unified Diff: device/generic_sensor/platform_sensor_provider_android.cc

Issue 2284613002: [sensors] Android platform adaptation for Generic Sensor API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to master. 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 side-by-side diff with in-line comments
Download patch
Index: device/generic_sensor/platform_sensor_provider_android.cc
diff --git a/device/generic_sensor/platform_sensor_provider_android.cc b/device/generic_sensor/platform_sensor_provider_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4009512cef3112eb524268ce46102ce61fde3d25
--- /dev/null
+++ b/device/generic_sensor/platform_sensor_provider_android.cc
@@ -0,0 +1,74 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/generic_sensor/platform_sensor_provider.h"
+
+#include "base/android/context_utils.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/memory/singleton.h"
+#include "device/generic_sensor/platform_sensor_android.h"
+#include "jni/PlatformSensorProvider_jni.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ScopedJavaLocalRef;
+
+namespace device {
+
+class PlatformSensorProviderAndroid : public PlatformSensorProvider {
+ public:
+ PlatformSensorProviderAndroid();
+ ~PlatformSensorProviderAndroid() override;
+
+ static PlatformSensorProviderAndroid* GetInstance();
+
+ protected:
+ scoped_refptr<PlatformSensor> CreateSensorInternal(
+ mojom::SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ uint64_t buffer_size) override;
+
+ private:
+ // Java object org.chromium.device.sensors.PlatformSensorProvider
+ base::android::ScopedJavaGlobalRef<jobject> j_object_;
+
+ DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderAndroid);
+};
+
+// static
+PlatformSensorProvider* PlatformSensorProvider::GetInstance() {
+ return PlatformSensorProviderAndroid::GetInstance();
+}
+
+// static
+PlatformSensorProviderAndroid* PlatformSensorProviderAndroid::GetInstance() {
+ return base::Singleton<
+ PlatformSensorProviderAndroid,
+ base::LeakySingletonTraits<PlatformSensorProviderAndroid>>::get();
+}
+
+PlatformSensorProviderAndroid::PlatformSensorProviderAndroid() {
+ JNIEnv* env = AttachCurrentThread();
+ j_object_.Reset(Java_PlatformSensorProvider_create(
+ env, base::android::GetApplicationContext()));
+}
+
+PlatformSensorProviderAndroid::~PlatformSensorProviderAndroid() = default;
+
+scoped_refptr<PlatformSensor>
+PlatformSensorProviderAndroid::CreateSensorInternal(
+ mojom::SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ uint64_t buffer_size) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> sensor = Java_PlatformSensorProvider_createSensor(
+ env, j_object_.obj(), static_cast<jint>(type));
+
+ if (!sensor.obj())
+ return nullptr;
+
+ return new PlatformSensorAndroid(type, std::move(mapping), buffer_size, this,
+ sensor);
+}
+
+} // namespace device
« no previous file with comments | « device/generic_sensor/platform_sensor_android.cc ('k') | device/generic_sensor/platform_sensor_provider_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698