| Index: device/device_sensors/device_sensors_orientation_impl.cc
|
| diff --git a/device/device_sensors/device_sensors_orientation_impl.cc b/device/device_sensors/device_sensors_orientation_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..815221b998b01aee244a6957fc82f2dfca15001c
|
| --- /dev/null
|
| +++ b/device/device_sensors/device_sensors_orientation_impl.cc
|
| @@ -0,0 +1,68 @@
|
| +// 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_orientation_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 DeviceSensorsOrientationImpl::Create(
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
| + mojo::InterfaceRequest<DeviceSensorsOrientation> request) {
|
| + if (base::ThreadTaskRunnerHandle::Get() == task_runner) {
|
| + DeviceSensorsOrientationImpl::CreateOnTaskRunnerThread(request.Pass());
|
| + } else {
|
| + task_runner->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&DeviceSensorsOrientationImpl::CreateOnTaskRunnerThread,
|
| + base::Passed(&request)));
|
| + }
|
| +}
|
| +
|
| +// static
|
| +void DeviceSensorsOrientationImpl::CreateOnTaskRunnerThread(
|
| + mojo::InterfaceRequest<DeviceSensorsOrientation> request) {
|
| + new DeviceSensorsOrientationImpl(request.Pass());
|
| +}
|
| +
|
| +DeviceSensorsOrientationImpl::DeviceSensorsOrientationImpl(
|
| + mojo::InterfaceRequest<DeviceSensorsOrientation> request)
|
| + : binding_(this, request.Pass()), is_started_(false) {
|
| +}
|
| +
|
| +DeviceSensorsOrientationImpl::~DeviceSensorsOrientationImpl() {
|
| + if (!is_started_)
|
| + return;
|
| + DeviceInertialSensorService::GetInstance()->RemoveConsumer(
|
| + CONSUMER_TYPE_ORIENTATION);
|
| +}
|
| +
|
| +void DeviceSensorsOrientationImpl::StartPolling(
|
| + int32 peer_process_id,
|
| + const StartPollingCallback& callback) {
|
| + if (is_started_)
|
| + return;
|
| + is_started_ = true;
|
| + DeviceInertialSensorService::GetInstance()->AddConsumer(
|
| + CONSUMER_TYPE_ORIENTATION);
|
| +
|
| + base::Process peer_process =
|
| + base::Process::OpenWithExtraPrivileges(peer_process_id);
|
| + base::SharedMemoryHandle handle =
|
| + DeviceInertialSensorService::GetInstance()
|
| + ->GetSharedMemoryHandleForProcess(CONSUMER_TYPE_ORIENTATION,
|
| + peer_process.Handle());
|
| + device::SharedMemoryPtr result = device::SharedMemory::From(handle);
|
| + callback.Run(result.Pass());
|
| +}
|
| +
|
| +} // namespace device
|
|
|