OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/mock_bluetooth_adapter.h" | 5 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 error_callback); | 61 error_callback); |
62 } | 62 } |
63 | 63 |
64 void MockBluetoothAdapter::AddMockDevice( | 64 void MockBluetoothAdapter::AddMockDevice( |
65 std::unique_ptr<MockBluetoothDevice> mock_device) { | 65 std::unique_ptr<MockBluetoothDevice> mock_device) { |
66 mock_devices_.push_back(std::move(mock_device)); | 66 mock_devices_.push_back(std::move(mock_device)); |
67 } | 67 } |
68 | 68 |
69 std::unique_ptr<MockBluetoothDevice> MockBluetoothAdapter::RemoveMockDevice( | 69 std::unique_ptr<MockBluetoothDevice> MockBluetoothAdapter::RemoveMockDevice( |
70 const std::string& address) { | 70 const std::string& address) { |
71 for (auto it = mock_devices_.begin(); it != mock_devices_.end(); ++it) { | 71 for (auto& device : mock_devices_) { |
72 if ((*it)->GetAddress() != address) { | 72 if (device->GetAddress() != address) { |
73 continue; | 73 continue; |
74 } | 74 } |
75 std::unique_ptr<MockBluetoothDevice> removed_device(*it); | 75 std::unique_ptr<MockBluetoothDevice> removed_device = std::move(device); |
76 mock_devices_.weak_erase(it); | 76 auto it = std::find(mock_devices_.begin(), mock_devices_.end(), device); |
77 return removed_device; | 77 if (it != mock_devices_.end()) { |
| 78 mock_devices_.erase(it); |
| 79 return removed_device; |
| 80 } |
78 } | 81 } |
79 return nullptr; | 82 return nullptr; |
80 } | 83 } |
81 | 84 |
82 BluetoothAdapter::ConstDeviceList MockBluetoothAdapter::GetConstMockDevices() { | 85 BluetoothAdapter::ConstDeviceList MockBluetoothAdapter::GetConstMockDevices() { |
83 BluetoothAdapter::ConstDeviceList devices; | 86 BluetoothAdapter::ConstDeviceList devices; |
84 for (auto* it : mock_devices_) { | 87 for (auto& device : mock_devices_) { |
85 devices.push_back(it); | 88 devices.push_back(device.get()); |
86 } | 89 } |
87 return devices; | 90 return devices; |
88 } | 91 } |
89 | 92 |
90 BluetoothAdapter::DeviceList MockBluetoothAdapter::GetMockDevices() { | 93 BluetoothAdapter::DeviceList MockBluetoothAdapter::GetMockDevices() { |
91 BluetoothAdapter::DeviceList devices; | 94 BluetoothAdapter::DeviceList devices; |
92 for (auto* it : mock_devices_) { | 95 for (auto& device : mock_devices_) { |
93 devices.push_back(it); | 96 devices.push_back(device.get()); |
94 } | 97 } |
95 return devices; | 98 return devices; |
96 } | 99 } |
97 | 100 |
98 void MockBluetoothAdapter::RegisterAdvertisement( | 101 void MockBluetoothAdapter::RegisterAdvertisement( |
99 std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data, | 102 std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data, |
100 const CreateAdvertisementCallback& callback, | 103 const CreateAdvertisementCallback& callback, |
101 const AdvertisementErrorCallback& error_callback) { | 104 const AdvertisementErrorCallback& error_callback) { |
102 callback.Run(new MockBluetoothAdvertisement); | 105 callback.Run(new MockBluetoothAdvertisement); |
103 } | 106 } |
104 | 107 |
105 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 108 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
106 void MockBluetoothAdapter::SetAdvertisingInterval( | 109 void MockBluetoothAdapter::SetAdvertisingInterval( |
107 const base::TimeDelta& min, | 110 const base::TimeDelta& min, |
108 const base::TimeDelta& max, | 111 const base::TimeDelta& max, |
109 const base::Closure& callback, | 112 const base::Closure& callback, |
110 const AdvertisementErrorCallback& error_callback) {} | 113 const AdvertisementErrorCallback& error_callback) {} |
111 #endif | 114 #endif |
112 | 115 |
113 } // namespace device | 116 } // namespace device |
OLD | NEW |