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.h" | 5 #include "components/arc/arc_bridge_service.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 base::ScopedFD fd) { | 127 base::ScopedFD fd) { |
128 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread()); | 128 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread()); |
129 if (state_ != State::READY) { | 129 if (state_ != State::READY) { |
130 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; | 130 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; |
131 return false; | 131 return false; |
132 } | 132 } |
133 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( | 133 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( |
134 name, device_type, base::FileDescriptor(fd.Pass()))); | 134 name, device_type, base::FileDescriptor(fd.Pass()))); |
135 } | 135 } |
136 | 136 |
137 bool ArcBridgeService::NotifyNotificationEvent(const std::string& key, | |
138 NotificationEvent event) { | |
139 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread()); | |
140 if (state_ != State::READY) { | |
141 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; | |
142 return false; | |
143 } | |
144 if (key.empty()) { | |
145 LOG(ERROR) << "NotifyNotificationEvent failed: Wrong parameter"; | |
146 return false; | |
147 } | |
148 return ipc_channel_->Send( | |
149 new ArcInstanceMsg_NotifyNotificationEvent(key, event)); | |
150 } | |
151 | |
137 void ArcBridgeService::SocketConnect(const base::FilePath& socket_path) { | 152 void ArcBridgeService::SocketConnect(const base::FilePath& socket_path) { |
138 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 153 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
139 if (state_ != State::STOPPED) { | 154 if (state_ != State::STOPPED) { |
140 VLOG(1) << "SocketConnect() called when instance is not stopped"; | 155 VLOG(1) << "SocketConnect() called when instance is not stopped"; |
141 return; | 156 return; |
142 } | 157 } |
143 SetState(State::CONNECTING); | 158 SetState(State::CONNECTING); |
144 base::PostTaskAndReplyWithResult( | 159 base::PostTaskAndReplyWithResult( |
145 file_task_runner_.get(), FROM_HERE, | 160 file_task_runner_.get(), FROM_HERE, |
146 base::Bind(&base::CreateDirectory, socket_path.DirName()), | 161 base::Bind(&base::CreateDirectory, socket_path.DirName()), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 | 248 |
234 void ArcBridgeService::OnInstanceReady() { | 249 void ArcBridgeService::OnInstanceReady() { |
235 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 250 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
236 if (state_ != State::STARTING) { | 251 if (state_ != State::STARTING) { |
237 VLOG(1) << "StopInstance() called while connecting"; | 252 VLOG(1) << "StopInstance() called while connecting"; |
238 return; | 253 return; |
239 } | 254 } |
240 SetState(State::READY); | 255 SetState(State::READY); |
241 } | 256 } |
242 | 257 |
258 void ArcBridgeService::OnNotificationPosted( | |
259 const arc::ArcNotificationData& data) { | |
260 FOR_EACH_OBSERVER(Observer, observer_list_, | |
khmel1
2015/11/25 00:30:10
DCHECK(origin_task_runner_->RunsTasksOnCurrentThre
yoshiki
2015/11/25 09:40:35
Done.
| |
261 OnNotificationPostedFromAndroid(data)); | |
262 } | |
263 | |
264 void ArcBridgeService::OnNotificationRemoved(const std::string& key) { | |
265 FOR_EACH_OBSERVER(Observer, observer_list_, | |
266 OnNotificationRemovedFromAndroid(key)); | |
267 } | |
268 | |
243 void ArcBridgeService::SetState(State state) { | 269 void ArcBridgeService::SetState(State state) { |
244 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 270 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
245 // DCHECK on enum classes not supported. | 271 // DCHECK on enum classes not supported. |
246 DCHECK(state_ != state); | 272 DCHECK(state_ != state); |
247 state_ = state; | 273 state_ = state; |
248 FOR_EACH_OBSERVER(Observer, observer_list_, OnStateChanged(state_)); | 274 FOR_EACH_OBSERVER(Observer, observer_list_, OnStateChanged(state_)); |
249 } | 275 } |
250 | 276 |
251 bool ArcBridgeService::OnMessageReceived(const IPC::Message& message) { | 277 bool ArcBridgeService::OnMessageReceived(const IPC::Message& message) { |
252 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 278 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
253 bool handled = true; | 279 bool handled = true; |
254 | 280 |
255 IPC_BEGIN_MESSAGE_MAP(ArcBridgeService, message) | 281 IPC_BEGIN_MESSAGE_MAP(ArcBridgeService, message) |
256 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceReady, OnInstanceReady) | 282 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceReady, OnInstanceReady) |
283 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationPosted, | |
284 OnNotificationPosted) | |
285 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationRemoved, | |
286 OnNotificationRemoved) | |
257 IPC_MESSAGE_UNHANDLED(handled = false) | 287 IPC_MESSAGE_UNHANDLED(handled = false) |
258 IPC_END_MESSAGE_MAP() | 288 IPC_END_MESSAGE_MAP() |
259 | 289 |
260 if (!handled) | 290 if (!handled) |
261 LOG(ERROR) << "Invalid message with type = " << message.type(); | 291 LOG(ERROR) << "Invalid message with type = " << message.type(); |
262 return handled; | 292 return handled; |
263 } | 293 } |
264 | 294 |
265 void ArcBridgeService::OnArcAvailable(bool available) { | 295 void ArcBridgeService::OnArcAvailable(bool available) { |
266 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 296 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
267 if (available_ == available) | 297 if (available_ == available) |
268 return; | 298 return; |
269 available_ = available; | 299 available_ = available; |
270 FOR_EACH_OBSERVER(Observer, observer_list_, OnAvailableChanged(available_)); | 300 FOR_EACH_OBSERVER(Observer, observer_list_, OnAvailableChanged(available_)); |
271 PrerequisitesChanged(); | 301 PrerequisitesChanged(); |
272 } | 302 } |
273 | 303 |
274 void ArcBridgeService::OnInstanceStopped(bool success) { | 304 void ArcBridgeService::OnInstanceStopped(bool success) { |
275 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 305 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
276 // STOPPING is the only valid state for this function. | 306 // STOPPING is the only valid state for this function. |
277 // DCHECK on enum classes not supported. | 307 // DCHECK on enum classes not supported. |
278 DCHECK(state_ == State::STOPPING); | 308 DCHECK(state_ == State::STOPPING); |
279 ipc_channel_.reset(); | 309 ipc_channel_.reset(); |
280 SetState(State::STOPPED); | 310 SetState(State::STOPPED); |
281 } | 311 } |
282 | 312 |
283 } // namespace arc | 313 } // namespace arc |
OLD | NEW |