| 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
|
|
|