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

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

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Test compilation fix + comment from Ken 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 void CreateSensorInternal(mojom::SensorType type, 26 void CreateSensorInternal(mojom::SensorType type,
27 mojo::ScopedSharedBufferMapping mapping, 27 mojo::ScopedSharedBufferMapping mapping,
28 uint64_t buffer_size,
29 const CreateSensorCallback& callback) override; 28 const CreateSensorCallback& callback) 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
(...skipping 12 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 void PlatformSensorProviderAndroid::CreateSensorInternal( 57 void PlatformSensorProviderAndroid::CreateSensorInternal(
59 mojom::SensorType type, 58 mojom::SensorType type,
60 mojo::ScopedSharedBufferMapping mapping, 59 mojo::ScopedSharedBufferMapping mapping,
61 uint64_t buffer_size,
62 const CreateSensorCallback& callback) { 60 const CreateSensorCallback& callback) {
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 callback.Run(nullptr); 66 callback.Run(nullptr);
69 67
70 scoped_refptr<PlatformSensorAndroid> concrete_sensor = 68 scoped_refptr<PlatformSensorAndroid> concrete_sensor =
71 new PlatformSensorAndroid(type, std::move(mapping), buffer_size, this, 69 new PlatformSensorAndroid(type, std::move(mapping), this, sensor);
72 sensor);
73 callback.Run(concrete_sensor); 70 callback.Run(concrete_sensor);
74 } 71 }
75 72
76 } // namespace device 73 } // 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