1 // Copyright 2017 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 #ifndef SERVICES_DEVICE_SERIAL_SERIAL_PORT_MANAGER_IMPL_H_
6 #define SERVICES_DEVICE_SERIAL_SERIAL_PORT_MANAGER_IMPL_H_
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "mojo/public/cpp/bindings/binding_set.h"
13 #include "services/device/public/mojom/serial.mojom.h"
16 class SingleThreadTaskRunner;
17 class UnguessableToken;
22 class SerialDeviceEnumerator;
24 // TODO(leonhsl): Merge this class with SerialDeviceEnumerator if/once
25 // SerialDeviceEnumerator is exposed only via the Device Service.
27 class SerialPortManagerImpl : public mojom::SerialPortManager {
29 SerialPortManagerImpl(
30 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
31 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
32 ~SerialPortManagerImpl() override;
34 void Bind(mojom::SerialPortManagerRequest request);
35 void SetSerialEnumeratorForTesting(
36 std::unique_ptr<SerialDeviceEnumerator> fake_enumerator);
39 // mojom::SerialPortManager methods:
40 void GetDevices(GetDevicesCallback callback) override;
41 void GetPort(const base::UnguessableToken& token,
42 mojom::SerialPortRequest request) override;
44 std::unique_ptr<SerialDeviceEnumerator> enumerator_;
46 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
47 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
49 mojo::BindingSet<SerialPortManager> bindings_;
51 DISALLOW_COPY_AND_ASSIGN(SerialPortManagerImpl);
56 #endif // SERVICES_DEVICE_SERIAL_SERIAL_PORT_MANAGER_IMPL_H_