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 "services/device/device_service.h" | 5 #include "services/device/device_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "device/generic_sensor/sensor_provider_impl.h" | 15 #include "device/generic_sensor/sensor_provider_impl.h" |
16 #include "device/sensors/device_sensor_host.h" | |
17 #include "device/wake_lock/wake_lock_provider.h" | 16 #include "device/wake_lock/wake_lock_provider.h" |
18 #include "mojo/public/cpp/system/message_pipe.h" | 17 #include "mojo/public/cpp/system/message_pipe.h" |
19 #include "services/device/fingerprint/fingerprint.h" | 18 #include "services/device/fingerprint/fingerprint.h" |
20 #include "services/device/power_monitor/power_monitor_message_broadcaster.h" | 19 #include "services/device/power_monitor/power_monitor_message_broadcaster.h" |
21 #include "services/device/public/cpp/device_features.h" | 20 #include "services/device/public/cpp/device_features.h" |
22 #include "services/device/public/interfaces/battery_monitor.mojom.h" | 21 #include "services/device/public/interfaces/battery_monitor.mojom.h" |
23 #include "services/device/time_zone_monitor/time_zone_monitor.h" | 22 #include "services/device/time_zone_monitor/time_zone_monitor.h" |
24 #include "services/service_manager/public/cpp/bind_source_info.h" | 23 #include "services/service_manager/public/cpp/bind_source_info.h" |
25 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
26 | 25 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 83 |
85 DeviceService::~DeviceService() { | 84 DeviceService::~DeviceService() { |
86 #if !defined(OS_ANDROID) | 85 #if !defined(OS_ANDROID) |
87 device::BatteryStatusService::GetInstance()->Shutdown(); | 86 device::BatteryStatusService::GetInstance()->Shutdown(); |
88 #endif | 87 #endif |
89 } | 88 } |
90 | 89 |
91 void DeviceService::OnStart() { | 90 void DeviceService::OnStart() { |
92 registry_.AddInterface<mojom::Fingerprint>(base::Bind( | 91 registry_.AddInterface<mojom::Fingerprint>(base::Bind( |
93 &DeviceService::BindFingerprintRequest, base::Unretained(this))); | 92 &DeviceService::BindFingerprintRequest, base::Unretained(this))); |
94 registry_.AddInterface<mojom::MotionSensor>(base::Bind( | |
95 &DeviceService::BindMotionSensorRequest, base::Unretained(this))); | |
96 registry_.AddInterface<mojom::OrientationSensor>(base::Bind( | |
97 &DeviceService::BindOrientationSensorRequest, base::Unretained(this))); | |
98 registry_.AddInterface<mojom::OrientationAbsoluteSensor>( | |
99 base::Bind(&DeviceService::BindOrientationAbsoluteSensorRequest, | |
100 base::Unretained(this))); | |
101 registry_.AddInterface<mojom::PowerMonitor>(base::Bind( | 93 registry_.AddInterface<mojom::PowerMonitor>(base::Bind( |
102 &DeviceService::BindPowerMonitorRequest, base::Unretained(this))); | 94 &DeviceService::BindPowerMonitorRequest, base::Unretained(this))); |
103 registry_.AddInterface<mojom::ScreenOrientationListener>( | 95 registry_.AddInterface<mojom::ScreenOrientationListener>( |
104 base::Bind(&DeviceService::BindScreenOrientationListenerRequest, | 96 base::Bind(&DeviceService::BindScreenOrientationListenerRequest, |
105 base::Unretained(this))); | 97 base::Unretained(this))); |
106 if (base::FeatureList::IsEnabled(features::kGenericSensor)) { | 98 if (base::FeatureList::IsEnabled(features::kGenericSensor)) { |
107 registry_.AddInterface<mojom::SensorProvider>(base::Bind( | 99 registry_.AddInterface<mojom::SensorProvider>(base::Bind( |
108 &DeviceService::BindSensorProviderRequest, base::Unretained(this))); | 100 &DeviceService::BindSensorProviderRequest, base::Unretained(this))); |
109 } | 101 } |
110 registry_.AddInterface<mojom::TimeZoneMonitor>(base::Bind( | 102 registry_.AddInterface<mojom::TimeZoneMonitor>(base::Bind( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 VibrationManagerImpl::Create(std::move(request)); | 151 VibrationManagerImpl::Create(std::move(request)); |
160 } | 152 } |
161 #endif | 153 #endif |
162 | 154 |
163 void DeviceService::BindFingerprintRequest( | 155 void DeviceService::BindFingerprintRequest( |
164 const service_manager::BindSourceInfo& source_info, | 156 const service_manager::BindSourceInfo& source_info, |
165 mojom::FingerprintRequest request) { | 157 mojom::FingerprintRequest request) { |
166 Fingerprint::Create(std::move(request)); | 158 Fingerprint::Create(std::move(request)); |
167 } | 159 } |
168 | 160 |
169 void DeviceService::BindMotionSensorRequest( | |
170 const service_manager::BindSourceInfo& source_info, | |
171 mojom::MotionSensorRequest request) { | |
172 #if defined(OS_ANDROID) | |
173 // On Android the device sensors implementations need to run on the UI thread | |
174 // to communicate to Java. | |
175 DeviceMotionHost::Create(std::move(request)); | |
176 #else | |
177 // On platforms other than Android the device sensors implementations run on | |
178 // the IO thread. | |
179 if (io_task_runner_) { | |
180 io_task_runner_->PostTask(FROM_HERE, base::Bind(&DeviceMotionHost::Create, | |
181 base::Passed(&request))); | |
182 } | |
183 #endif // defined(OS_ANDROID) | |
184 } | |
185 | |
186 void DeviceService::BindOrientationSensorRequest( | |
187 const service_manager::BindSourceInfo& source_info, | |
188 mojom::OrientationSensorRequest request) { | |
189 #if defined(OS_ANDROID) | |
190 // On Android the device sensors implementations need to run on the UI thread | |
191 // to communicate to Java. | |
192 DeviceOrientationHost::Create(std::move(request)); | |
193 #else | |
194 // On platforms other than Android the device sensors implementations run on | |
195 // the IO thread. | |
196 if (io_task_runner_) { | |
197 io_task_runner_->PostTask( | |
198 FROM_HERE, | |
199 base::Bind(&DeviceOrientationHost::Create, base::Passed(&request))); | |
200 } | |
201 #endif // defined(OS_ANDROID) | |
202 } | |
203 | |
204 void DeviceService::BindOrientationAbsoluteSensorRequest( | |
205 const service_manager::BindSourceInfo& source_info, | |
206 mojom::OrientationAbsoluteSensorRequest request) { | |
207 #if defined(OS_ANDROID) | |
208 // On Android the device sensors implementations need to run on the UI thread | |
209 // to communicate to Java. | |
210 DeviceOrientationAbsoluteHost::Create(std::move(request)); | |
211 #else | |
212 // On platforms other than Android the device sensors implementations run on | |
213 // the IO thread. | |
214 if (io_task_runner_) { | |
215 io_task_runner_->PostTask(FROM_HERE, | |
216 base::Bind(&DeviceOrientationAbsoluteHost::Create, | |
217 base::Passed(&request))); | |
218 } | |
219 #endif // defined(OS_ANDROID) | |
220 } | |
221 | |
222 void DeviceService::BindPowerMonitorRequest( | 161 void DeviceService::BindPowerMonitorRequest( |
223 const service_manager::BindSourceInfo& source_info, | 162 const service_manager::BindSourceInfo& source_info, |
224 mojom::PowerMonitorRequest request) { | 163 mojom::PowerMonitorRequest request) { |
225 if (!power_monitor_message_broadcaster_) { | 164 if (!power_monitor_message_broadcaster_) { |
226 power_monitor_message_broadcaster_ = | 165 power_monitor_message_broadcaster_ = |
227 base::MakeUnique<PowerMonitorMessageBroadcaster>(); | 166 base::MakeUnique<PowerMonitorMessageBroadcaster>(); |
228 } | 167 } |
229 power_monitor_message_broadcaster_->Bind(std::move(request)); | 168 power_monitor_message_broadcaster_->Bind(std::move(request)); |
230 } | 169 } |
231 | 170 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 java_interface_provider_.Bind(std::move(provider)); | 216 java_interface_provider_.Bind(std::move(provider)); |
278 | 217 |
279 java_interface_provider_initialized_ = true; | 218 java_interface_provider_initialized_ = true; |
280 } | 219 } |
281 | 220 |
282 return &java_interface_provider_; | 221 return &java_interface_provider_; |
283 } | 222 } |
284 #endif | 223 #endif |
285 | 224 |
286 } // namespace device | 225 } // namespace device |
OLD | NEW |