| OLD | NEW |
| (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/device_sensor_host.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "device/sensors/device_sensor_export.h" | |
| 10 #include "device/sensors/device_sensor_service.h" | |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 12 | |
| 13 namespace device { | |
| 14 | |
| 15 template <typename MojoInterface, ConsumerType consumer_type> | |
| 16 void DeviceSensorHost<MojoInterface, consumer_type>::Create( | |
| 17 mojo::InterfaceRequest<MojoInterface> request) { | |
| 18 mojo::MakeStrongBinding( | |
| 19 base::WrapUnique(new DeviceSensorHost<MojoInterface, consumer_type>), | |
| 20 std::move(request)); | |
| 21 } | |
| 22 | |
| 23 template <typename MojoInterface, ConsumerType consumer_type> | |
| 24 DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost() | |
| 25 : is_started_(false) { | |
| 26 #if defined(OS_ANDROID) | |
| 27 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
| 28 #endif | |
| 29 } | |
| 30 | |
| 31 template <typename MojoInterface, ConsumerType consumer_type> | |
| 32 DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() { | |
| 33 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 34 if (is_started_) | |
| 35 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); | |
| 36 } | |
| 37 | |
| 38 template <typename MojoInterface, ConsumerType consumer_type> | |
| 39 void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost:: | |
| 40 StartPolling(const typename MojoInterface::StartPollingCallback& callback) { | |
| 41 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 42 DCHECK(!is_started_); | |
| 43 if (is_started_) | |
| 44 return; | |
| 45 is_started_ = true; | |
| 46 DeviceSensorService::GetInstance()->AddConsumer(consumer_type); | |
| 47 callback.Run( | |
| 48 DeviceSensorService::GetInstance()->GetSharedMemoryHandle(consumer_type)); | |
| 49 } | |
| 50 | |
| 51 template <typename MojoInterface, ConsumerType consumer_type> | |
| 52 void DeviceSensorHost<MojoInterface, | |
| 53 consumer_type>::DeviceSensorHost::StopPolling() { | |
| 54 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 55 DCHECK(is_started_); | |
| 56 if (!is_started_) | |
| 57 return; | |
| 58 is_started_ = false; | |
| 59 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); | |
| 60 } | |
| 61 | |
| 62 template class DEVICE_SENSOR_EXPORT | |
| 63 DeviceSensorHost<device::mojom::LightSensor, CONSUMER_TYPE_LIGHT>; | |
| 64 template class DEVICE_SENSOR_EXPORT | |
| 65 DeviceSensorHost<device::mojom::MotionSensor, CONSUMER_TYPE_MOTION>; | |
| 66 template class DEVICE_SENSOR_EXPORT | |
| 67 DeviceSensorHost<device::mojom::OrientationSensor, | |
| 68 CONSUMER_TYPE_ORIENTATION>; | |
| 69 template class DEVICE_SENSOR_EXPORT | |
| 70 DeviceSensorHost<device::mojom::OrientationAbsoluteSensor, | |
| 71 CONSUMER_TYPE_ORIENTATION_ABSOLUTE>; | |
| 72 | |
| 73 } // namespace device | |
| OLD | NEW |