| 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/sensor_provider_impl.h" | 5 #include "device/generic_sensor/sensor_provider_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "device/generic_sensor/platform_sensor_provider.h" | 9 #include "device/generic_sensor/platform_sensor_provider.h" |
| 10 #include "device/generic_sensor/sensor_impl.h" | 10 #include "device/generic_sensor/sensor_impl.h" |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" | 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 12 | 12 |
| 13 namespace device { | 13 namespace device { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 uint64_t GetBufferOffset(mojom::SensorType type) { | 17 uint64_t GetBufferOffset(mojom::SensorType type) { |
| 18 return (static_cast<uint64_t>(mojom::SensorType::LAST) - | 18 return (static_cast<uint64_t>(mojom::SensorType::LAST) - |
| 19 static_cast<uint64_t>(type)) * | 19 static_cast<uint64_t>(type)) * |
| 20 mojom::SensorInitParams::kReadBufferSize; | 20 mojom::SensorInitParams::kReadBufferSize; |
| 21 } | 21 } |
| 22 | 22 |
| 23 void RunCallback(mojom::SensorInitParamsPtr init_params, | 23 void RunCallback(mojom::SensorInitParamsPtr init_params, |
| 24 SensorImpl* sensor, | 24 mojom::SensorClientRequest client, |
| 25 const SensorProviderImpl::GetSensorCallback& callback) { | 25 const SensorProviderImpl::GetSensorCallback& callback) { |
| 26 callback.Run(std::move(init_params), sensor->GetClient()); | 26 callback.Run(std::move(init_params), std::move(client)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void NotifySensorCreated( | 29 void NotifySensorCreated( |
| 30 mojom::SensorInitParamsPtr init_params, | 30 mojom::SensorInitParamsPtr init_params, |
| 31 SensorImpl* sensor, | 31 mojom::SensorClientRequest client, |
| 32 const SensorProviderImpl::GetSensorCallback& callback) { | 32 const SensorProviderImpl::GetSensorCallback& callback) { |
| 33 base::ThreadTaskRunnerHandle::Get()->PostTask( | 33 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 34 FROM_HERE, | 34 FROM_HERE, base::Bind(RunCallback, base::Passed(&init_params), |
| 35 base::Bind(RunCallback, base::Passed(&init_params), sensor, callback)); | 35 base::Passed(&client), callback)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 void SensorProviderImpl::Create(mojom::SensorProviderRequest request) { | 41 void SensorProviderImpl::Create(mojom::SensorProviderRequest request) { |
| 42 PlatformSensorProvider* provider = PlatformSensorProvider::GetInstance(); | 42 PlatformSensorProvider* provider = PlatformSensorProvider::GetInstance(); |
| 43 if (provider) { | 43 if (provider) { |
| 44 mojo::MakeStrongBinding(base::WrapUnique(new SensorProviderImpl(provider)), | 44 mojo::MakeStrongBinding(base::WrapUnique(new SensorProviderImpl(provider)), |
| 45 std::move(request)); | 45 std::move(request)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 89 } |
| 90 | 90 |
| 91 auto sensor_impl = base::MakeUnique<SensorImpl>(sensor); | 91 auto sensor_impl = base::MakeUnique<SensorImpl>(sensor); |
| 92 | 92 |
| 93 auto init_params = mojom::SensorInitParams::New(); | 93 auto init_params = mojom::SensorInitParams::New(); |
| 94 init_params->memory = std::move(cloned_handle); | 94 init_params->memory = std::move(cloned_handle); |
| 95 init_params->buffer_offset = GetBufferOffset(type); | 95 init_params->buffer_offset = GetBufferOffset(type); |
| 96 init_params->mode = sensor->GetReportingMode(); | 96 init_params->mode = sensor->GetReportingMode(); |
| 97 init_params->default_configuration = sensor->GetDefaultConfiguration(); | 97 init_params->default_configuration = sensor->GetDefaultConfiguration(); |
| 98 | 98 |
| 99 NotifySensorCreated(std::move(init_params), sensor_impl.get(), callback); | 99 NotifySensorCreated(std::move(init_params), sensor_impl->GetClient(), |
| 100 callback); |
| 100 | 101 |
| 101 mojo::MakeStrongBinding(std::move(sensor_impl), std::move(sensor_request)); | 102 mojo::MakeStrongBinding(std::move(sensor_impl), std::move(sensor_request)); |
| 102 } | 103 } |
| 103 | 104 |
| 104 } // namespace device | 105 } // namespace device |
| OLD | NEW |