OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <utility> | 16 #include <utility> |
17 | 17 |
18 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
19 #include "base/location.h" | 19 #include "base/location.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
22 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
23 #include "base/rand_util.h" | 23 #include "base/rand_util.h" |
24 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
25 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
| 26 #include "base/task_scheduler/post_task.h" |
26 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
27 #include "base/threading/worker_pool.h" | |
28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
29 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" | 29 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" |
30 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 30 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
31 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" | 31 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
32 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" | 32 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
33 #include "device/bluetooth/dbus/fake_bluetooth_agent_service_provider.h" | 33 #include "device/bluetooth/dbus/fake_bluetooth_agent_service_provider.h" |
34 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" | 34 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
35 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" | 35 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
36 #include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h" | 36 #include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h" |
37 #include "device/bluetooth/dbus/fake_bluetooth_profile_service_provider.h" | 37 #include "device/bluetooth/dbus/fake_bluetooth_profile_service_provider.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 error_callback.Run(kNoResponseError, "failed to get socket flags"); | 508 error_callback.Run(kNoResponseError, "failed to get socket flags"); |
509 return; | 509 return; |
510 } | 510 } |
511 | 511 |
512 args |= O_NONBLOCK; | 512 args |= O_NONBLOCK; |
513 if (fcntl(fds[1], F_SETFL, args) < 0) { | 513 if (fcntl(fds[1], F_SETFL, args) < 0) { |
514 error_callback.Run(kNoResponseError, "failed to set socket non-blocking"); | 514 error_callback.Run(kNoResponseError, "failed to set socket non-blocking"); |
515 return; | 515 return; |
516 } | 516 } |
517 | 517 |
518 base::WorkerPool::GetTaskRunner(false) | 518 base::PostTaskWithTraits( |
519 ->PostTask(FROM_HERE, base::Bind(&SimulatedProfileSocket, fds[0])); | 519 FROM_HERE, base::TaskTraits() |
| 520 .WithShutdownBehavior( |
| 521 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 522 .MayBlock(), |
| 523 base::Bind(&SimulatedProfileSocket, fds[0])); |
520 | 524 |
521 base::ScopedFD fd(fds[1]); | 525 base::ScopedFD fd(fds[1]); |
522 | 526 |
523 // Post the new connection to the service provider. | 527 // Post the new connection to the service provider. |
524 BluetoothProfileServiceProvider::Delegate::Options options; | 528 BluetoothProfileServiceProvider::Delegate::Options options; |
525 | 529 |
526 profile_service_provider->NewConnection( | 530 profile_service_provider->NewConnection( |
527 object_path, std::move(fd), options, | 531 object_path, std::move(fd), options, |
528 base::Bind(&FakeBluetoothDeviceClient::ConnectionCallback, | 532 base::Bind(&FakeBluetoothDeviceClient::ConnectionCallback, |
529 base::Unretained(this), object_path, callback, | 533 base::Unretained(this), object_path, callback, |
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 } | 1810 } |
1807 properties->type.set_valid(true); | 1811 properties->type.set_valid(true); |
1808 | 1812 |
1809 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 1813 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
1810 device_list_.push_back(device_path); | 1814 device_list_.push_back(device_path); |
1811 for (auto& observer : observers_) | 1815 for (auto& observer : observers_) |
1812 observer.DeviceAdded(device_path); | 1816 observer.DeviceAdded(device_path); |
1813 } | 1817 } |
1814 | 1818 |
1815 } // namespace bluez | 1819 } // namespace bluez |
OLD | NEW |