OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <utility> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/bind.h" |
| 14 #include "base/logging.h" |
| 15 #include "base/message_loop.h" |
| 16 #include "base/stl_util.h" |
| 17 #include "base/time.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 20 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| 21 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" |
| 22 #include "dbus/object_path.h" |
| 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 24 |
| 25 namespace { |
| 26 |
| 27 // Default interval between simulated events. |
| 28 const int kSimulationIntervalMs = 750; |
| 29 |
| 30 } |
| 31 |
| 32 namespace chromeos { |
| 33 |
| 34 const dbus::ObjectPath FakeBluetoothDeviceClient::kPairedDevicePath( |
| 35 "/fake/hci0/dev0"); |
| 36 const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] = |
| 37 "00:11:22:33:44:55"; |
| 38 const char FakeBluetoothDeviceClient::kPairedDeviceName[] = |
| 39 "Fake Device"; |
| 40 const uint32 FakeBluetoothDeviceClient::kPairedDeviceClass = 0x000104; |
| 41 |
| 42 const dbus::ObjectPath FakeBluetoothDeviceClient::kAppleMousePath( |
| 43 "/fake/hci0/dev1"); |
| 44 const char FakeBluetoothDeviceClient::kAppleMouseAddress[] = |
| 45 "28:CF:DA:00:00:00"; |
| 46 const char FakeBluetoothDeviceClient::kAppleMouseName[] = |
| 47 "Apple Magic Mouse"; |
| 48 const uint32 FakeBluetoothDeviceClient::kAppleMouseClass = 0x002580; |
| 49 |
| 50 const dbus::ObjectPath FakeBluetoothDeviceClient::kAppleKeyboardPath( |
| 51 "/fake/hci0/dev2"); |
| 52 const char FakeBluetoothDeviceClient::kAppleKeyboardAddress[] = |
| 53 "28:37:37:00:00:00"; |
| 54 const char FakeBluetoothDeviceClient::kAppleKeyboardName[] = |
| 55 "Apple Wireless Keyboard"; |
| 56 const uint32 FakeBluetoothDeviceClient::kAppleKeyboardClass = 0x002540; |
| 57 |
| 58 const dbus::ObjectPath FakeBluetoothDeviceClient::kVanishingDevicePath( |
| 59 "/fake/hci0/dev3"); |
| 60 const char FakeBluetoothDeviceClient::kVanishingDeviceAddress[] = |
| 61 "01:02:03:04:05:06"; |
| 62 const char FakeBluetoothDeviceClient::kVanishingDeviceName[] = |
| 63 "Vanishing Device"; |
| 64 const uint32 FakeBluetoothDeviceClient::kVanishingDeviceClass = 0x000104; |
| 65 |
| 66 const dbus::ObjectPath FakeBluetoothDeviceClient::kMicrosoftMousePath( |
| 67 "/fake/hci0/dev4"); |
| 68 const char FakeBluetoothDeviceClient::kMicrosoftMouseAddress[] = |
| 69 "7C:ED:8D:00:00:00"; |
| 70 const char FakeBluetoothDeviceClient::kMicrosoftMouseName[] = |
| 71 "Microsoft Mouse"; |
| 72 const uint32 FakeBluetoothDeviceClient::kMicrosoftMouseClass = 0x002540; |
| 73 |
| 74 const dbus::ObjectPath FakeBluetoothDeviceClient::kMotorolaKeyboardPath( |
| 75 "/fake/hci0/dev5"); |
| 76 const char FakeBluetoothDeviceClient::kMotorolaKeyboardAddress[] = |
| 77 "00:0F:F6:00:00:00"; |
| 78 const char FakeBluetoothDeviceClient::kMotorolaKeyboardName[] = |
| 79 "Motorola Keyboard"; |
| 80 const uint32 FakeBluetoothDeviceClient::kMotorolaKeyboardClass = 0x002580; |
| 81 |
| 82 const dbus::ObjectPath FakeBluetoothDeviceClient::kPhonePath( |
| 83 "/fake/hci0/dev6"); |
| 84 const char FakeBluetoothDeviceClient::kPhoneAddress[] = |
| 85 "20:7D:74:00:00:00"; |
| 86 const char FakeBluetoothDeviceClient::kPhoneName[] = |
| 87 "Phone"; |
| 88 const uint32 FakeBluetoothDeviceClient::kPhoneClass = 0x7a020c; |
| 89 |
| 90 FakeBluetoothDeviceClient::Properties::Properties( |
| 91 const PropertyChangedCallback& callback) |
| 92 : ExperimentalBluetoothDeviceClient::Properties( |
| 93 NULL, |
| 94 bluetooth_device::kExperimentalBluetoothDeviceInterface, |
| 95 callback) { |
| 96 } |
| 97 |
| 98 FakeBluetoothDeviceClient::Properties::~Properties() { |
| 99 } |
| 100 |
| 101 void FakeBluetoothDeviceClient::Properties::Get( |
| 102 dbus::PropertyBase* property, |
| 103 dbus::PropertySet::GetCallback callback) { |
| 104 VLOG(1) << "Get " << property->name(); |
| 105 callback.Run(false); |
| 106 } |
| 107 |
| 108 void FakeBluetoothDeviceClient::Properties::GetAll() { |
| 109 VLOG(1) << "GetAll"; |
| 110 } |
| 111 |
| 112 void FakeBluetoothDeviceClient::Properties::Set( |
| 113 dbus::PropertyBase *property, |
| 114 dbus::PropertySet::SetCallback callback) { |
| 115 VLOG(1) << "Set " << property->name(); |
| 116 if (property->name() == trusted.name()) { |
| 117 callback.Run(true); |
| 118 property->ReplaceValueWithSetValue(); |
| 119 NotifyPropertyChanged(property->name()); |
| 120 } else { |
| 121 callback.Run(false); |
| 122 } |
| 123 } |
| 124 |
| 125 |
| 126 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() |
| 127 : simulation_interval_ms_(kSimulationIntervalMs), |
| 128 discovery_simulation_step_(0) { |
| 129 Properties* properties = new Properties(base::Bind( |
| 130 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 131 base::Unretained(this), |
| 132 kPairedDevicePath)); |
| 133 properties->address.ReplaceValue(kPairedDeviceAddress); |
| 134 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); |
| 135 properties->name.ReplaceValue("Fake Device (Name)"); |
| 136 properties->alias.ReplaceValue(kPairedDeviceName); |
| 137 properties->paired.ReplaceValue(true); |
| 138 properties->trusted.ReplaceValue(true); |
| 139 properties->adapter.ReplaceValue(FakeBluetoothAdapterClient::kAdapterPath); |
| 140 |
| 141 std::vector<std::string> uuids; |
| 142 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); |
| 143 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); |
| 144 properties->uuids.ReplaceValue(uuids); |
| 145 |
| 146 properties_map_[kPairedDevicePath] = properties; |
| 147 device_list_.push_back(kPairedDevicePath); |
| 148 } |
| 149 |
| 150 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() { |
| 151 // Clean up Properties structures |
| 152 STLDeleteValues(&properties_map_); |
| 153 } |
| 154 |
| 155 void FakeBluetoothDeviceClient::AddObserver(Observer* observer) { |
| 156 observers_.AddObserver(observer); |
| 157 } |
| 158 |
| 159 void FakeBluetoothDeviceClient::RemoveObserver(Observer* observer) { |
| 160 observers_.RemoveObserver(observer); |
| 161 } |
| 162 |
| 163 std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter( |
| 164 const dbus::ObjectPath& adapter_path) { |
| 165 if (adapter_path == FakeBluetoothAdapterClient::kAdapterPath) |
| 166 return device_list_; |
| 167 else |
| 168 return std::vector<dbus::ObjectPath>(); |
| 169 } |
| 170 |
| 171 FakeBluetoothDeviceClient::Properties* |
| 172 FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) { |
| 173 PropertiesMap::iterator iter = properties_map_.find(object_path); |
| 174 if (iter != properties_map_.end()) |
| 175 return iter->second; |
| 176 return NULL; |
| 177 } |
| 178 |
| 179 void FakeBluetoothDeviceClient::Connect( |
| 180 const dbus::ObjectPath& object_path, |
| 181 const base::Closure& callback, |
| 182 const ErrorCallback& error_callback) { |
| 183 VLOG(1) << "Connect: " << object_path.value(); |
| 184 Properties* properties = GetProperties(object_path); |
| 185 |
| 186 if (properties->connected.value() == true) { |
| 187 // Already connected. |
| 188 callback.Run(); |
| 189 return; |
| 190 } |
| 191 |
| 192 if (properties->paired.value() != true && |
| 193 object_path != kMicrosoftMousePath) { |
| 194 // Must be paired. |
| 195 error_callback.Run(bluetooth_adapter::kErrorFailed, "Not paired"); |
| 196 return; |
| 197 } |
| 198 |
| 199 // The device can be connected. |
| 200 properties->connected.ReplaceValue(true); |
| 201 |
| 202 callback.Run(); |
| 203 properties->NotifyPropertyChanged(properties->connected.name()); |
| 204 } |
| 205 |
| 206 void FakeBluetoothDeviceClient::Disconnect( |
| 207 const dbus::ObjectPath& object_path, |
| 208 const base::Closure& callback, |
| 209 const ErrorCallback& error_callback) { |
| 210 VLOG(1) << "Disconnect: " << object_path.value(); |
| 211 error_callback.Run(kNoResponseError, ""); |
| 212 } |
| 213 |
| 214 void FakeBluetoothDeviceClient::ConnectProfile( |
| 215 const dbus::ObjectPath& object_path, |
| 216 const std::string& uuid, |
| 217 const base::Closure& callback, |
| 218 const ErrorCallback& error_callback) { |
| 219 VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; |
| 220 error_callback.Run(kNoResponseError, ""); |
| 221 } |
| 222 |
| 223 void FakeBluetoothDeviceClient::DisconnectProfile( |
| 224 const dbus::ObjectPath& object_path, |
| 225 const std::string& uuid, |
| 226 const base::Closure& callback, |
| 227 const ErrorCallback& error_callback) { |
| 228 VLOG(1) << "DisconnectProfile: " << object_path.value() << " " << uuid; |
| 229 error_callback.Run(kNoResponseError, ""); |
| 230 } |
| 231 |
| 232 void FakeBluetoothDeviceClient::Pair( |
| 233 const dbus::ObjectPath& object_path, |
| 234 const base::Closure& callback, |
| 235 const ErrorCallback& error_callback) { |
| 236 VLOG(1) << "Pair: " << object_path.value(); |
| 237 Properties* properties = GetProperties(object_path); |
| 238 |
| 239 if (properties->paired.value() == true) { |
| 240 // Already paired. |
| 241 callback.Run(); |
| 242 return; |
| 243 } |
| 244 |
| 245 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = |
| 246 static_cast<FakeBluetoothAgentManagerClient*>( |
| 247 DBusThreadManager::Get()-> |
| 248 GetExperimentalBluetoothAgentManagerClient()); |
| 249 FakeBluetoothAgentServiceProvider* agent_service_provider = |
| 250 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
| 251 if (agent_service_provider == NULL) { |
| 252 error_callback.Run(kNoResponseError, "Missing agent"); |
| 253 return; |
| 254 } |
| 255 |
| 256 if (object_path == kAppleMousePath) { |
| 257 // No need to call anything on the pairing delegate, just wait 3 times |
| 258 // the interval before acting as if the other end accepted it. |
| 259 MessageLoop::current()->PostDelayedTask( |
| 260 FROM_HERE, |
| 261 base::Bind(&FakeBluetoothDeviceClient::CompletePairing, |
| 262 base::Unretained(this), |
| 263 object_path, callback, error_callback), |
| 264 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| 265 |
| 266 } else if (object_path == kAppleKeyboardPath) { |
| 267 // Display a Pincode, and wait 7 times the interval before acting as |
| 268 // if the other end accepted it. |
| 269 agent_service_provider->DisplayPinCode(object_path, "123456"); |
| 270 |
| 271 MessageLoop::current()->PostDelayedTask( |
| 272 FROM_HERE, |
| 273 base::Bind(&FakeBluetoothDeviceClient::CompletePairing, |
| 274 base::Unretained(this), |
| 275 object_path, callback, error_callback), |
| 276 base::TimeDelta::FromMilliseconds(7 * simulation_interval_ms_)); |
| 277 |
| 278 } else if (object_path == kMotorolaKeyboardPath) { |
| 279 // Request a Pincode. |
| 280 agent_service_provider->RequestPinCode( |
| 281 object_path, |
| 282 base::Bind(&FakeBluetoothDeviceClient::PinCodeCallback, |
| 283 base::Unretained(this), |
| 284 object_path, |
| 285 callback, |
| 286 error_callback)); |
| 287 |
| 288 } else if (object_path == kPhonePath) { |
| 289 // Request confirmation of a Passkey. |
| 290 agent_service_provider->RequestConfirmation( |
| 291 object_path, 123456, |
| 292 base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, |
| 293 base::Unretained(this), |
| 294 object_path, |
| 295 callback, |
| 296 error_callback)); |
| 297 |
| 298 } else { |
| 299 error_callback.Run(kNoResponseError, "No pairing fake"); |
| 300 } |
| 301 |
| 302 // TODO(keybuk): no example of |
| 303 // RequestPasskey |
| 304 // DisplayPasskey |
| 305 |
| 306 } |
| 307 |
| 308 void FakeBluetoothDeviceClient::CompletePairing( |
| 309 const dbus::ObjectPath& object_path, |
| 310 const base::Closure& callback, |
| 311 const ErrorCallback& error_callback) { |
| 312 VLOG(1) << "CompletePairing: " << object_path.value(); |
| 313 Properties* properties = GetProperties(object_path); |
| 314 |
| 315 properties->paired.ReplaceValue(true); |
| 316 |
| 317 callback.Run(); |
| 318 properties->NotifyPropertyChanged(properties->paired.name()); |
| 319 } |
| 320 |
| 321 void FakeBluetoothDeviceClient::PinCodeCallback( |
| 322 const dbus::ObjectPath& object_path, |
| 323 const base::Closure& callback, |
| 324 const ErrorCallback& error_callback, |
| 325 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, |
| 326 const std::string& pincode) { |
| 327 VLOG(1) << "PinCodeCallback: " << object_path.value(); |
| 328 |
| 329 if (status == ExperimentalBluetoothAgentServiceProvider::Delegate::SUCCESS) { |
| 330 MessageLoop::current()->PostDelayedTask( |
| 331 FROM_HERE, |
| 332 base::Bind(&FakeBluetoothDeviceClient::CompletePairing, |
| 333 base::Unretained(this), |
| 334 object_path, callback, error_callback), |
| 335 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| 336 } |
| 337 } |
| 338 |
| 339 void FakeBluetoothDeviceClient::ConfirmationCallback( |
| 340 const dbus::ObjectPath& object_path, |
| 341 const base::Closure& callback, |
| 342 const ErrorCallback& error_callback, |
| 343 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status) { |
| 344 VLOG(1) << "ConfirmationCallback: " << object_path.value(); |
| 345 |
| 346 if (status == ExperimentalBluetoothAgentServiceProvider::Delegate::SUCCESS) { |
| 347 MessageLoop::current()->PostDelayedTask( |
| 348 FROM_HERE, |
| 349 base::Bind(&FakeBluetoothDeviceClient::CompletePairing, |
| 350 base::Unretained(this), |
| 351 object_path, callback, error_callback), |
| 352 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| 353 } |
| 354 } |
| 355 |
| 356 |
| 357 void FakeBluetoothDeviceClient::CancelPairing( |
| 358 const dbus::ObjectPath& object_path, |
| 359 const base::Closure& callback, |
| 360 const ErrorCallback& error_callback) { |
| 361 VLOG(1) << "CancelPairing: " << object_path.value(); |
| 362 error_callback.Run(kNoResponseError, ""); |
| 363 } |
| 364 |
| 365 |
| 366 void FakeBluetoothDeviceClient::BeginDiscoverySimulation( |
| 367 const dbus::ObjectPath& adapter_path) { |
| 368 VLOG(1) << "starting discovery simulation"; |
| 369 |
| 370 discovery_simulation_step_ = 1; |
| 371 |
| 372 MessageLoop::current()->PostDelayedTask( |
| 373 FROM_HERE, |
| 374 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, |
| 375 base::Unretained(this)), |
| 376 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| 377 } |
| 378 |
| 379 void FakeBluetoothDeviceClient::EndDiscoverySimulation( |
| 380 const dbus::ObjectPath& adapter_path) { |
| 381 VLOG(1) << "stopping discovery simulation"; |
| 382 discovery_simulation_step_ = 0; |
| 383 } |
| 384 |
| 385 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { |
| 386 simulation_interval_ms_ = interval_ms; |
| 387 } |
| 388 |
| 389 void FakeBluetoothDeviceClient::RemoveDevice( |
| 390 const dbus::ObjectPath& adapter_path, |
| 391 const dbus::ObjectPath& device_path) { |
| 392 std::vector<dbus::ObjectPath>::iterator listiter = |
| 393 std::find(device_list_.begin(), device_list_.end(), device_path); |
| 394 if (listiter == device_list_.end()) |
| 395 return; |
| 396 |
| 397 PropertiesMap::iterator iter = properties_map_.find(device_path); |
| 398 Properties* properties = iter->second; |
| 399 |
| 400 VLOG(1) << "removing device: " << properties->alias.value(); |
| 401 device_list_.erase(listiter); |
| 402 |
| 403 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 404 DeviceRemoved(device_path)); |
| 405 |
| 406 delete properties; |
| 407 properties_map_.erase(iter); |
| 408 } |
| 409 |
| 410 void FakeBluetoothDeviceClient::OnPropertyChanged( |
| 411 const dbus::ObjectPath& object_path, |
| 412 const std::string& property_name) { |
| 413 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 414 DevicePropertyChanged(object_path, property_name)); |
| 415 } |
| 416 |
| 417 void FakeBluetoothDeviceClient::DiscoverySimulationTimer() { |
| 418 if (!discovery_simulation_step_) |
| 419 return; |
| 420 |
| 421 // Timer fires every .75s, the numbers below are arbitrary to give a feel |
| 422 // for a discovery process. |
| 423 VLOG(1) << "discovery simulation, step " << discovery_simulation_step_; |
| 424 if (discovery_simulation_step_ == 2) { |
| 425 if (std::find(device_list_.begin(), device_list_.end(), |
| 426 kAppleMousePath) == device_list_.end()) { |
| 427 Properties* properties = new Properties(base::Bind( |
| 428 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 429 base::Unretained(this), |
| 430 kAppleMousePath)); |
| 431 properties->address.ReplaceValue(kAppleMouseAddress); |
| 432 properties->bluetooth_class.ReplaceValue(kAppleMouseClass); |
| 433 properties->name.ReplaceValue("Fake Apple Magic Mouse"); |
| 434 properties->alias.ReplaceValue(kAppleMouseName); |
| 435 properties->adapter.ReplaceValue( |
| 436 FakeBluetoothAdapterClient::kAdapterPath); |
| 437 |
| 438 properties_map_[kAppleMousePath] = properties; |
| 439 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 440 DeviceAdded(kAppleMousePath)); |
| 441 } |
| 442 |
| 443 } else if (discovery_simulation_step_ == 4) { |
| 444 if (std::find(device_list_.begin(), device_list_.end(), |
| 445 kAppleKeyboardPath) == device_list_.end()) { |
| 446 Properties *properties = new Properties(base::Bind( |
| 447 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 448 base::Unretained(this), |
| 449 kAppleKeyboardPath)); |
| 450 properties->address.ReplaceValue(kAppleKeyboardAddress); |
| 451 properties->bluetooth_class.ReplaceValue(kAppleKeyboardClass); |
| 452 properties->name.ReplaceValue("Fake Apple Wireless Keyboard"); |
| 453 properties->alias.ReplaceValue(kAppleKeyboardName); |
| 454 properties->adapter.ReplaceValue( |
| 455 FakeBluetoothAdapterClient::kAdapterPath); |
| 456 |
| 457 properties_map_[kAppleKeyboardPath] = properties; |
| 458 device_list_.push_back(kAppleKeyboardPath); |
| 459 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 460 DeviceAdded(kAppleKeyboardPath)); |
| 461 } |
| 462 |
| 463 if (std::find(device_list_.begin(), device_list_.end(), |
| 464 kVanishingDevicePath) == device_list_.end()) { |
| 465 Properties* properties = new Properties(base::Bind( |
| 466 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 467 base::Unretained(this), |
| 468 kVanishingDevicePath)); |
| 469 properties->address.ReplaceValue(kVanishingDeviceAddress); |
| 470 properties->bluetooth_class.ReplaceValue(kVanishingDeviceClass); |
| 471 properties->name.ReplaceValue("Fake Vanishing Device"); |
| 472 properties->alias.ReplaceValue(kVanishingDeviceName); |
| 473 properties->adapter.ReplaceValue( |
| 474 FakeBluetoothAdapterClient::kAdapterPath); |
| 475 |
| 476 properties_map_[kVanishingDevicePath] = properties; |
| 477 device_list_.push_back(kVanishingDevicePath); |
| 478 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 479 DeviceAdded(kVanishingDevicePath)); |
| 480 } |
| 481 |
| 482 } else if (discovery_simulation_step_ == 7) { |
| 483 if (std::find(device_list_.begin(), device_list_.end(), |
| 484 kMicrosoftMousePath) == device_list_.end()) { |
| 485 Properties* properties = new Properties(base::Bind( |
| 486 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 487 base::Unretained(this), |
| 488 kMicrosoftMousePath)); |
| 489 properties->address.ReplaceValue(kMicrosoftMouseAddress); |
| 490 properties->bluetooth_class.ReplaceValue(kMicrosoftMouseClass); |
| 491 properties->name.ReplaceValue("Fake Microsoft Mouse"); |
| 492 properties->alias.ReplaceValue(kMicrosoftMouseName); |
| 493 properties->adapter.ReplaceValue( |
| 494 FakeBluetoothAdapterClient::kAdapterPath); |
| 495 |
| 496 properties_map_[kMicrosoftMousePath] = properties; |
| 497 device_list_.push_back(kMicrosoftMousePath); |
| 498 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 499 DeviceAdded(kMicrosoftMousePath)); |
| 500 } |
| 501 |
| 502 } else if (discovery_simulation_step_ == 8) { |
| 503 if (std::find(device_list_.begin(), device_list_.end(), |
| 504 kMotorolaKeyboardPath) == device_list_.end()) { |
| 505 Properties* properties = new Properties(base::Bind( |
| 506 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 507 base::Unretained(this), |
| 508 kMotorolaKeyboardPath)); |
| 509 properties->address.ReplaceValue(kMotorolaKeyboardAddress); |
| 510 properties->bluetooth_class.ReplaceValue(kMotorolaKeyboardClass); |
| 511 properties->name.ReplaceValue("Fake Motorola Keyboard"); |
| 512 properties->alias.ReplaceValue(kMotorolaKeyboardName); |
| 513 properties->adapter.ReplaceValue( |
| 514 FakeBluetoothAdapterClient::kAdapterPath); |
| 515 |
| 516 properties_map_[kMotorolaKeyboardPath] = properties; |
| 517 device_list_.push_back(kMotorolaKeyboardPath); |
| 518 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 519 DeviceAdded(kMotorolaKeyboardPath)); |
| 520 } |
| 521 |
| 522 } else if (discovery_simulation_step_ == 10) { |
| 523 if (std::find(device_list_.begin(), device_list_.end(), |
| 524 kPhonePath) == device_list_.end()) { |
| 525 Properties* properties = new Properties(base::Bind( |
| 526 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 527 base::Unretained(this), |
| 528 kPhonePath)); |
| 529 properties->address.ReplaceValue(kPhoneAddress); |
| 530 properties->bluetooth_class.ReplaceValue(kPhoneClass); |
| 531 properties->name.ReplaceValue("Fake Phone"); |
| 532 properties->alias.ReplaceValue(kPhoneName); |
| 533 properties->adapter.ReplaceValue( |
| 534 FakeBluetoothAdapterClient::kAdapterPath); |
| 535 |
| 536 properties_map_[kPhonePath] = properties; |
| 537 device_list_.push_back(kPhonePath); |
| 538 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 539 DeviceAdded(kPhonePath)); |
| 540 } |
| 541 |
| 542 } else if (discovery_simulation_step_ == 13) { |
| 543 RemoveDevice(FakeBluetoothAdapterClient::kAdapterPath, |
| 544 kVanishingDevicePath); |
| 545 |
| 546 } else if (discovery_simulation_step_ == 14) { |
| 547 return; |
| 548 |
| 549 } |
| 550 |
| 551 ++discovery_simulation_step_; |
| 552 MessageLoop::current()->PostDelayedTask( |
| 553 FROM_HERE, |
| 554 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, |
| 555 base::Unretained(this)), |
| 556 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| 557 } |
| 558 |
| 559 } // namespace chromeos |
OLD | NEW |