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 void ArcBridgeServiceImpl::SocketConnect(const base::FilePath& socket_path) { | 127 void ArcBridgeServiceImpl::SocketConnect(const base::FilePath& socket_path) { |
112 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 128 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
113 if (state() != State::STOPPED) { | 129 if (state() != State::STOPPED) { |
114 VLOG(1) << "SocketConnect() called when instance is not stopped"; | 130 VLOG(1) << "SocketConnect() called when instance is not stopped"; |
115 return; | 131 return; |
116 } | 132 } |
117 SetState(State::CONNECTING); | 133 SetState(State::CONNECTING); |
118 base::PostTaskAndReplyWithResult( | 134 base::PostTaskAndReplyWithResult( |
119 file_task_runner_.get(), FROM_HERE, | 135 file_task_runner_.get(), FROM_HERE, |
120 base::Bind(&base::CreateDirectory, socket_path.DirName()), | 136 base::Bind(&base::CreateDirectory, socket_path.DirName()), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (state() != State::STARTING && state() != State::READY) { | 228 if (state() != State::STARTING && state() != State::READY) { |
213 VLOG(1) << "StopInstance() called while connecting"; | 229 VLOG(1) << "StopInstance() called while connecting"; |
214 return; | 230 return; |
215 } | 231 } |
216 if (phase == InstanceBootPhase::BRIDGE_READY) { | 232 if (phase == InstanceBootPhase::BRIDGE_READY) { |
217 SetState(State::READY); | 233 SetState(State::READY); |
218 } | 234 } |
219 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase)); | 235 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase)); |
220 } | 236 } |
221 | 237 |
| 238 void ArcBridgeServiceImpl::OnNotificationPostedFromAndroid( |
| 239 const arc::ArcNotificationData& data) { |
| 240 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
| 241 FOR_EACH_OBSERVER(NotificationObserver, notification_observer_list(), |
| 242 OnNotificationPostedFromAndroid(data)); |
| 243 } |
| 244 |
| 245 void ArcBridgeServiceImpl::OnNotificationRemovedFromAndroid( |
| 246 const std::string& key) { |
| 247 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
| 248 FOR_EACH_OBSERVER(NotificationObserver, notification_observer_list(), |
| 249 OnNotificationRemovedFromAndroid(key)); |
| 250 } |
| 251 |
222 bool ArcBridgeServiceImpl::OnMessageReceived(const IPC::Message& message) { | 252 bool ArcBridgeServiceImpl::OnMessageReceived(const IPC::Message& message) { |
223 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 253 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
224 bool handled = true; | 254 bool handled = true; |
225 | 255 |
226 IPC_BEGIN_MESSAGE_MAP(ArcBridgeServiceImpl, message) | 256 IPC_BEGIN_MESSAGE_MAP(ArcBridgeServiceImpl, message) |
227 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceBootPhase, | 257 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceBootPhase, |
228 OnInstanceBootPhase) | 258 OnInstanceBootPhase) |
| 259 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationPosted, |
| 260 OnNotificationPostedFromAndroid) |
| 261 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationRemoved, |
| 262 OnNotificationRemovedFromAndroid) |
229 IPC_MESSAGE_UNHANDLED(handled = false) | 263 IPC_MESSAGE_UNHANDLED(handled = false) |
230 IPC_END_MESSAGE_MAP() | 264 IPC_END_MESSAGE_MAP() |
231 | 265 |
232 if (!handled) | 266 if (!handled) |
233 LOG(ERROR) << "Invalid message with type = " << message.type(); | 267 LOG(ERROR) << "Invalid message with type = " << message.type(); |
234 return handled; | 268 return handled; |
235 } | 269 } |
236 | 270 |
237 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { | 271 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { |
238 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 272 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
239 if (available() == arc_available) | 273 if (available() == arc_available) |
240 return; | 274 return; |
241 SetAvailable(arc_available); | 275 SetAvailable(arc_available); |
242 PrerequisitesChanged(); | 276 PrerequisitesChanged(); |
243 } | 277 } |
244 | 278 |
245 void ArcBridgeServiceImpl::OnInstanceStopped(bool success) { | 279 void ArcBridgeServiceImpl::OnInstanceStopped(bool success) { |
246 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 280 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
247 // STOPPING is the only valid state for this function. | 281 // STOPPING is the only valid state for this function. |
248 // DCHECK on enum classes not supported. | 282 // DCHECK on enum classes not supported. |
249 DCHECK(state() == State::STOPPING); | 283 DCHECK(state() == State::STOPPING); |
250 ipc_channel_.reset(); | 284 ipc_channel_.reset(); |
251 SetState(State::STOPPED); | 285 SetState(State::STOPPED); |
252 } | 286 } |
253 | 287 |
254 } // namespace arc | 288 } // namespace arc |
OLD | NEW |