summaryrefslogtreecommitdiffstats
path: root/device/serial
diff options
context:
space:
mode:
Diffstat (limited to 'device/serial')
-rw-r--r--device/serial/serial_io_handler.cc34
-rw-r--r--device/serial/serial_io_handler.h10
2 files changed, 38 insertions, 6 deletions
diff --git a/device/serial/serial_io_handler.cc b/device/serial/serial_io_handler.cc
index 35b41f7..a5257ed 100644
--- a/device/serial/serial_io_handler.cc
+++ b/device/serial/serial_io_handler.cc
@@ -54,12 +54,15 @@ void SerialIoHandler::Open(const std::string& port,
chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
DCHECK(client) << "Could not get permission_broker client.";
// PermissionBrokerClient should be called on the UI thread.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner =
+ base::ThreadTaskRunnerHandle::Get();
ui_thread_task_runner_->PostTask(
- FROM_HERE, base::Bind(&chromeos::PermissionBrokerClient::OpenPath,
- base::Unretained(client), port,
- base::Bind(&SerialIoHandler::OnPathOpened, this,
- file_thread_task_runner_,
- base::ThreadTaskRunnerHandle::Get())));
+ FROM_HERE,
+ base::Bind(
+ &chromeos::PermissionBrokerClient::OpenPath, base::Unretained(client),
+ port, base::Bind(&SerialIoHandler::OnPathOpened, this,
+ file_thread_task_runner_, task_runner),
+ base::Bind(&SerialIoHandler::OnPathOpenError, this, task_runner)));
#else
file_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&SerialIoHandler::StartOpen, this, port,
@@ -73,12 +76,20 @@ void SerialIoHandler::OnPathOpened(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
dbus::FileDescriptor fd) {
- DCHECK(CalledOnValidThread());
file_thread_task_runner->PostTask(
FROM_HERE, base::Bind(&SerialIoHandler::ValidateOpenPort, this,
io_thread_task_runner, base::Passed(&fd)));
}
+void SerialIoHandler::OnPathOpenError(
+ scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
+ const std::string& error_name,
+ const std::string& error_message) {
+ io_thread_task_runner->PostTask(
+ FROM_HERE, base::Bind(&SerialIoHandler::ReportPathOpenError, this,
+ error_name, error_message));
+}
+
void SerialIoHandler::ValidateOpenPort(
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
dbus::FileDescriptor fd) {
@@ -93,6 +104,17 @@ void SerialIoHandler::ValidateOpenPort(
base::Bind(&SerialIoHandler::FinishOpen, this, base::Passed(&file)));
}
+void SerialIoHandler::ReportPathOpenError(const std::string& error_name,
+ const std::string& error_message) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!open_complete_.is_null());
+ LOG(ERROR) << "Permission broker failed to open '" << port_
+ << "': " << error_name << ": " << error_message;
+ OpenCompleteCallback callback = open_complete_;
+ open_complete_.Reset();
+ callback.Run(false);
+}
+
#endif
void SerialIoHandler::MergeConnectionOptions(
diff --git a/device/serial/serial_io_handler.h b/device/serial/serial_io_handler.h
index f494743..d1a4827 100644
--- a/device/serial/serial_io_handler.h
+++ b/device/serial/serial_io_handler.h
@@ -50,10 +50,20 @@ class SerialIoHandler : public base::NonThreadSafe,
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
dbus::FileDescriptor fd);
+ // Signals that the permission broker failed to open the port.
+ void OnPathOpenError(
+ scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
+ const std::string& error_name,
+ const std::string& error_message);
+
// Validates the file descriptor provided by the permission broker.
void ValidateOpenPort(
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
dbus::FileDescriptor fd);
+
+ // Reports the open error from the permission broker.
+ void ReportPathOpenError(const std::string& error_name,
+ const std::string& error_message);
#endif // defined(OS_CHROMEOS)
// Performs an async Read operation. Behavior is undefined if this is called