[M73 Dev][Tizen] Fix linker errors
[platform/framework/web/chromium-efl.git] / services / device / serial / serial_port_manager_impl.cc
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.
4
5 #include "services/device/serial/serial_port_manager_impl.h"
6
7 #include <string>
8 #include <utility>
9
10 #include "base/sequenced_task_runner.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h"
12 #include "services/device/serial/serial_device_enumerator.h"
13 #include "services/device/serial/serial_port_impl.h"
14
15 namespace device {
16
17 SerialPortManagerImpl::SerialPortManagerImpl(
18     scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
19     scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
20     : io_task_runner_(std::move(io_task_runner)),
21       ui_task_runner_(std::move(ui_task_runner)) {}
22
23 SerialPortManagerImpl::~SerialPortManagerImpl() = default;
24
25 void SerialPortManagerImpl::Bind(mojom::SerialPortManagerRequest request) {
26   bindings_.AddBinding(this, std::move(request));
27 }
28
29 void SerialPortManagerImpl::SetSerialEnumeratorForTesting(
30     std::unique_ptr<SerialDeviceEnumerator> fake_enumerator) {
31   DCHECK(fake_enumerator);
32   enumerator_ = std::move(fake_enumerator);
33 }
34
35 void SerialPortManagerImpl::GetDevices(GetDevicesCallback callback) {
36   if (!enumerator_)
37     enumerator_ = SerialDeviceEnumerator::Create();
38   std::move(callback).Run(enumerator_->GetDevices());
39 }
40
41 void SerialPortManagerImpl::GetPort(const base::UnguessableToken& token,
42                                     mojom::SerialPortRequest request) {
43   if (!enumerator_)
44     enumerator_ = SerialDeviceEnumerator::Create();
45   base::Optional<base::FilePath> path = enumerator_->GetPathFromToken(token);
46   if (path) {
47     io_task_runner_->PostTask(
48         FROM_HERE, base::BindOnce(&SerialPortImpl::Create, *path,
49                                   std::move(request), ui_task_runner_));
50   }
51 }
52
53 }  // namespace device