| 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 "content/browser/device_sensors/device_sensor_host.h" | 5 #include "content/browser/device_sensors/device_sensor_host.h" |
| 6 | 6 |
| 7 #include "content/browser/device_sensors/device_sensor_service.h" | 7 #include "content/browser/device_sensors/device_sensor_service.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 template <typename MojoInterface, ConsumerType consumer_type> | 12 template <typename MojoInterface, ConsumerType consumer_type> |
| 13 void DeviceSensorHost<MojoInterface, consumer_type>::Create( | 13 void DeviceSensorHost<MojoInterface, consumer_type>::Create( |
| 14 mojo::InterfaceRequest<MojoInterface> request) { | 14 mojo::InterfaceRequest<MojoInterface> request) { |
| 15 new DeviceSensorHost(std::move(request)); | 15 new DeviceSensorHost(std::move(request)); |
| 16 } | 16 } |
| 17 | 17 |
| 18 template <typename MojoInterface, ConsumerType consumer_type> | 18 template <typename MojoInterface, ConsumerType consumer_type> |
| 19 DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost( | 19 DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost( |
| 20 mojo::InterfaceRequest<MojoInterface> request) | 20 mojo::InterfaceRequest<MojoInterface> request) |
| 21 : is_started_(false), binding_(this, std::move(request)) {} | 21 : is_started_(false), binding_(this, std::move(request)) { |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 23 } |
| 22 | 24 |
| 23 template <typename MojoInterface, ConsumerType consumer_type> | 25 template <typename MojoInterface, ConsumerType consumer_type> |
| 24 DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() { | 26 DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() { |
| 25 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 27 DCHECK(thread_checker_.CalledOnValidThread()); |
| 26 if (is_started_) | 28 if (is_started_) |
| 27 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); | 29 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); |
| 28 } | 30 } |
| 29 | 31 |
| 30 template <typename MojoInterface, ConsumerType consumer_type> | 32 template <typename MojoInterface, ConsumerType consumer_type> |
| 31 void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost:: | 33 void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost:: |
| 32 StartPolling(const typename MojoInterface::StartPollingCallback& callback) { | 34 StartPolling(const typename MojoInterface::StartPollingCallback& callback) { |
| 33 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 35 DCHECK(thread_checker_.CalledOnValidThread()); |
| 34 DCHECK(!is_started_); | 36 DCHECK(!is_started_); |
| 35 if (is_started_) | 37 if (is_started_) |
| 36 return; | 38 return; |
| 37 is_started_ = true; | 39 is_started_ = true; |
| 38 DeviceSensorService::GetInstance()->AddConsumer(consumer_type); | 40 DeviceSensorService::GetInstance()->AddConsumer(consumer_type); |
| 39 callback.Run( | 41 callback.Run( |
| 40 DeviceSensorService::GetInstance()->GetSharedMemoryHandle(consumer_type)); | 42 DeviceSensorService::GetInstance()->GetSharedMemoryHandle(consumer_type)); |
| 41 } | 43 } |
| 42 | 44 |
| 43 template <typename MojoInterface, ConsumerType consumer_type> | 45 template <typename MojoInterface, ConsumerType consumer_type> |
| 44 void DeviceSensorHost<MojoInterface, | 46 void DeviceSensorHost<MojoInterface, |
| 45 consumer_type>::DeviceSensorHost::StopPolling() { | 47 consumer_type>::DeviceSensorHost::StopPolling() { |
| 46 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
| 47 DCHECK(is_started_); | 49 DCHECK(is_started_); |
| 48 if (!is_started_) | 50 if (!is_started_) |
| 49 return; | 51 return; |
| 50 is_started_ = false; | 52 is_started_ = false; |
| 51 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); | 53 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); |
| 52 } | 54 } |
| 53 | 55 |
| 54 template class DeviceSensorHost<device::mojom::LightSensor, | 56 template class DeviceSensorHost<device::mojom::LightSensor, |
| 55 CONSUMER_TYPE_LIGHT>; | 57 CONSUMER_TYPE_LIGHT>; |
| 56 template class DeviceSensorHost<device::mojom::MotionSensor, | 58 template class DeviceSensorHost<device::mojom::MotionSensor, |
| 57 CONSUMER_TYPE_MOTION>; | 59 CONSUMER_TYPE_MOTION>; |
| 58 template class DeviceSensorHost<device::mojom::OrientationSensor, | 60 template class DeviceSensorHost<device::mojom::OrientationSensor, |
| 59 CONSUMER_TYPE_ORIENTATION>; | 61 CONSUMER_TYPE_ORIENTATION>; |
| 60 template class DeviceSensorHost<device::mojom::OrientationAbsoluteSensor, | 62 template class DeviceSensorHost<device::mojom::OrientationAbsoluteSensor, |
| 61 CONSUMER_TYPE_ORIENTATION_ABSOLUTE>; | 63 CONSUMER_TYPE_ORIENTATION_ABSOLUTE>; |
| 62 | 64 |
| 63 } // namespace content | 65 } // namespace content |
| OLD | NEW |