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

Unified Diff: device/device_sensors/device_sensors_motion_impl.cc

Issue 1164563003: Extract device_sensors to /device via Mojofication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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: device/device_sensors/device_sensors_motion_impl.cc
diff --git a/device/device_sensors/device_sensors_motion_impl.cc b/device/device_sensors/device_sensors_motion_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c8134bc16f2c36aae2aef5cc3e552f77789df7a1
--- /dev/null
+++ b/device/device_sensors/device_sensors_motion_impl.cc
@@ -0,0 +1,74 @@
+// Copyright 2015 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 "device/device_sensors/device_sensors_motion_impl.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/process/process.h"
+#include "base/thread_task_runner_handle.h"
+#include "device/device_sensors/device_inertial_sensor_service.h"
+#include "device/device_sensors/type_converters.h"
+
+namespace device {
+
+// static
+void DeviceSensorsMotionImpl::Create(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ mojo::InterfaceRequest<DeviceSensorsMotion> request) {
+ if (base::ThreadTaskRunnerHandle::Get() == task_runner) {
+ DeviceSensorsMotionImpl::CreateOnTaskRunnerThread(request.Pass());
+ } else {
+ task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(&DeviceSensorsMotionImpl::CreateOnTaskRunnerThread,
+ base::Passed(&request)));
+ }
+}
+
+// static
+void DeviceSensorsMotionImpl::CreateOnTaskRunnerThread(
+ mojo::InterfaceRequest<DeviceSensorsMotion> request) {
+ new DeviceSensorsMotionImpl(request.Pass());
+}
+
+DeviceSensorsMotionImpl::DeviceSensorsMotionImpl(
+ mojo::InterfaceRequest<DeviceSensorsMotion> request)
+ : binding_(this, request.Pass()), is_started_(false) {
+}
+
+DeviceSensorsMotionImpl::~DeviceSensorsMotionImpl() {
+ if (!is_started_)
+ return;
+ DeviceInertialSensorService::GetInstance()->RemoveConsumer(
+ CONSUMER_TYPE_MOTION);
+}
+
+void DeviceSensorsMotionImpl::StartPolling(
+ int32 peer_process_id,
+ const StartPollingCallback& callback) {
+ if (is_started_)
+ return;
+ is_started_ = true;
+ LOG(WARNING) << "DeviceSensorsMotionImpl::StartPolling, peer process id: "
+ << peer_process_id;
+ LOG(WARNING) << "DeviceSensorsMotionImpl::StartPolling, current process id: "
+ << base::GetCurrentProcId();
+ DeviceInertialSensorService::GetInstance()->AddConsumer(CONSUMER_TYPE_MOTION);
+
+ base::Process peer_process =
+ base::Process::OpenWithExtraPrivileges(peer_process_id);
+ base::SharedMemoryHandle handle =
+ DeviceInertialSensorService::GetInstance()
+ ->GetSharedMemoryHandleForProcess(CONSUMER_TYPE_MOTION,
+ peer_process.Handle());
+ device::SharedMemoryPtr result = device::SharedMemory::From(handle);
+ LOG(WARNING)
+ << "DeviceSensorsMotionImpl::StartPolling, shared memory handle: "
+ << result->fd;
+ callback.Run(result.Pass());
+}
+
+} // namespace device
« no previous file with comments | « device/device_sensors/device_sensors_motion_impl.h ('k') | device/device_sensors/device_sensors_orientation_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698