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

Unified Diff: content/browser/device_sensors/device_sensor_host.cc

Issue 2037513002: Convert device_sensors to use mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@conversion--mime-registry
Patch Set: rebase Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698