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 | 11 |
12 namespace device { | 12 namespace device { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 uint64_t GetBufferOffset(mojom::SensorType type) { | 16 uint64_t GetBufferOffset(mojom::SensorType type) { |
17 return (static_cast<uint64_t>(mojom::SensorType::LAST) - | 17 return (static_cast<uint64_t>(mojom::SensorType::LAST) - |
18 static_cast<uint64_t>(type)) * | 18 static_cast<uint64_t>(type)) * |
19 mojom::SensorReadBuffer::kReadBufferSize; | 19 mojom::SensorInitParams::kReadBufferSize; |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 // static | 24 // static |
25 void SensorProviderImpl::Create( | 25 void SensorProviderImpl::Create( |
26 mojo::InterfaceRequest<mojom::SensorProvider> request) { | 26 mojo::InterfaceRequest<mojom::SensorProvider> request) { |
27 PlatformSensorProvider* provider = PlatformSensorProvider::GetInstance(); | 27 PlatformSensorProvider* provider = PlatformSensorProvider::GetInstance(); |
28 if (provider) | 28 if (provider) |
29 new SensorProviderImpl(std::move(request), provider); | 29 new SensorProviderImpl(std::move(request), provider); |
(...skipping 13 matching lines...) Expand all Loading... |
43 const GetSensorCallback& callback) { | 43 const GetSensorCallback& callback) { |
44 auto cloned_handle = provider_->CloneSharedBufferHandle(); | 44 auto cloned_handle = provider_->CloneSharedBufferHandle(); |
45 if (!cloned_handle.is_valid()) { | 45 if (!cloned_handle.is_valid()) { |
46 callback.Run(nullptr, nullptr); | 46 callback.Run(nullptr, nullptr); |
47 return; | 47 return; |
48 } | 48 } |
49 | 49 |
50 scoped_refptr<PlatformSensor> sensor = provider_->GetSensor(type); | 50 scoped_refptr<PlatformSensor> sensor = provider_->GetSensor(type); |
51 if (!sensor) { | 51 if (!sensor) { |
52 sensor = provider_->CreateSensor( | 52 sensor = provider_->CreateSensor( |
53 type, mojom::SensorReadBuffer::kReadBufferSize, GetBufferOffset(type)); | 53 type, mojom::SensorInitParams::kReadBufferSize, GetBufferOffset(type)); |
54 } | 54 } |
55 | 55 |
56 if (!sensor) { | 56 if (!sensor) { |
57 callback.Run(nullptr, nullptr); | 57 callback.Run(nullptr, nullptr); |
58 return; | 58 return; |
59 } | 59 } |
60 | 60 |
61 auto sensor_impl = new SensorImpl(std::move(sensor_request), sensor); | 61 auto sensor_impl = new SensorImpl(std::move(sensor_request), sensor); |
62 | 62 |
63 auto sensor_read_buffer = mojom::SensorReadBuffer::New(); | 63 auto init_params = mojom::SensorInitParams::New(); |
64 sensor_read_buffer->memory = std::move(cloned_handle); | 64 init_params->memory = std::move(cloned_handle); |
65 sensor_read_buffer->offset = GetBufferOffset(type); | 65 init_params->buffer_offset = GetBufferOffset(type); |
66 sensor_read_buffer->mode = sensor->GetReportingMode(); | 66 init_params->mode = sensor->GetReportingMode(); |
| 67 init_params->default_configuration = sensor->GetDefaultConfiguration(); |
67 | 68 |
68 callback.Run(std::move(sensor_read_buffer), sensor_impl->GetClient()); | 69 callback.Run(std::move(init_params), sensor_impl->GetClient()); |
69 } | 70 } |
70 | 71 |
71 } // namespace device | 72 } // namespace device |
OLD | NEW |