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