Chromium Code Reviews| Index: content/browser/device_sensors/device_sensor_host.cc |
| diff --git a/content/browser/device_sensors/device_sensor_host.cc b/content/browser/device_sensors/device_sensor_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9f5fd66c6822259b745b166ed20ac4937568c4ab |
| --- /dev/null |
| +++ b/content/browser/device_sensors/device_sensor_host.cc |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/device_sensors/device_sensor_host.h" |
| + |
| +#include "content/browser/device_sensors/device_inertial_sensor_service.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace content { |
| + |
| +template <typename MojoInterface, ConsumerType consumer_type> |
| +void DeviceSensorHost<MojoInterface, consumer_type>::Create( |
| + mojo::InterfaceRequest<MojoInterface> request) { |
| + new DeviceSensorHost(std::move(request)); |
| +} |
| + |
| +template <typename MojoInterface, ConsumerType consumer_type> |
| +DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost( |
| + mojo::InterfaceRequest<MojoInterface> request) |
| + : is_started_(false), binding_(this, std::move(request)) {} |
| + |
| +template <typename MojoInterface, ConsumerType consumer_type> |
| +DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (is_started_) |
| + DeviceInertialSensorService::GetInstance()->RemoveConsumer(consumer_type); |
|
dcheng
2016/07/04 03:39:49
Is the name for this still accurate? It looks like
Sam McNally
2016/07/04 08:31:38
I think you're right.
|
| +} |
| + |
| +template <typename MojoInterface, ConsumerType consumer_type> |
| +void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost:: |
| + StartPolling(const typename MojoInterface::StartPollingCallback& callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + DCHECK(!is_started_); |
| + if (is_started_) |
| + return; |
| + is_started_ = true; |
| + DeviceInertialSensorService::GetInstance()->AddConsumer(consumer_type); |
| + callback.Run( |
| + DeviceInertialSensorService::GetInstance()->GetSharedMemoryHandle( |
| + consumer_type)); |
| +} |
| + |
| +template <typename MojoInterface, ConsumerType consumer_type> |
| +void DeviceSensorHost<MojoInterface, |
| + consumer_type>::DeviceSensorHost::StopPolling() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + DCHECK(is_started_); |
| + if (!is_started_) |
| + return; |
| + is_started_ = false; |
| + DeviceInertialSensorService::GetInstance()->RemoveConsumer(consumer_type); |
| +} |
| + |
| +template class DeviceSensorHost<device::mojom::LightSensor, |
| + CONSUMER_TYPE_LIGHT>; |
| +template class DeviceSensorHost<device::mojom::MotionSensor, |
| + CONSUMER_TYPE_MOTION>; |
| +template class DeviceSensorHost<device::mojom::OrientationSensor, |
| + CONSUMER_TYPE_ORIENTATION>; |
| +template class DeviceSensorHost<device::mojom::OrientationAbsoluteSensor, |
| + CONSUMER_TYPE_ORIENTATION_ABSOLUTE>; |
| + |
| +} // namespace content |