Index: components/arc/arc_bridge_service.cc |
diff --git a/components/arc/arc_bridge_service.cc b/components/arc/arc_bridge_service.cc |
index 5466cbce238b70be787ff8ee81255ed84276fac9..f94d9089ccee050f4035aa88a2bf8d68d62bbe21 100644 |
--- a/components/arc/arc_bridge_service.cc |
+++ b/components/arc/arc_bridge_service.cc |
@@ -37,6 +37,7 @@ ArcBridgeService::ArcBridgeService( |
enabled_(false), |
state_(ArcBridgeService::STOPPED), |
weak_factory_(this) { |
+ LOG(ERROR) << "[ARC] ArcBridgeService"; |
elijahtaylor1
2015/11/02 22:30:29
is it appropriate to log to the error channel thes
denniskempin
2015/11/16 18:39:28
This was just for debugging. I removed them again.
|
ipc_thread_.StartWithOptions( |
base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
} |
@@ -55,6 +56,7 @@ bool ArcBridgeService::GetEnabledPref(PrefService* pref_service) { |
} |
void ArcBridgeService::HandleStartup() { |
+ LOG(ERROR) << "[ARC] HandleStartup"; |
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
if (!enabled_) |
return; |
@@ -62,6 +64,7 @@ void ArcBridgeService::HandleStartup() { |
} |
void ArcBridgeService::Shutdown() { |
+ LOG(ERROR) << "[ARC] Shutdown"; |
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
if (state_ == ArcBridgeService::STOPPED || |
state_ == ArcBridgeService::STOPPING) { |
@@ -69,6 +72,12 @@ void ArcBridgeService::Shutdown() { |
return; |
} |
SetState(ArcBridgeService::STOPPING); |
+ |
+ // Destroying the BridgeDevices will close their file descriptors, which will |
+ // cause the corresponding devices on the instance-side to be destroyed as |
elijahtaylor1
2015/11/02 22:30:29
how is this guaranteed? do failed reads cause the
denniskempin
2015/11/16 18:39:28
Yes, the EventHub will close devices in two condit
|
+ // well. |
+ bridge_devices_.clear(); |
+ |
ipc_channel_->Close(); |
ipc_channel_.reset(); |
base::PostTaskAndReplyWithResult( |
@@ -102,20 +111,33 @@ void ArcBridgeService::SetEnabled(bool enabled) { |
enabled_); |
} |
-bool ArcBridgeService::RegisterInputDevice( |
- const std::string& name, const std::string& device_type, |
- base::ScopedFD fd) { |
- // ipc_channel_->Send() is thread-safe, so there is no thread check. |
- if (state_ != ArcBridgeService::READY) { |
- LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; |
- return false; |
+base::ScopedFD ArcBridgeService::CreateBridgeInputDevice( |
+ const std::string& name, const std::string& device_type) { |
+ LOG(ERROR) << "[ARC] CreateBridgeInputDevice"; |
+ |
+ // Create file descriptor pair for communication |
+ int fd[2]; |
+ if (pipe(fd) < 0) { |
+ LOG(ERROR) << "Cannot create pipe: " << strerror(errno); |
elijahtaylor1
2015/11/02 22:30:29
https://code.google.com/p/chromium/codesearch#chro
denniskempin
2015/11/16 18:39:28
Done. PLOG does automatically append the error des
|
} |
- return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( |
- name, device_type, base::FileDescriptor(fd.Pass()))); |
+ |
+ // The read end is sent to the instance |
+ ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( |
+ name, device_type, base::FileDescriptor(fd[0], true))); |
+ |
+ // return the write end |
+ return base::ScopedFD(fd[1]); |
+} |
+ |
+void ArcBridgeService::SetupBridgeInputDevices() { |
+ bridge_devices_.push_back(new TouchscreenBridgeInputDevice( |
+ CreateBridgeInputDevice("ChromeOS Touchscreen", "touchscreen"))); |
} |
void ArcBridgeService::SocketConnect(const base::FilePath& socket_path) { |
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
+ LOG(ERROR) << "[ARC] SocketConnect"; |
+ |
if (state_ != ArcBridgeService::STOPPED) { |
LOG(ERROR) << "SocketConnect() called when instance is not stopped"; |
return; |
@@ -130,6 +152,7 @@ void ArcBridgeService::SocketConnect(const base::FilePath& socket_path) { |
socket_path)); |
} |
+ |
void ArcBridgeService::SocketConnectAfterEnsureParentDirectory( |
const base::FilePath& socket_path, bool directory_present) { |
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
@@ -192,6 +215,7 @@ bool ArcBridgeService::Connect(const IPC::ChannelHandle& handle, |
LOG(ERROR) << "Shutdown requested while connecting"; |
return false; |
} |
+ LOG(ERROR) << "[ARC] Connect"; |
ipc_channel_ = IPC::ChannelProxy::Create(handle, mode, this, |
ipc_thread_.task_runner().get()); |
@@ -207,6 +231,8 @@ void ArcBridgeService::OnInstanceReady() { |
LOG(ERROR) << "Shutdown requested while connecting"; |
return; |
} |
+ LOG(ERROR) << "[ARC] OnInstanceReady"; |
+ SetupBridgeInputDevices(); |
SetState(ArcBridgeService::READY); |
} |
@@ -246,6 +272,7 @@ bool ArcBridgeService::OnMessageReceived(const IPC::Message& message) { |
void ArcBridgeService::OnInstanceStarted( |
chromeos::DBusMethodCallStatus status) { |
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
+ LOG(ERROR) << "[ARC] OnInstanceStarted"; |
if (state_ != ArcBridgeService::CONNECTED) { |
LOG(ERROR) << "Shutdown requested while connecting"; |
return; |