platform_sensor_provider_mac.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include "services/device/generic_sensor/platform_sensor_provider_mac.h"
  5. #include "services/device/generic_sensor/orientation_quaternion_fusion_algorithm_using_euler_angles.h"
  6. #include "services/device/generic_sensor/platform_sensor_accelerometer_mac.h"
  7. #include "services/device/generic_sensor/platform_sensor_ambient_light_mac.h"
  8. #include "services/device/generic_sensor/platform_sensor_fusion.h"
  9. #include "services/device/generic_sensor/relative_orientation_euler_angles_fusion_algorithm_using_accelerometer.h"
  10. namespace device {
  11. PlatformSensorProviderMac::PlatformSensorProviderMac() = default;
  12. PlatformSensorProviderMac::~PlatformSensorProviderMac() = default;
  13. void PlatformSensorProviderMac::CreateSensorInternal(
  14. mojom::SensorType type,
  15. SensorReadingSharedBuffer* reading_buffer,
  16. CreateSensorCallback callback) {
  17. // Create Sensors here.
  18. switch (type) {
  19. case mojom::SensorType::AMBIENT_LIGHT: {
  20. scoped_refptr<PlatformSensor> sensor =
  21. new PlatformSensorAmbientLightMac(reading_buffer, this);
  22. std::move(callback).Run(std::move(sensor));
  23. break;
  24. }
  25. case mojom::SensorType::ACCELEROMETER: {
  26. std::move(callback).Run(
  27. base::MakeRefCounted<PlatformSensorAccelerometerMac>(reading_buffer,
  28. this));
  29. break;
  30. }
  31. case mojom::SensorType::RELATIVE_ORIENTATION_EULER_ANGLES: {
  32. auto fusion_algorithm = std::make_unique<
  33. RelativeOrientationEulerAnglesFusionAlgorithmUsingAccelerometer>();
  34. // If this PlatformSensorFusion object is successfully initialized,
  35. // |callback| will be run with a reference to this object.
  36. PlatformSensorFusion::Create(reading_buffer, this,
  37. std::move(fusion_algorithm),
  38. std::move(callback));
  39. break;
  40. }
  41. case mojom::SensorType::RELATIVE_ORIENTATION_QUATERNION: {
  42. auto orientation_quaternion_fusion_algorithm_using_euler_angles =
  43. std::make_unique<
  44. OrientationQuaternionFusionAlgorithmUsingEulerAngles>(
  45. false /* absolute */);
  46. // If this PlatformSensorFusion object is successfully initialized,
  47. // |callback| will be run with a reference to this object.
  48. PlatformSensorFusion::Create(
  49. reading_buffer, this,
  50. std::move(orientation_quaternion_fusion_algorithm_using_euler_angles),
  51. std::move(callback));
  52. break;
  53. }
  54. default:
  55. std::move(callback).Run(nullptr);
  56. }
  57. }
  58. } // namespace device