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

Side by Side Diff: services/device/device_service.cc

Issue 2692993006: Port device_sensors to be hosted in Device Service (Closed)
Patch Set: code rebase Created 3 years, 9 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
« no previous file with comments | « services/device/device_service.h ('k') | services/device/manifest.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/device/device_service.h" 5 #include "services/device/device_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "device/sensors/device_sensor_host.h"
12 #include "services/device/fingerprint/fingerprint.h" 13 #include "services/device/fingerprint/fingerprint.h"
13 #include "services/device/power_monitor/power_monitor_message_broadcaster.h" 14 #include "services/device/power_monitor/power_monitor_message_broadcaster.h"
14 #include "services/device/time_zone_monitor/time_zone_monitor.h" 15 #include "services/device/time_zone_monitor/time_zone_monitor.h"
15 #include "services/service_manager/public/cpp/connection.h" 16 #include "services/service_manager/public/cpp/connection.h"
16 #include "services/service_manager/public/cpp/interface_registry.h" 17 #include "services/service_manager/public/cpp/interface_registry.h"
17 18
18 #if defined(OS_ANDROID) 19 #if defined(OS_ANDROID)
19 #include "services/device/android/register_jni.h" 20 #include "services/device/android/register_jni.h"
20 #include "services/device/screen_orientation/screen_orientation_listener_android .h" 21 #include "services/device/screen_orientation/screen_orientation_listener_android .h"
21 #endif 22 #endif
(...skipping 20 matching lines...) Expand all
42 : file_task_runner_(std::move(file_task_runner)), 43 : file_task_runner_(std::move(file_task_runner)),
43 io_task_runner_(std::move(io_task_runner)) {} 44 io_task_runner_(std::move(io_task_runner)) {}
44 45
45 DeviceService::~DeviceService() {} 46 DeviceService::~DeviceService() {}
46 47
47 void DeviceService::OnStart() {} 48 void DeviceService::OnStart() {}
48 49
49 bool DeviceService::OnConnect(const service_manager::ServiceInfo& remote_info, 50 bool DeviceService::OnConnect(const service_manager::ServiceInfo& remote_info,
50 service_manager::InterfaceRegistry* registry) { 51 service_manager::InterfaceRegistry* registry) {
51 registry->AddInterface<mojom::Fingerprint>(this); 52 registry->AddInterface<mojom::Fingerprint>(this);
53 registry->AddInterface<mojom::LightSensor>(this);
54 registry->AddInterface<mojom::MotionSensor>(this);
55 registry->AddInterface<mojom::OrientationSensor>(this);
56 registry->AddInterface<mojom::OrientationAbsoluteSensor>(this);
52 registry->AddInterface<mojom::PowerMonitor>(this); 57 registry->AddInterface<mojom::PowerMonitor>(this);
53 registry->AddInterface<mojom::ScreenOrientationListener>(this); 58 registry->AddInterface<mojom::ScreenOrientationListener>(this);
54 registry->AddInterface<mojom::TimeZoneMonitor>(this); 59 registry->AddInterface<mojom::TimeZoneMonitor>(this);
55 60
56 return true; 61 return true;
57 } 62 }
58 63
59 void DeviceService::Create(const service_manager::Identity& remote_identity, 64 void DeviceService::Create(const service_manager::Identity& remote_identity,
60 mojom::FingerprintRequest request) { 65 mojom::FingerprintRequest request) {
61 Fingerprint::Create(std::move(request)); 66 Fingerprint::Create(std::move(request));
62 } 67 }
63 68
64 void DeviceService::Create(const service_manager::Identity& remote_identity, 69 void DeviceService::Create(const service_manager::Identity& remote_identity,
70 mojom::LightSensorRequest request) {
71 #if defined(OS_ANDROID)
72 // On Android the device sensors implementations need to run on the UI thread
73 // to communicate to Java.
74 DeviceLightHost::Create(std::move(request));
75 #else
76 // On platforms other than Android the device sensors implementations run on
77 // the IO thread.
78 if (io_task_runner_) {
79 io_task_runner_->PostTask(FROM_HERE, base::Bind(&DeviceLightHost::Create,
80 base::Passed(&request)));
81 }
82 #endif // defined(OS_ANDROID)
83 }
84
85 void DeviceService::Create(const service_manager::Identity& remote_identity,
86 mojom::MotionSensorRequest request) {
87 #if defined(OS_ANDROID)
88 // On Android the device sensors implementations need to run on the UI thread
89 // to communicate to Java.
90 DeviceMotionHost::Create(std::move(request));
91 #else
92 // On platforms other than Android the device sensors implementations run on
93 // the IO thread.
94 if (io_task_runner_) {
95 io_task_runner_->PostTask(FROM_HERE, base::Bind(&DeviceMotionHost::Create,
96 base::Passed(&request)));
97 }
98 #endif // defined(OS_ANDROID)
99 }
100
101 void DeviceService::Create(const service_manager::Identity& remote_identity,
102 mojom::OrientationSensorRequest request) {
103 #if defined(OS_ANDROID)
104 // On Android the device sensors implementations need to run on the UI thread
105 // to communicate to Java.
106 DeviceOrientationHost::Create(std::move(request));
107 #else
108 // On platforms other than Android the device sensors implementations run on
109 // the IO thread.
110 if (io_task_runner_) {
111 io_task_runner_->PostTask(
112 FROM_HERE,
113 base::Bind(&DeviceOrientationHost::Create, base::Passed(&request)));
114 }
115 #endif // defined(OS_ANDROID)
116 }
117
118 void DeviceService::Create(const service_manager::Identity& remote_identity,
119 mojom::OrientationAbsoluteSensorRequest request) {
120 #if defined(OS_ANDROID)
121 // On Android the device sensors implementations need to run on the UI thread
122 // to communicate to Java.
123 DeviceOrientationAbsoluteHost::Create(std::move(request));
124 #else
125 // On platforms other than Android the device sensors implementations run on
126 // the IO thread.
127 if (io_task_runner_) {
128 io_task_runner_->PostTask(FROM_HERE,
129 base::Bind(&DeviceOrientationAbsoluteHost::Create,
130 base::Passed(&request)));
131 }
132 #endif // defined(OS_ANDROID)
133 }
134
135 void DeviceService::Create(const service_manager::Identity& remote_identity,
65 mojom::PowerMonitorRequest request) { 136 mojom::PowerMonitorRequest request) {
66 if (!power_monitor_message_broadcaster_) { 137 if (!power_monitor_message_broadcaster_) {
67 power_monitor_message_broadcaster_ = 138 power_monitor_message_broadcaster_ =
68 base::MakeUnique<PowerMonitorMessageBroadcaster>(); 139 base::MakeUnique<PowerMonitorMessageBroadcaster>();
69 } 140 }
70 power_monitor_message_broadcaster_->Bind(std::move(request)); 141 power_monitor_message_broadcaster_->Bind(std::move(request));
71 } 142 }
72 143
73 void DeviceService::Create(const service_manager::Identity& remote_identity, 144 void DeviceService::Create(const service_manager::Identity& remote_identity,
74 mojom::ScreenOrientationListenerRequest request) { 145 mojom::ScreenOrientationListenerRequest request) {
75 #if defined(OS_ANDROID) 146 #if defined(OS_ANDROID)
76 if (io_task_runner_) { 147 if (io_task_runner_) {
77 io_task_runner_->PostTask( 148 io_task_runner_->PostTask(
78 FROM_HERE, base::Bind(&ScreenOrientationListenerAndroid::Create, 149 FROM_HERE, base::Bind(&ScreenOrientationListenerAndroid::Create,
79 base::Passed(&request))); 150 base::Passed(&request)));
80 } 151 }
81 #endif 152 #endif
82 } 153 }
83 154
84 void DeviceService::Create(const service_manager::Identity& remote_identity, 155 void DeviceService::Create(const service_manager::Identity& remote_identity,
85 mojom::TimeZoneMonitorRequest request) { 156 mojom::TimeZoneMonitorRequest request) {
86 if (!time_zone_monitor_) 157 if (!time_zone_monitor_)
87 time_zone_monitor_ = TimeZoneMonitor::Create(file_task_runner_); 158 time_zone_monitor_ = TimeZoneMonitor::Create(file_task_runner_);
88 time_zone_monitor_->Bind(std::move(request)); 159 time_zone_monitor_->Bind(std::move(request));
89 } 160 }
90 161
91 } // namespace device 162 } // namespace device
OLDNEW
« no previous file with comments | « services/device/device_service.h ('k') | services/device/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698