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_adapter_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
6 | 6 |
7 #include <map> | |
8 #include <utility> | |
9 | |
10 #include "base/bind_helpers.h" | |
11 #include "base/callback_forward.h" | |
7 #include "base/location.h" | 12 #include "base/location.h" |
8 #include "base/logging.h" | 13 #include "base/logging.h" |
9 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
11 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "dbus/bus.h" | |
18 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h" | |
12 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 19 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
13 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" | 20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 22 |
16 namespace bluez { | 23 namespace bluez { |
17 | 24 |
18 namespace { | 25 namespace { |
19 | 26 |
20 // Default interval for delayed tasks. | 27 // Default interval for delayed tasks. |
21 const int kSimulationIntervalMs = 750; | 28 const int kSimulationIntervalMs = 750; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 } else { | 71 } else { |
65 callback.Run(false); | 72 callback.Run(false); |
66 } | 73 } |
67 } | 74 } |
68 | 75 |
69 FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() | 76 FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() |
70 : visible_(true), | 77 : visible_(true), |
71 second_visible_(false), | 78 second_visible_(false), |
72 discovering_count_(0), | 79 discovering_count_(0), |
73 set_discovery_filter_should_fail_(false), | 80 set_discovery_filter_should_fail_(false), |
74 simulation_interval_ms_(kSimulationIntervalMs) { | 81 simulation_interval_ms_(kSimulationIntervalMs), |
82 last_handle_(0) { | |
75 properties_.reset(new Properties(base::Bind( | 83 properties_.reset(new Properties(base::Bind( |
76 &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this)))); | 84 &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this)))); |
77 | 85 |
78 properties_->address.ReplaceValue(kAdapterAddress); | 86 properties_->address.ReplaceValue(kAdapterAddress); |
79 properties_->name.ReplaceValue("Fake Adapter (Name)"); | 87 properties_->name.ReplaceValue("Fake Adapter (Name)"); |
80 properties_->alias.ReplaceValue(kAdapterName); | 88 properties_->alias.ReplaceValue(kAdapterName); |
81 properties_->pairable.ReplaceValue(true); | 89 properties_->pairable.ReplaceValue(true); |
82 | 90 |
83 second_properties_.reset(new Properties(base::Bind( | 91 second_properties_.reset(new Properties(base::Bind( |
84 &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this)))); | 92 &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this)))); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 PostDelayedTask(base::Bind(error_callback, kNoResponseError, "")); | 227 PostDelayedTask(base::Bind(error_callback, kNoResponseError, "")); |
220 set_discovery_filter_should_fail_ = false; | 228 set_discovery_filter_should_fail_ = false; |
221 return; | 229 return; |
222 } | 230 } |
223 | 231 |
224 discovery_filter_.reset(new DiscoveryFilter()); | 232 discovery_filter_.reset(new DiscoveryFilter()); |
225 discovery_filter_->CopyFrom(discovery_filter); | 233 discovery_filter_->CopyFrom(discovery_filter); |
226 PostDelayedTask(callback); | 234 PostDelayedTask(callback); |
227 } | 235 } |
228 | 236 |
237 void FakeBluetoothAdapterClient::CreateServiceRecord( | |
238 const dbus::ObjectPath& object_path, | |
239 const bluez::BluetoothServiceRecordBlueZ& record, | |
240 const ServiceRecordCallback& callback, | |
241 const ErrorCallback& error_callback) { | |
242 last_handle_++; | |
xiyuan
2016/06/22 15:53:06
nit: ++last_handle_
rkc
2016/06/22 21:06:38
Done.
| |
243 records_.emplace(last_handle_, record); | |
244 callback.Run(last_handle_); | |
245 } | |
246 | |
247 void FakeBluetoothAdapterClient::RemoveServiceRecord( | |
248 const dbus::ObjectPath& object_path, | |
249 uint32_t handle, | |
250 const base::Closure& callback, | |
251 const ErrorCallback& error_callback) { | |
252 auto it = records_.find(handle); | |
253 if (it == records_.end()) { | |
254 error_callback.Run(bluetooth_adapter::kErrorDoesNotExist, | |
255 "Service record does not exist."); | |
256 return; | |
257 } | |
258 records_.erase(it); | |
259 callback.Run(); | |
260 } | |
261 | |
229 void FakeBluetoothAdapterClient::SetSimulationIntervalMs(int interval_ms) { | 262 void FakeBluetoothAdapterClient::SetSimulationIntervalMs(int interval_ms) { |
230 simulation_interval_ms_ = interval_ms; | 263 simulation_interval_ms_ = interval_ms; |
231 } | 264 } |
232 | 265 |
233 BluetoothAdapterClient::DiscoveryFilter* | 266 BluetoothAdapterClient::DiscoveryFilter* |
234 FakeBluetoothAdapterClient::GetDiscoveryFilter() { | 267 FakeBluetoothAdapterClient::GetDiscoveryFilter() { |
235 return discovery_filter_.get(); | 268 return discovery_filter_.get(); |
236 } | 269 } |
237 | 270 |
238 void FakeBluetoothAdapterClient::SetVisible(bool visible) { | 271 void FakeBluetoothAdapterClient::SetVisible(bool visible) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 } | 330 } |
298 | 331 |
299 void FakeBluetoothAdapterClient::PostDelayedTask( | 332 void FakeBluetoothAdapterClient::PostDelayedTask( |
300 const base::Closure& callback) { | 333 const base::Closure& callback) { |
301 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 334 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
302 FROM_HERE, callback, | 335 FROM_HERE, callback, |
303 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 336 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
304 } | 337 } |
305 | 338 |
306 } // namespace bluez | 339 } // namespace bluez |
OLD | NEW |