GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / device / serial / serial_service_impl.cc
blob5fc886df2eca241e338333ee682e8ae420656a41
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "device/serial/serial_service_impl.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "device/serial/serial_io_handler.h"
11 namespace device {
13 SerialServiceImpl::SerialServiceImpl(
14 scoped_refptr<SerialConnectionFactory> connection_factory)
15 : connection_factory_(connection_factory) {
18 SerialServiceImpl::SerialServiceImpl(
19 scoped_refptr<SerialConnectionFactory> connection_factory,
20 scoped_ptr<SerialDeviceEnumerator> device_enumerator)
21 : device_enumerator_(device_enumerator.Pass()),
22 connection_factory_(connection_factory) {
25 SerialServiceImpl::~SerialServiceImpl() {
28 // static
29 void SerialServiceImpl::Create(
30 scoped_refptr<base::MessageLoopProxy> io_message_loop,
31 scoped_refptr<base::MessageLoopProxy> ui_message_loop,
32 mojo::InterfaceRequest<serial::SerialService> request) {
33 mojo::BindToRequest(new SerialServiceImpl(new SerialConnectionFactory(
34 base::Bind(SerialIoHandler::Create,
35 base::MessageLoopProxy::current(),
36 ui_message_loop),
37 io_message_loop)),
38 &request);
41 // static
42 void SerialServiceImpl::CreateOnMessageLoop(
43 scoped_refptr<base::MessageLoopProxy> message_loop,
44 scoped_refptr<base::MessageLoopProxy> io_message_loop,
45 scoped_refptr<base::MessageLoopProxy> ui_message_loop,
46 mojo::InterfaceRequest<serial::SerialService> request) {
47 message_loop->PostTask(FROM_HERE,
48 base::Bind(&SerialServiceImpl::Create,
49 io_message_loop,
50 ui_message_loop,
51 base::Passed(&request)));
54 void SerialServiceImpl::GetDevices(
55 const mojo::Callback<void(mojo::Array<serial::DeviceInfoPtr>)>& callback) {
56 callback.Run(GetDeviceEnumerator()->GetDevices());
59 void SerialServiceImpl::Connect(
60 const mojo::String& path,
61 serial::ConnectionOptionsPtr options,
62 mojo::InterfaceRequest<serial::Connection> connection_request,
63 mojo::InterfaceRequest<serial::DataSink> sink,
64 mojo::InterfaceRequest<serial::DataSource> source,
65 mojo::InterfacePtr<serial::DataSourceClient> source_client) {
66 if (!IsValidPath(path))
67 return;
68 connection_factory_->CreateConnection(path, options.Pass(),
69 connection_request.Pass(), sink.Pass(),
70 source.Pass(), source_client.Pass());
73 SerialDeviceEnumerator* SerialServiceImpl::GetDeviceEnumerator() {
74 if (!device_enumerator_)
75 device_enumerator_ = SerialDeviceEnumerator::Create();
76 return device_enumerator_.get();
79 bool SerialServiceImpl::IsValidPath(const mojo::String& path) {
80 mojo::Array<serial::DeviceInfoPtr> devices(
81 GetDeviceEnumerator()->GetDevices());
82 for (size_t i = 0; i < devices.size(); i++) {
83 if (path == devices[i]->path)
84 return true;
86 return false;
89 } // namespace device