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

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

Issue 2948253002: Revert of Refactor DeviceMotionEventPump to use //device/generic_sensor instead of //device/sensors (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « device/generic_sensor/DEPS ('k') | services/device/device_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/feature_list.h"
10 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
11 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
12 #include "device/generic_sensor/platform_sensor_provider.h" 11 #include "device/generic_sensor/platform_sensor_provider.h"
13 #include "device/generic_sensor/sensor_impl.h" 12 #include "device/generic_sensor/sensor_impl.h"
14 #include "mojo/public/cpp/bindings/strong_binding.h" 13 #include "mojo/public/cpp/bindings/strong_binding.h"
15 #include "services/device/public/cpp/device_features.h"
16 14
17 namespace device { 15 namespace device {
18 16
19 namespace { 17 namespace {
20 18
21 void RunCallback(mojom::SensorInitParamsPtr init_params, 19 void RunCallback(mojom::SensorInitParamsPtr init_params,
22 mojom::SensorClientRequest client, 20 mojom::SensorClientRequest client,
23 SensorProviderImpl::GetSensorCallback callback) { 21 SensorProviderImpl::GetSensorCallback callback) {
24 std::move(callback).Run(std::move(init_params), std::move(client)); 22 std::move(callback).Run(std::move(init_params), std::move(client));
25 } 23 }
(...skipping 23 matching lines...) Expand all
49 SensorProviderImpl::SensorProviderImpl(PlatformSensorProvider* provider) 47 SensorProviderImpl::SensorProviderImpl(PlatformSensorProvider* provider)
50 : provider_(provider), weak_ptr_factory_(this) { 48 : provider_(provider), weak_ptr_factory_(this) {
51 DCHECK(provider_); 49 DCHECK(provider_);
52 } 50 }
53 51
54 SensorProviderImpl::~SensorProviderImpl() {} 52 SensorProviderImpl::~SensorProviderImpl() {}
55 53
56 void SensorProviderImpl::GetSensor(mojom::SensorType type, 54 void SensorProviderImpl::GetSensor(mojom::SensorType type,
57 mojom::SensorRequest sensor_request, 55 mojom::SensorRequest sensor_request,
58 GetSensorCallback callback) { 56 GetSensorCallback callback) {
59 // TODO(juncai): remove when the GenericSensor feature goes stable.
60 // For sensors that are used by DeviceMotionEvent, don't check the
61 // features::kGenericSensor flag.
62 if (!base::FeatureList::IsEnabled(features::kGenericSensor) &&
63 !(type == mojom::SensorType::ACCELEROMETER ||
64 type == mojom::SensorType::LINEAR_ACCELERATION ||
65 type == mojom::SensorType::GYROSCOPE)) {
66 NotifySensorCreated(nullptr, nullptr, std::move(callback));
67 return;
68 }
69
70 auto cloned_handle = provider_->CloneSharedBufferHandle(); 57 auto cloned_handle = provider_->CloneSharedBufferHandle();
71 if (!cloned_handle.is_valid()) { 58 if (!cloned_handle.is_valid()) {
72 NotifySensorCreated(nullptr, nullptr, std::move(callback)); 59 NotifySensorCreated(nullptr, nullptr, std::move(callback));
73 return; 60 return;
74 } 61 }
75 62
76 scoped_refptr<PlatformSensor> sensor = provider_->GetSensor(type); 63 scoped_refptr<PlatformSensor> sensor = provider_->GetSensor(type);
77 if (!sensor) { 64 if (!sensor) {
78 PlatformSensorProviderBase::CreateSensorCallback cb = base::Bind( 65 PlatformSensorProviderBase::CreateSensorCallback cb = base::Bind(
79 &SensorProviderImpl::SensorCreated, weak_ptr_factory_.GetWeakPtr(), 66 &SensorProviderImpl::SensorCreated, weak_ptr_factory_.GetWeakPtr(),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 init_params->minimum_frequency = sensor->GetMinimumSupportedFrequency(); 102 init_params->minimum_frequency = sensor->GetMinimumSupportedFrequency();
116 DCHECK_GT(init_params->minimum_frequency, 0.0); 103 DCHECK_GT(init_params->minimum_frequency, 0.0);
117 104
118 NotifySensorCreated(std::move(init_params), sensor_impl->GetClient(), 105 NotifySensorCreated(std::move(init_params), sensor_impl->GetClient(),
119 std::move(callback)); 106 std::move(callback));
120 107
121 mojo::MakeStrongBinding(std::move(sensor_impl), std::move(sensor_request)); 108 mojo::MakeStrongBinding(std::move(sensor_impl), std::move(sensor_request));
122 } 109 }
123 110
124 } // namespace device 111 } // namespace device
OLDNEW
« no previous file with comments | « device/generic_sensor/DEPS ('k') | services/device/device_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698