| OLD | NEW |
| 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_provider.h" | 5 #include "device/generic_sensor/platform_sensor_provider_android.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "device/generic_sensor/platform_sensor_android.h" | 10 #include "device/generic_sensor/platform_sensor_android.h" |
| 11 #include "jni/PlatformSensorProvider_jni.h" | 11 #include "jni/PlatformSensorProvider_jni.h" |
| 12 | 12 |
| 13 using base::android::AttachCurrentThread; | 13 using base::android::AttachCurrentThread; |
| 14 using base::android::ScopedJavaLocalRef; | 14 using base::android::ScopedJavaLocalRef; |
| 15 | 15 |
| 16 namespace device { | 16 namespace device { |
| 17 | 17 |
| 18 class PlatformSensorProviderAndroid : public PlatformSensorProvider { | |
| 19 public: | |
| 20 PlatformSensorProviderAndroid(); | |
| 21 ~PlatformSensorProviderAndroid() override; | |
| 22 | |
| 23 static PlatformSensorProviderAndroid* GetInstance(); | |
| 24 | |
| 25 protected: | |
| 26 void CreateSensorInternal(mojom::SensorType type, | |
| 27 mojo::ScopedSharedBufferMapping mapping, | |
| 28 const CreateSensorCallback& callback) override; | |
| 29 | |
| 30 private: | |
| 31 // Java object org.chromium.device.sensors.PlatformSensorProvider | |
| 32 base::android::ScopedJavaGlobalRef<jobject> j_object_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderAndroid); | |
| 35 }; | |
| 36 | |
| 37 // static | |
| 38 PlatformSensorProvider* PlatformSensorProvider::GetInstance() { | |
| 39 return PlatformSensorProviderAndroid::GetInstance(); | |
| 40 } | |
| 41 | |
| 42 // static | 18 // static |
| 43 PlatformSensorProviderAndroid* PlatformSensorProviderAndroid::GetInstance() { | 19 PlatformSensorProviderAndroid* PlatformSensorProviderAndroid::GetInstance() { |
| 44 return base::Singleton< | 20 return base::Singleton< |
| 45 PlatformSensorProviderAndroid, | 21 PlatformSensorProviderAndroid, |
| 46 base::LeakySingletonTraits<PlatformSensorProviderAndroid>>::get(); | 22 base::LeakySingletonTraits<PlatformSensorProviderAndroid>>::get(); |
| 47 } | 23 } |
| 48 | 24 |
| 49 PlatformSensorProviderAndroid::PlatformSensorProviderAndroid() { | 25 PlatformSensorProviderAndroid::PlatformSensorProviderAndroid() { |
| 50 JNIEnv* env = AttachCurrentThread(); | 26 JNIEnv* env = AttachCurrentThread(); |
| 51 j_object_.Reset(Java_PlatformSensorProvider_create( | 27 j_object_.Reset(Java_PlatformSensorProvider_create( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 | 40 |
| 65 if (!sensor.obj()) | 41 if (!sensor.obj()) |
| 66 callback.Run(nullptr); | 42 callback.Run(nullptr); |
| 67 | 43 |
| 68 scoped_refptr<PlatformSensorAndroid> concrete_sensor = | 44 scoped_refptr<PlatformSensorAndroid> concrete_sensor = |
| 69 new PlatformSensorAndroid(type, std::move(mapping), this, sensor); | 45 new PlatformSensorAndroid(type, std::move(mapping), this, sensor); |
| 70 callback.Run(concrete_sensor); | 46 callback.Run(concrete_sensor); |
| 71 } | 47 } |
| 72 | 48 |
| 73 } // namespace device | 49 } // namespace device |
| OLD | NEW |