Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: content/browser/device_sensors/device_sensor_host.cc

Issue 2646093002: Move //content/browser/device_sensor/ into device/sensors (Closed)
Patch Set: gn format & code rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "content/browser/device_sensors/device_sensor_service.h"
10 #include "mojo/public/cpp/bindings/strong_binding.h"
11
12 namespace content {
13
14 template <typename MojoInterface, ConsumerType consumer_type>
15 void DeviceSensorHost<MojoInterface, consumer_type>::Create(
16 mojo::InterfaceRequest<MojoInterface> request) {
17 mojo::MakeStrongBinding(
18 base::WrapUnique(new DeviceSensorHost<MojoInterface, consumer_type>),
19 std::move(request));
20 }
21
22 template <typename MojoInterface, ConsumerType consumer_type>
23 DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost()
24 : is_started_(false) {
25 #if defined(OS_ANDROID)
26 DCHECK(base::MessageLoopForUI::IsCurrent());
27 #else
28 DCHECK(base::MessageLoopForIO::IsCurrent());
29 #endif
30 }
31
32 template <typename MojoInterface, ConsumerType consumer_type>
33 DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() {
34 DCHECK(thread_checker_.CalledOnValidThread());
35 if (is_started_)
36 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type);
37 }
38
39 template <typename MojoInterface, ConsumerType consumer_type>
40 void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost::
41 StartPolling(const typename MojoInterface::StartPollingCallback& callback) {
42 DCHECK(thread_checker_.CalledOnValidThread());
43 DCHECK(!is_started_);
44 if (is_started_)
45 return;
46 is_started_ = true;
47 DeviceSensorService::GetInstance()->AddConsumer(consumer_type);
48 callback.Run(
49 DeviceSensorService::GetInstance()->GetSharedMemoryHandle(consumer_type));
50 }
51
52 template <typename MojoInterface, ConsumerType consumer_type>
53 void DeviceSensorHost<MojoInterface,
54 consumer_type>::DeviceSensorHost::StopPolling() {
55 DCHECK(thread_checker_.CalledOnValidThread());
56 DCHECK(is_started_);
57 if (!is_started_)
58 return;
59 is_started_ = false;
60 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type);
61 }
62
63 template class DeviceSensorHost<device::mojom::LightSensor,
64 CONSUMER_TYPE_LIGHT>;
65 template class DeviceSensorHost<device::mojom::MotionSensor,
66 CONSUMER_TYPE_MOTION>;
67 template class DeviceSensorHost<device::mojom::OrientationSensor,
68 CONSUMER_TYPE_ORIENTATION>;
69 template class DeviceSensorHost<device::mojom::OrientationAbsoluteSensor,
70 CONSUMER_TYPE_ORIENTATION_ABSOLUTE>;
71
72 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/device_sensors/device_sensor_host.h ('k') | content/browser/device_sensors/device_sensor_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698