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

Side by Side Diff: device/device_sensors/device_sensors_light_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_light_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 DeviceSensorsLightImpl::Create(
19 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
20 mojo::InterfaceRequest<DeviceSensorsLight> request) {
21 if (base::ThreadTaskRunnerHandle::Get() == task_runner) {
22 DeviceSensorsLightImpl::CreateOnTaskRunnerThread(request.Pass());
23 } else {
24 task_runner->PostTask(
25 FROM_HERE, base::Bind(&DeviceSensorsLightImpl::CreateOnTaskRunnerThread,
26 base::Passed(&request)));
27 }
28 }
29
30 // static
31 void DeviceSensorsLightImpl::CreateOnTaskRunnerThread(
32 mojo::InterfaceRequest<DeviceSensorsLight> request) {
33 new DeviceSensorsLightImpl(request.Pass());
34 }
35
36 DeviceSensorsLightImpl::DeviceSensorsLightImpl(
37 mojo::InterfaceRequest<DeviceSensorsLight> request)
38 : binding_(this, request.Pass()), is_started_(false) {
39 }
40
41 DeviceSensorsLightImpl::~DeviceSensorsLightImpl() {
42 if (!is_started_)
43 return;
44 DeviceInertialSensorService::GetInstance()->RemoveConsumer(
45 CONSUMER_TYPE_LIGHT);
46 }
47
48 void DeviceSensorsLightImpl::StartPolling(
49 int32 peer_process_id,
50 const StartPollingCallback& callback) {
51 if (is_started_)
52 return;
53 is_started_ = true;
54 DeviceInertialSensorService::GetInstance()->AddConsumer(CONSUMER_TYPE_LIGHT);
55
56 base::Process peer_process =
57 base::Process::OpenWithExtraPrivileges(peer_process_id);
58 base::SharedMemoryHandle handle =
59 DeviceInertialSensorService::GetInstance()
60 ->GetSharedMemoryHandleForProcess(CONSUMER_TYPE_LIGHT,
61 peer_process.Handle());
62 device::SharedMemoryPtr result = device::SharedMemory::From(handle);
63 callback.Run(result.Pass());
64 }
65
66 } // namespace device
OLDNEW
« no previous file with comments | « device/device_sensors/device_sensors_light_impl.h ('k') | device/device_sensors/device_sensors_motion_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698