Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2665)

Unified Diff: device/serial/serial_service_impl.cc

Issue 401563002: Add a partial Mojo serial connection interface and implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/serial/serial_service_impl.h ('k') | device/serial/serial_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/serial/serial_service_impl.cc
diff --git a/device/serial/serial_service_impl.cc b/device/serial/serial_service_impl.cc
index 1d83e23a6ad848177018e6c400e04f0c995b2af8..14a8033f4ed48e06e22c4e1f03abb6341ac9990c 100644
--- a/device/serial/serial_service_impl.cc
+++ b/device/serial/serial_service_impl.cc
@@ -6,10 +6,20 @@
#include "base/bind.h"
#include "base/location.h"
+#include "device/serial/serial_io_handler.h"
namespace device {
-SerialServiceImpl::SerialServiceImpl() {
+SerialServiceImpl::SerialServiceImpl(
+ scoped_refptr<SerialConnectionFactory> connection_factory)
+ : connection_factory_(connection_factory) {
+}
+
+SerialServiceImpl::SerialServiceImpl(
+ scoped_refptr<SerialConnectionFactory> connection_factory,
+ scoped_ptr<SerialDeviceEnumerator> device_enumerator)
+ : device_enumerator_(device_enumerator.Pass()),
+ connection_factory_(connection_factory) {
}
SerialServiceImpl::~SerialServiceImpl() {
@@ -17,28 +27,65 @@ SerialServiceImpl::~SerialServiceImpl() {
// static
void SerialServiceImpl::Create(
+ scoped_refptr<base::MessageLoopProxy> io_message_loop,
mojo::InterfaceRequest<serial::SerialService> request) {
- mojo::BindToRequest(new SerialServiceImpl(), &request);
+ mojo::BindToRequest(new SerialServiceImpl(new SerialConnectionFactory(
+ base::Bind(SerialIoHandler::Create,
+ base::MessageLoopProxy::current()),
+ io_message_loop)),
+ &request);
}
// static
void SerialServiceImpl::CreateOnMessageLoop(
scoped_refptr<base::MessageLoopProxy> message_loop,
+ scoped_refptr<base::MessageLoopProxy> io_message_loop,
mojo::InterfaceRequest<serial::SerialService> request) {
message_loop->PostTask(
FROM_HERE,
- base::Bind(&SerialServiceImpl::Create, base::Passed(&request)));
+ base::Bind(
+ &SerialServiceImpl::Create, io_message_loop, base::Passed(&request)));
}
void SerialServiceImpl::GetDevices(
const mojo::Callback<void(mojo::Array<serial::DeviceInfoPtr>)>& callback) {
- if (!device_enumerator_)
- device_enumerator_ = SerialDeviceEnumerator::Create();
- callback.Run(device_enumerator_->GetDevices());
+ callback.Run(GetDeviceEnumerator()->GetDevices());
+}
+
+void SerialServiceImpl::Connect(
+ const mojo::String& path,
+ serial::ConnectionOptionsPtr options,
+ mojo::InterfaceRequest<serial::Connection> connection_request) {
+ if (!IsValidPath(path))
+ return;
+ connection_factory_->CreateConnection(
+ path, options.Pass(), connection_request.Pass());
}
void SerialServiceImpl::OnConnectionError() {
delete this;
}
+SerialDeviceEnumerator* SerialServiceImpl::GetDeviceEnumerator() {
+ if (!device_enumerator_)
+ device_enumerator_ = SerialDeviceEnumerator::Create();
+ return device_enumerator_.get();
+}
+
+bool SerialServiceImpl::IsValidPath(const mojo::String& path) {
+ mojo::Array<serial::DeviceInfoPtr> devices(
+ GetDeviceEnumerator()->GetDevices());
+ for (size_t i = 0; i < devices.size(); i++) {
+ if (path == devices[i]->path)
+ return true;
+ }
+ return false;
+}
+
+void SerialServiceImpl::OnConnected(
+ const mojo::Callback<void(serial::ConnectionInfoPtr)>& callback,
+ serial::ConnectionInfoPtr result) {
+ callback.Run(result.Pass());
+}
+
} // namespace device
« no previous file with comments | « device/serial/serial_service_impl.h ('k') | device/serial/serial_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698