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

Side by Side Diff: device/generic_sensor/platform_sensor_provider_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_provider.h" 5 #include "device/generic_sensor/platform_sensor_provider.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 { 18 class PlatformSensorProviderAndroid : public PlatformSensorProvider {
19 public: 19 public:
20 PlatformSensorProviderAndroid(); 20 PlatformSensorProviderAndroid();
21 ~PlatformSensorProviderAndroid() override; 21 ~PlatformSensorProviderAndroid() override;
22 22
23 static PlatformSensorProviderAndroid* GetInstance(); 23 static PlatformSensorProviderAndroid* GetInstance();
24 24
25 protected: 25 protected:
26 scoped_refptr<PlatformSensor> CreateSensorInternal( 26 scoped_refptr<PlatformSensor> CreateSensorInternal(
27 mojom::SensorType type, 27 mojom::SensorType type,
28 mojo::ScopedSharedBufferMapping mapping, 28 mojo::ScopedSharedBufferMapping mapping) override;
29 uint64_t buffer_size) override;
30 29
31 private: 30 private:
32 // Java object org.chromium.device.sensors.PlatformSensorProvider 31 // Java object org.chromium.device.sensors.PlatformSensorProvider
33 base::android::ScopedJavaGlobalRef<jobject> j_object_; 32 base::android::ScopedJavaGlobalRef<jobject> j_object_;
34 33
35 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderAndroid); 34 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderAndroid);
36 }; 35 };
37 36
38 // static 37 // static
39 PlatformSensorProvider* PlatformSensorProvider::GetInstance() { 38 PlatformSensorProvider* PlatformSensorProvider::GetInstance() {
(...skipping 11 matching lines...) Expand all
51 JNIEnv* env = AttachCurrentThread(); 50 JNIEnv* env = AttachCurrentThread();
52 j_object_.Reset(Java_PlatformSensorProvider_create( 51 j_object_.Reset(Java_PlatformSensorProvider_create(
53 env, base::android::GetApplicationContext())); 52 env, base::android::GetApplicationContext()));
54 } 53 }
55 54
56 PlatformSensorProviderAndroid::~PlatformSensorProviderAndroid() = default; 55 PlatformSensorProviderAndroid::~PlatformSensorProviderAndroid() = default;
57 56
58 scoped_refptr<PlatformSensor> 57 scoped_refptr<PlatformSensor>
59 PlatformSensorProviderAndroid::CreateSensorInternal( 58 PlatformSensorProviderAndroid::CreateSensorInternal(
60 mojom::SensorType type, 59 mojom::SensorType type,
61 mojo::ScopedSharedBufferMapping mapping, 60 mojo::ScopedSharedBufferMapping mapping) {
62 uint64_t buffer_size) {
63 JNIEnv* env = AttachCurrentThread(); 61 JNIEnv* env = AttachCurrentThread();
64 ScopedJavaLocalRef<jobject> sensor = Java_PlatformSensorProvider_createSensor( 62 ScopedJavaLocalRef<jobject> sensor = Java_PlatformSensorProvider_createSensor(
65 env, j_object_.obj(), static_cast<jint>(type)); 63 env, j_object_.obj(), static_cast<jint>(type));
66 64
67 if (!sensor.obj()) 65 if (!sensor.obj())
68 return nullptr; 66 return nullptr;
69 67
70 return new PlatformSensorAndroid(type, std::move(mapping), buffer_size, this, 68 return new PlatformSensorAndroid(type, std::move(mapping), this, sensor);
71 sensor);
72 } 69 }
73 70
74 } // namespace device 71 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698