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

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

Issue 2330943002: [Sensors] Handle default sensor configuration (Closed)
Patch Set: Rebased Created 4 years, 3 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/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::SensorReadBuffer::kReadBufferSize; 20 mojom::SensorInitParams::kReadBufferSize;
21 } 21 }
22 22
23 } // namespace 23 } // namespace
24 24
25 // static 25 // static
26 void SensorProviderImpl::Create(mojom::SensorProviderRequest request) { 26 void SensorProviderImpl::Create(mojom::SensorProviderRequest request) {
27 PlatformSensorProvider* provider = PlatformSensorProvider::GetInstance(); 27 PlatformSensorProvider* provider = PlatformSensorProvider::GetInstance();
28 if (provider) { 28 if (provider) {
29 mojo::MakeStrongBinding(base::WrapUnique(new SensorProviderImpl(provider)), 29 mojo::MakeStrongBinding(base::WrapUnique(new SensorProviderImpl(provider)),
30 std::move(request)); 30 std::move(request));
(...skipping 12 matching lines...) Expand all
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 = base::MakeUnique<SensorImpl>(sensor); 61 auto sensor_impl = base::MakeUnique<SensorImpl>(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 mojo::MakeStrongBinding(std::move(sensor_impl), std::move(sensor_request)); 71 mojo::MakeStrongBinding(std::move(sensor_impl), std::move(sensor_request));
71 } 72 }
72 73
73 } // namespace device 74 } // namespace device
OLDNEW
« no previous file with comments | « device/generic_sensor/public/interfaces/sensor_provider.mojom ('k') | third_party/WebKit/Source/modules/sensor/Sensor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698