OLD | NEW |
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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 base::ScopedFD fd) { | 101 base::ScopedFD fd) { |
102 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 102 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
103 if (state() != State::READY) { | 103 if (state() != State::READY) { |
104 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; | 104 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; |
105 return false; | 105 return false; |
106 } | 106 } |
107 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( | 107 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( |
108 name, device_type, base::FileDescriptor(fd.Pass()))); | 108 name, device_type, base::FileDescriptor(fd.Pass()))); |
109 } | 109 } |
110 | 110 |
| 111 bool ArcBridgeServiceImpl::SendNotificationEventToAndroid( |
| 112 const std::string& key, ArcNotificationEvent event) { |
| 113 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread()); |
| 114 if (key.empty()) { |
| 115 LOG(ERROR) << "SendNotificationToAndroid failed: Wrong parameter"; |
| 116 return false; |
| 117 } |
| 118 if (state() != State::READY) { |
| 119 LOG(ERROR) << "Called SendNotificationEventToAndroid when the service is" |
| 120 << "not ready"; |
| 121 return false; |
| 122 } |
| 123 return ipc_channel_->Send( |
| 124 new ArcInstanceMsg_SendNotificationEventToAndroid(key, event)); |
| 125 } |
| 126 |
111 bool ArcBridgeServiceImpl::RefreshAppList() { | 127 bool ArcBridgeServiceImpl::RefreshAppList() { |
112 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 128 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
113 if (state() != State::READY) { | 129 if (state() != State::READY) { |
114 LOG(ERROR) << "Called RefreshAppList when the service is not ready"; | 130 LOG(ERROR) << "Called RefreshAppList when the service is not ready"; |
115 return false; | 131 return false; |
116 } | 132 } |
117 return ipc_channel_->Send(new ArcInstanceMsg_RefreshApps()); | 133 return ipc_channel_->Send(new ArcInstanceMsg_RefreshApps()); |
118 } | 134 } |
119 | 135 |
120 bool ArcBridgeServiceImpl::LaunchApp(const std::string& package, | 136 bool ArcBridgeServiceImpl::LaunchApp(const std::string& package, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 if (state() != State::STARTING && state() != State::READY) { | 260 if (state() != State::STARTING && state() != State::READY) { |
245 VLOG(1) << "StopInstance() called while connecting"; | 261 VLOG(1) << "StopInstance() called while connecting"; |
246 return; | 262 return; |
247 } | 263 } |
248 if (phase == InstanceBootPhase::BRIDGE_READY) { | 264 if (phase == InstanceBootPhase::BRIDGE_READY) { |
249 SetState(State::READY); | 265 SetState(State::READY); |
250 } | 266 } |
251 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase)); | 267 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase)); |
252 } | 268 } |
253 | 269 |
| 270 void ArcBridgeServiceImpl::OnNotificationPostedFromAndroid( |
| 271 const arc::ArcNotificationData& data) { |
| 272 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
| 273 FOR_EACH_OBSERVER(NotificationObserver, notification_observer_list(), |
| 274 OnNotificationPostedFromAndroid(data)); |
| 275 } |
| 276 |
| 277 void ArcBridgeServiceImpl::OnNotificationRemovedFromAndroid( |
| 278 const std::string& key) { |
| 279 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
| 280 FOR_EACH_OBSERVER(NotificationObserver, notification_observer_list(), |
| 281 OnNotificationRemovedFromAndroid(key)); |
| 282 } |
| 283 |
254 bool ArcBridgeServiceImpl::OnMessageReceived(const IPC::Message& message) { | 284 bool ArcBridgeServiceImpl::OnMessageReceived(const IPC::Message& message) { |
255 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 285 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
256 bool handled = true; | 286 bool handled = true; |
257 | 287 |
258 IPC_BEGIN_MESSAGE_MAP(ArcBridgeServiceImpl, message) | 288 IPC_BEGIN_MESSAGE_MAP(ArcBridgeServiceImpl, message) |
259 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceBootPhase, | 289 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceBootPhase, |
260 OnInstanceBootPhase) | 290 OnInstanceBootPhase) |
261 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_AppListRefreshed, OnAppListRefreshed) | 291 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_AppListRefreshed, OnAppListRefreshed) |
262 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_AppIcon, OnAppIcon) | 292 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_AppIcon, OnAppIcon) |
| 293 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationPosted, |
| 294 OnNotificationPostedFromAndroid) |
| 295 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationRemoved, |
| 296 OnNotificationRemovedFromAndroid) |
263 IPC_MESSAGE_UNHANDLED(handled = false) | 297 IPC_MESSAGE_UNHANDLED(handled = false) |
264 IPC_END_MESSAGE_MAP() | 298 IPC_END_MESSAGE_MAP() |
265 | 299 |
266 if (!handled) | 300 if (!handled) |
267 LOG(ERROR) << "Invalid message with type = " << message.type(); | 301 LOG(ERROR) << "Invalid message with type = " << message.type(); |
268 return handled; | 302 return handled; |
269 } | 303 } |
270 | 304 |
271 void ArcBridgeServiceImpl::OnAppListRefreshed( | 305 void ArcBridgeServiceImpl::OnAppListRefreshed( |
272 const std::vector<arc::AppInfo>& apps) { | 306 const std::vector<arc::AppInfo>& apps) { |
(...skipping 23 matching lines...) Expand all Loading... |
296 void ArcBridgeServiceImpl::OnInstanceStopped(bool success) { | 330 void ArcBridgeServiceImpl::OnInstanceStopped(bool success) { |
297 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 331 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
298 // STOPPING is the only valid state for this function. | 332 // STOPPING is the only valid state for this function. |
299 // DCHECK on enum classes not supported. | 333 // DCHECK on enum classes not supported. |
300 DCHECK(state() == State::STOPPING); | 334 DCHECK(state() == State::STOPPING); |
301 ipc_channel_.reset(); | 335 ipc_channel_.reset(); |
302 SetState(State::STOPPED); | 336 SetState(State::STOPPED); |
303 } | 337 } |
304 | 338 |
305 } // namespace arc | 339 } // namespace arc |
OLD | NEW |