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

Side by Side Diff: components/arc/arc_bridge_service_impl.cc

Issue 1523643002: arc-bridge: Move most methods to Mojo interfaces (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Addressed feedback Created 5 years 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "components/arc/arc_bridge_service_impl.h" 5 #include "components/arc/arc_bridge_service_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "chromeos/chromeos_switches.h" 16 #include "chromeos/chromeos_switches.h"
17 #include "chromeos/dbus/dbus_method_call_status.h" 17 #include "chromeos/dbus/dbus_method_call_status.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/session_manager_client.h" 19 #include "chromeos/dbus/session_manager_client.h"
20 #include "mojo/public/cpp/bindings/array.h"
21 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
22
23 namespace mojo {
24
25 template <>
26 struct TypeConverter<arc::AppInfo, arc::AppInfoPtr> {
27 static arc::AppInfo Convert(const arc::AppInfoPtr& app_info_ptr) {
28 return *app_info_ptr;
29 }
30 };
31
32 template <>
33 struct TypeConverter<arc::RunningAppProcessInfo,
34 arc::RunningAppProcessInfoPtr> {
35 static arc::RunningAppProcessInfo Convert(
36 const arc::RunningAppProcessInfoPtr& process_ptr) {
37 return *process_ptr;
38 }
39 };
40
41 } // namespace mojo
42 20
43 namespace arc { 21 namespace arc {
44 22
45 ArcBridgeServiceImpl::ArcBridgeServiceImpl( 23 ArcBridgeServiceImpl::ArcBridgeServiceImpl(
46 scoped_ptr<ArcBridgeBootstrap> bootstrap) 24 scoped_ptr<ArcBridgeBootstrap> bootstrap)
47 : bootstrap_(std::move(bootstrap)), 25 : bootstrap_(std::move(bootstrap)),
48 binding_(this), 26 binding_(this),
49 session_started_(false), 27 session_started_(false),
50 weak_factory_(this) { 28 weak_factory_(this) {
51 bootstrap_->set_delegate(this); 29 bootstrap_->set_delegate(this);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
92 if (state() == State::STOPPED || state() == State::STOPPING) { 70 if (state() == State::STOPPED || state() == State::STOPPING) {
93 VLOG(1) << "StopInstance() called when ARC is not running"; 71 VLOG(1) << "StopInstance() called when ARC is not running";
94 return; 72 return;
95 } 73 }
96 74
97 SetState(State::STOPPING); 75 SetState(State::STOPPING);
98 bootstrap_->Stop(); 76 bootstrap_->Stop();
99 } 77 }
100 78
101 bool ArcBridgeServiceImpl::RegisterInputDevice(const std::string& name,
102 const std::string& device_type,
103 base::ScopedFD fd) {
104 DCHECK(CalledOnValidThread());
105 if (state() != State::READY) {
106 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready";
107 return false;
108 }
109 MojoHandle wrapped_handle;
110 MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper(
111 mojo::embedder::ScopedPlatformHandle(
112 mojo::embedder::PlatformHandle(fd.release())),
113 &wrapped_handle);
114 if (wrap_result != MOJO_RESULT_OK) {
115 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result;
116 return false;
117 }
118 instance_ptr_->RegisterInputDevice(
119 name, device_type, mojo::ScopedHandle(mojo::Handle(wrapped_handle)));
120 return true;
121 }
122
123 bool ArcBridgeServiceImpl::SendNotificationEventToAndroid(
124 const std::string& key, ArcNotificationEvent event) {
125 DCHECK(CalledOnValidThread());
126 if (key.empty()) {
127 LOG(ERROR) << "SendNotificationToAndroid failed: Wrong parameter";
128 return false;
129 }
130 if (state() != State::READY) {
131 LOG(ERROR) << "Called SendNotificationEventToAndroid when the service is"
132 << "not ready";
133 return false;
134 }
135 instance_ptr_->SendNotificationEventToAndroid(key, event);
136 return true;
137 }
138
139 bool ArcBridgeServiceImpl::RefreshAppList() {
140 DCHECK(CalledOnValidThread());
141 if (state() != State::READY) {
142 LOG(ERROR) << "Called RefreshAppList when the service is not ready";
143 return false;
144 }
145 instance_ptr_->RefreshAppList();
146 return true;
147 }
148
149 bool ArcBridgeServiceImpl::LaunchApp(const std::string& package,
150 const std::string& activity) {
151 DCHECK(CalledOnValidThread());
152 if (state() != State::READY) {
153 LOG(ERROR) << "Called LaunchApp when the service is not ready";
154 return false;
155 }
156 instance_ptr_->LaunchApp(package, activity);
157 return true;
158 }
159
160 bool ArcBridgeServiceImpl::RequestAppIcon(const std::string& package,
161 const std::string& activity,
162 ScaleFactor scale_factor) {
163 DCHECK(CalledOnValidThread());
164 if (state() != State::READY) {
165 LOG(ERROR) << "Called RequestAppIcon when the service is not ready";
166 return false;
167 }
168 instance_ptr_->RequestAppIcon(package, activity, scale_factor);
169 return true;
170 }
171
172 bool ArcBridgeServiceImpl::RequestProcessList() {
173 DCHECK(CalledOnValidThread());
174 if (state() != State::READY) {
175 LOG(ERROR) << "Called RequestProcessList when the service is not ready";
176 return false;
177 }
178 instance_ptr_->RequestProcessList();
179 return true;
180 }
181
182 void ArcBridgeServiceImpl::OnInstanceBootPhase(InstanceBootPhase phase) {
183 DCHECK(CalledOnValidThread());
184 // The state can be CONNECTED the first time this is called, and will then
185 // transition to READY after BRIDGE_READY has been passed.
186 if (state() != State::CONNECTED && state() != State::READY) {
187 VLOG(1) << "StopInstance() called while connecting";
188 return;
189 }
190 if (phase == INSTANCE_BOOT_PHASE_BRIDGE_READY) {
191 SetState(State::READY);
192 }
193 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase));
194 }
195
196 void ArcBridgeServiceImpl::OnNotificationPosted(ArcNotificationDataPtr data) {
197 DCHECK(CalledOnValidThread());
198 FOR_EACH_OBSERVER(NotificationObserver, notification_observer_list(),
199 OnNotificationPostedFromAndroid(*data.get()));
200 }
201
202 void ArcBridgeServiceImpl::OnNotificationRemoved(const mojo::String& key) {
203 DCHECK(CalledOnValidThread());
204 FOR_EACH_OBSERVER(NotificationObserver, notification_observer_list(),
205 OnNotificationRemovedFromAndroid(key));
206 }
207
208 void ArcBridgeServiceImpl::OnAppListRefreshed(
209 mojo::Array<arc::AppInfoPtr> apps_ptr) {
210 DCHECK(CalledOnValidThread());
211 std::vector<arc::AppInfo> apps(apps_ptr.To<std::vector<arc::AppInfo>>());
212 FOR_EACH_OBSERVER(AppObserver, app_observer_list(), OnAppListRefreshed(apps));
213 }
214
215 void ArcBridgeServiceImpl::OnAppIcon(const mojo::String& package,
216 const mojo::String& activity,
217 ScaleFactor scale_factor,
218 mojo::Array<uint8_t> icon_png_data) {
219 DCHECK(CalledOnValidThread());
220 FOR_EACH_OBSERVER(
221 AppObserver, app_observer_list(),
222 OnAppIcon(package, activity, scale_factor, icon_png_data.storage()));
223 }
224
225 void ArcBridgeServiceImpl::OnUpdateProcessList(
226 mojo::Array<RunningAppProcessInfoPtr> processes_ptr) {
227 DCHECK(CalledOnValidThread());
228 std::vector<RunningAppProcessInfo> processes(
229 processes_ptr.To<std::vector<RunningAppProcessInfo>>());
230 FOR_EACH_OBSERVER(
231 ProcessObserver,
232 process_observer_list(),
233 OnUpdateProcessList(processes));
234 }
235
236 void ArcBridgeServiceImpl::OnAcquireDisplayWakeLock(DisplayWakeLockType type) {
237 DCHECK(CalledOnValidThread());
238 // TODO(ejcaruso): Implement.
239 VLOG(1) << "OnAcquireDisplayWakeLock";
240 }
241
242 void ArcBridgeServiceImpl::OnReleaseDisplayWakeLock(DisplayWakeLockType type) {
243 DCHECK(CalledOnValidThread());
244 // TODO(ejcaruso): Implement.
245 VLOG(1) << "OnReleaseDisplayWakeLock";
246 }
247
248 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { 79 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) {
249 DCHECK(CalledOnValidThread()); 80 DCHECK(CalledOnValidThread());
250 if (available() == arc_available) 81 if (available() == arc_available)
251 return; 82 return;
252 SetAvailable(arc_available); 83 SetAvailable(arc_available);
253 PrerequisitesChanged(); 84 PrerequisitesChanged();
254 } 85 }
255 86
256 void ArcBridgeServiceImpl::OnConnectionEstablished( 87 void ArcBridgeServiceImpl::OnConnectionEstablished(
257 ArcBridgeInstancePtr instance) { 88 ArcBridgeInstancePtr instance) {
258 DCHECK(CalledOnValidThread()); 89 DCHECK(CalledOnValidThread());
259 if (state() != State::CONNECTING) { 90 if (state() != State::CONNECTING) {
260 VLOG(1) << "StopInstance() called while connecting"; 91 VLOG(1) << "StopInstance() called while connecting";
261 return; 92 return;
262 } 93 }
263 94
264 instance_ptr_ = std::move(instance); 95 instance_ptr_ = std::move(instance);
265 96
266 ArcBridgeHostPtr host; 97 ArcBridgeHostPtr host;
267 binding_.Bind(GetProxy(&host)); 98 binding_.Bind(GetProxy(&host));
268 instance_ptr_->Init(std::move(host)); 99 instance_ptr_->Init(std::move(host));
269 100
270 SetState(State::CONNECTED); 101 SetState(State::READY);
271 } 102 }
272 103
273 void ArcBridgeServiceImpl::OnStopped() { 104 void ArcBridgeServiceImpl::OnStopped() {
274 DCHECK(CalledOnValidThread()); 105 DCHECK(CalledOnValidThread());
275 SetState(State::STOPPED); 106 SetState(State::STOPPED);
276 } 107 }
277 108
278 } // namespace arc 109 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698