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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "device/device_sensors/device_sensors_motion_impl.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/process/process.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "device/device_sensors/device_inertial_sensor_service.h"
13 #include "device/device_sensors/type_converters.h"
14
15 namespace device {
16
17 // static
18 void DeviceSensorsMotionImpl::Create(
19 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
20 mojo::InterfaceRequest<DeviceSensorsMotion> request) {
21 if (base::ThreadTaskRunnerHandle::Get() == task_runner) {
22 DeviceSensorsMotionImpl::CreateOnTaskRunnerThread(request.Pass());
23 } else {
24 task_runner->PostTask(
25 FROM_HERE,
26 base::Bind(&DeviceSensorsMotionImpl::CreateOnTaskRunnerThread,
27 base::Passed(&request)));
28 }
29 }
30
31 // static
32 void DeviceSensorsMotionImpl::CreateOnTaskRunnerThread(
33 mojo::InterfaceRequest<DeviceSensorsMotion> request) {
34 new DeviceSensorsMotionImpl(request.Pass());
35 }
36
37 DeviceSensorsMotionImpl::DeviceSensorsMotionImpl(
38 mojo::InterfaceRequest<DeviceSensorsMotion> request)
39 : binding_(this, request.Pass()), is_started_(false) {
40 }
41
42 DeviceSensorsMotionImpl::~DeviceSensorsMotionImpl() {
43 if (!is_started_)
44 return;
45 DeviceInertialSensorService::GetInstance()->RemoveConsumer(
46 CONSUMER_TYPE_MOTION);
47 }
48
49 void DeviceSensorsMotionImpl::StartPolling(
50 int32 peer_process_id,
51 const StartPollingCallback& callback) {
52 if (is_started_)
53 return;
54 is_started_ = true;
55 LOG(WARNING) << "DeviceSensorsMotionImpl::StartPolling, peer process id: "
56 << peer_process_id;
57 LOG(WARNING) << "DeviceSensorsMotionImpl::StartPolling, current process id: "
58 << base::GetCurrentProcId();
59 DeviceInertialSensorService::GetInstance()->AddConsumer(CONSUMER_TYPE_MOTION);
60
61 base::Process peer_process =
62 base::Process::OpenWithExtraPrivileges(peer_process_id);
63 base::SharedMemoryHandle handle =
64 DeviceInertialSensorService::GetInstance()
65 ->GetSharedMemoryHandleForProcess(CONSUMER_TYPE_MOTION,
66 peer_process.Handle());
67 device::SharedMemoryPtr result = device::SharedMemory::From(handle);
68 LOG(WARNING)
69 << "DeviceSensorsMotionImpl::StartPolling, shared memory handle: "
70 << result->fd;
71 callback.Run(result.Pass());
72 }
73
74 } // namespace device
OLDNEW
« 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