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

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

Issue 2144623003: [sensors] Introduce Generic Sensor API interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheng comments Created 4 years, 5 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
(Empty)
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
5 #include "device/sensors/sensor_provider_impl.h"
6
7 #include <utility>
8
9 #include "device/sensors/platform_sensor_provider.h"
10 #include "device/sensors/sensor_impl.h"
11
12 namespace device {
13 namespace mojom {
14
15 namespace {
16 const uint64_t kSharedBufferSizeInBytes =
17 SensorReadBuffer::kReadBufferSize * static_cast<uint64_t>(SensorType::LAST);
18 }
19
20 PlatformSensorProvider* SensorProviderImpl::s_provider_ = nullptr;
21
22 // static
23 void SensorProviderImpl::Create(
24 mojo::InterfaceRequest<SensorProvider> request) {
25 if (!s_provider_)
26 s_provider_ = PlatformSensorProvider::Create(kSharedBufferSizeInBytes);
27
28 if (s_provider_) {
Reilly Grant (use Gerrit) 2016/07/27 22:07:58 nit: No braces for single-line if.
Mikhail 2016/08/09 19:38:28 Done.
29 new SensorProviderImpl(std::move(request));
30 }
31 }
32
33 SensorProviderImpl::SensorProviderImpl(
34 mojo::InterfaceRequest<SensorProvider> request)
35 : binding_(this, std::move(request)) {}
36
37 SensorProviderImpl::~SensorProviderImpl() {}
38
39 namespace {
Reilly Grant (use Gerrit) 2016/07/27 22:07:58 nit: Keep all the functions defined in anonymous n
Mikhail 2016/08/09 19:38:28 Done.
40
41 void ReportError(const SensorProvider::GetSensorCallback& callback) {
42 callback.Run(nullptr, nullptr);
43 }
44
45 uint64_t GetBufferOffset(device::SensorType type) {
46 return (static_cast<uint64_t>(SensorType::LAST) -
47 static_cast<uint64_t>(type)) *
48 SensorReadBuffer::kReadBufferSize;
49 }
50
51 } // namespace
52
53 void SensorProviderImpl::GetSensor(device::SensorType type,
54 SensorRequest sensor_request,
55 const GetSensorCallback& callback) {
56 auto cloned_handle = s_provider_->GetClonedSharedBufferHandle();
Reilly Grant (use Gerrit) 2016/07/27 22:07:58 The use of auto in this function is counter to my
Mikhail 2016/08/09 19:38:28 Done.
57 if (!cloned_handle.is_valid()) {
58 ReportError(callback);
59 return;
60 }
61
62 auto sensor = s_provider_->GetSensor(type);
63 if (!sensor)
Reilly Grant (use Gerrit) 2016/07/27 22:07:58 nit: Braces are required around the body of a mult
Mikhail 2016/08/09 19:38:28 Done.
64 sensor = s_provider_->CreateSensor(type, SensorReadBuffer::kReadBufferSize,
65 GetBufferOffset(type));
66 if (!sensor) {
67 ReportError(callback);
68 return;
69 }
70
71 SensorImpl* sensor_impl = new SensorImpl(std::move(sensor_request), sensor);
72
73 SensorReadBufferPtr sensor_read_buffer = SensorReadBuffer::New();
74 sensor_read_buffer->memory = std::move(cloned_handle);
75 sensor_read_buffer->offset = GetBufferOffset(type);
76 sensor_read_buffer->mode = sensor->GetReportingMode();
77
78 callback.Run(std::move(sensor_read_buffer), sensor_impl->GetClient());
79 }
80
81 } // namespace mojom
82 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698