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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "device/generic_sensor/platform_sensor_provider.h"
6
7 #include "base/android/context_utils.h"
8 #include "base/android/scoped_java_ref.h"
9 #include "base/memory/singleton.h"
10 #include "device/generic_sensor/platform_sensor_android.h"
11 #include "jni/PlatformSensorProvider_jni.h"
12
13 using base::android::AttachCurrentThread;
14 using base::android::ScopedJavaLocalRef;
15
16 namespace device {
17
18 class PlatformSensorProviderAndroid : public PlatformSensorProvider {
19 public:
20 PlatformSensorProviderAndroid();
21 ~PlatformSensorProviderAndroid() override;
22
23 static PlatformSensorProviderAndroid* GetInstance();
24
25 protected:
26 scoped_refptr<PlatformSensor> CreateSensorInternal(
27 mojom::SensorType type,
28 mojo::ScopedSharedBufferMapping mapping,
29 uint64_t buffer_size) override;
30
31 private:
32 // Java object org.chromium.device.sensors.PlatformSensorProvider
33 base::android::ScopedJavaGlobalRef<jobject> j_object_;
34
35 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderAndroid);
36 };
37
38 // static
39 PlatformSensorProvider* PlatformSensorProvider::GetInstance() {
40 return PlatformSensorProviderAndroid::GetInstance();
41 }
42
43 // static
44 PlatformSensorProviderAndroid* PlatformSensorProviderAndroid::GetInstance() {
45 return base::Singleton<
46 PlatformSensorProviderAndroid,
47 base::LeakySingletonTraits<PlatformSensorProviderAndroid>>::get();
48 }
49
50 PlatformSensorProviderAndroid::PlatformSensorProviderAndroid() {
51 JNIEnv* env = AttachCurrentThread();
52 j_object_.Reset(Java_PlatformSensorProvider_create(
53 env, base::android::GetApplicationContext()));
54 }
55
56 PlatformSensorProviderAndroid::~PlatformSensorProviderAndroid() = default;
57
58 scoped_refptr<PlatformSensor>
59 PlatformSensorProviderAndroid::CreateSensorInternal(
60 mojom::SensorType type,
61 mojo::ScopedSharedBufferMapping mapping,
62 uint64_t buffer_size) {
63 JNIEnv* env = AttachCurrentThread();
64 ScopedJavaLocalRef<jobject> sensor = Java_PlatformSensorProvider_createSensor(
65 env, j_object_.obj(), static_cast<jint>(type));
66
67 if (!sensor.obj())
68 return nullptr;
69
70 return new PlatformSensorAndroid(type, std::move(mapping), buffer_size, this,
71 sensor);
72 }
73
74 } // namespace device
OLDNEW
« 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