| 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/bluetooth_device_experimental_chromeos.h" | 5 #include "device/bluetooth/bluetooth_device_experimental_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" |
| 10 #include "base/strings/string_number_conversions.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" | 12 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" |
| 10 #include "chromeos/dbus/experimental_bluetooth_agent_manager_client.h" | 13 #include "chromeos/dbus/experimental_bluetooth_agent_manager_client.h" |
| 11 #include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" | 14 #include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" |
| 12 #include "chromeos/dbus/experimental_bluetooth_device_client.h" | 15 #include "chromeos/dbus/experimental_bluetooth_device_client.h" |
| 13 #include "chromeos/dbus/experimental_bluetooth_input_client.h" | 16 #include "chromeos/dbus/experimental_bluetooth_input_client.h" |
| 14 #include "dbus/bus.h" | 17 #include "dbus/bus.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_experimental_chromeos.h" | 18 #include "device/bluetooth/bluetooth_adapter_experimental_chromeos.h" |
| 16 #include "device/bluetooth/bluetooth_socket.h" | 19 #include "device/bluetooth/bluetooth_socket.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 21 |
| 19 using device::BluetoothDevice; | 22 using device::BluetoothDevice; |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 // The agent path is relatively meaningless since BlueZ only supports one | 26 // The agent path is relatively meaningless since BlueZ only supports one |
| 24 // at time and will fail in an attempt to register another with "Already Exists" | 27 // at time and will fail in an attempt to register another with "Already Exists" |
| 25 // (which we fail in OnRegisterAgentError with ERROR_INPROGRESS). | 28 // (which we fail in OnRegisterAgentError with ERROR_INPROGRESS). |
| 26 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; | 29 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; |
| 27 | 30 |
| 31 // Histogram enumerations for pairing methods. |
| 32 enum UMAPairingMethod { |
| 33 UMA_PAIRING_METHOD_NONE, |
| 34 UMA_PAIRING_METHOD_REQUEST_PINCODE, |
| 35 UMA_PAIRING_METHOD_REQUEST_PASSKEY, |
| 36 UMA_PAIRING_METHOD_DISPLAY_PINCODE, |
| 37 UMA_PAIRING_METHOD_DISPLAY_PASSKEY, |
| 38 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, |
| 39 // NOTE: Add new pairing methods immediately above this line. Make sure to |
| 40 // update the enum list in tools/histogram/histograms.xml accordinly. |
| 41 UMA_PAIRING_METHOD_COUNT |
| 42 }; |
| 43 |
| 44 // Histogram enumerations for pairing results. |
| 45 enum UMAPairingResult { |
| 46 UMA_PAIRING_RESULT_SUCCESS, |
| 47 UMA_PAIRING_RESULT_INPROGRESS, |
| 48 UMA_PAIRING_RESULT_FAILED, |
| 49 UMA_PAIRING_RESULT_AUTH_FAILED, |
| 50 UMA_PAIRING_RESULT_AUTH_CANCELED, |
| 51 UMA_PAIRING_RESULT_AUTH_REJECTED, |
| 52 UMA_PAIRING_RESULT_AUTH_TIMEOUT, |
| 53 UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE, |
| 54 UMA_PAIRING_RESULT_UNKNOWN_ERROR, |
| 55 // NOTE: Add new pairing results immediately above this line. Make sure to |
| 56 // update the enum list in tools/histogram/histograms.xml accordinly. |
| 57 UMA_PAIRING_RESULT_COUNT |
| 58 }; |
| 59 |
| 60 void ParseModalias(const dbus::ObjectPath& object_path, |
| 61 uint16 *vendor_id, |
| 62 uint16 *product_id, |
| 63 uint16 *device_id) { |
| 64 chromeos::ExperimentalBluetoothDeviceClient::Properties* properties = |
| 65 chromeos::DBusThreadManager::Get()-> |
| 66 GetExperimentalBluetoothDeviceClient()->GetProperties(object_path); |
| 67 DCHECK(properties); |
| 68 |
| 69 std::string modalias = properties->modalias.value(); |
| 70 if (StartsWithASCII(modalias, "usb:", false) && modalias.length() == 19) { |
| 71 // usb:vXXXXpXXXXdXXXX |
| 72 if (modalias[4] == 'v' && vendor_id != NULL) { |
| 73 uint64 component = 0; |
| 74 base::HexStringToUInt64(modalias.substr(5, 4), &component); |
| 75 *vendor_id = component; |
| 76 } |
| 77 |
| 78 if (modalias[9] == 'p' && product_id != NULL) { |
| 79 uint64 component = 0; |
| 80 base::HexStringToUInt64(modalias.substr(10, 4), &component); |
| 81 *product_id = component; |
| 82 } |
| 83 |
| 84 if (modalias[14] == 'd' && device_id != NULL) { |
| 85 uint64 component = 0; |
| 86 base::HexStringToUInt64(modalias.substr(15, 4), &component); |
| 87 *device_id = component; |
| 88 } |
| 89 } |
| 90 } |
| 91 |
| 28 } // namespace | 92 } // namespace |
| 29 | 93 |
| 30 namespace chromeos { | 94 namespace chromeos { |
| 31 | 95 |
| 32 BluetoothDeviceExperimentalChromeOS::BluetoothDeviceExperimentalChromeOS( | 96 BluetoothDeviceExperimentalChromeOS::BluetoothDeviceExperimentalChromeOS( |
| 33 BluetoothAdapterExperimentalChromeOS* adapter, | 97 BluetoothAdapterExperimentalChromeOS* adapter, |
| 34 const dbus::ObjectPath& object_path) | 98 const dbus::ObjectPath& object_path) |
| 35 : adapter_(adapter), | 99 : adapter_(adapter), |
| 36 object_path_(object_path), | 100 object_path_(object_path), |
| 37 num_connecting_calls_(0), | 101 num_connecting_calls_(0), |
| 38 pairing_delegate_(NULL), | 102 pairing_delegate_(NULL), |
| 103 pairing_delegate_used_(false), |
| 39 weak_ptr_factory_(this) { | 104 weak_ptr_factory_(this) { |
| 40 } | 105 } |
| 41 | 106 |
| 42 BluetoothDeviceExperimentalChromeOS::~BluetoothDeviceExperimentalChromeOS() { | 107 BluetoothDeviceExperimentalChromeOS::~BluetoothDeviceExperimentalChromeOS() { |
| 43 } | 108 } |
| 44 | 109 |
| 45 uint32 BluetoothDeviceExperimentalChromeOS::GetBluetoothClass() const { | 110 uint32 BluetoothDeviceExperimentalChromeOS::GetBluetoothClass() const { |
| 46 ExperimentalBluetoothDeviceClient::Properties* properties = | 111 ExperimentalBluetoothDeviceClient::Properties* properties = |
| 47 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | 112 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| 48 GetProperties(object_path_); | 113 GetProperties(object_path_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 62 | 127 |
| 63 std::string BluetoothDeviceExperimentalChromeOS::GetAddress() const { | 128 std::string BluetoothDeviceExperimentalChromeOS::GetAddress() const { |
| 64 ExperimentalBluetoothDeviceClient::Properties* properties = | 129 ExperimentalBluetoothDeviceClient::Properties* properties = |
| 65 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | 130 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| 66 GetProperties(object_path_); | 131 GetProperties(object_path_); |
| 67 DCHECK(properties); | 132 DCHECK(properties); |
| 68 | 133 |
| 69 return properties->address.value(); | 134 return properties->address.value(); |
| 70 } | 135 } |
| 71 | 136 |
| 137 uint16 BluetoothDeviceExperimentalChromeOS::GetVendorID() const { |
| 138 uint16 vendor_id = 0; |
| 139 ParseModalias(object_path_, &vendor_id, NULL, NULL); |
| 140 return vendor_id; |
| 141 } |
| 142 |
| 143 uint16 BluetoothDeviceExperimentalChromeOS::GetProductID() const { |
| 144 uint16 product_id = 0; |
| 145 ParseModalias(object_path_, NULL, &product_id, NULL); |
| 146 return product_id; |
| 147 } |
| 148 |
| 149 uint16 BluetoothDeviceExperimentalChromeOS::GetDeviceID() const { |
| 150 uint16 device_id = 0; |
| 151 ParseModalias(object_path_, NULL, NULL, &device_id); |
| 152 return device_id; |
| 153 } |
| 154 |
| 72 bool BluetoothDeviceExperimentalChromeOS::IsPaired() const { | 155 bool BluetoothDeviceExperimentalChromeOS::IsPaired() const { |
| 73 ExperimentalBluetoothDeviceClient::Properties* properties = | 156 ExperimentalBluetoothDeviceClient::Properties* properties = |
| 74 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | 157 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| 75 GetProperties(object_path_); | 158 GetProperties(object_path_); |
| 76 DCHECK(properties); | 159 DCHECK(properties); |
| 77 | 160 |
| 78 // Trusted devices are devices that don't support pairing but that the | 161 // Trusted devices are devices that don't support pairing but that the |
| 79 // user has explicitly connected; it makes no sense for UI purposes to | 162 // user has explicitly connected; it makes no sense for UI purposes to |
| 80 // treat them differently from each other. | 163 // treat them differently from each other. |
| 81 return properties->paired.value() || properties->trusted.value(); | 164 return properties->paired.value() || properties->trusted.value(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 237 |
| 155 if (IsPaired() || IsConnected() || !pairing_delegate || !IsPairable()) { | 238 if (IsPaired() || IsConnected() || !pairing_delegate || !IsPairable()) { |
| 156 // No need to pair, or unable to, skip straight to connection. | 239 // No need to pair, or unable to, skip straight to connection. |
| 157 ConnectInternal(callback, error_callback); | 240 ConnectInternal(callback, error_callback); |
| 158 } else { | 241 } else { |
| 159 // Initiate high-security connection with pairing. | 242 // Initiate high-security connection with pairing. |
| 160 DCHECK(!pairing_delegate_); | 243 DCHECK(!pairing_delegate_); |
| 161 DCHECK(agent_.get() == NULL); | 244 DCHECK(agent_.get() == NULL); |
| 162 | 245 |
| 163 pairing_delegate_ = pairing_delegate; | 246 pairing_delegate_ = pairing_delegate; |
| 247 pairing_delegate_used_ = false; |
| 164 | 248 |
| 165 // The agent path is relatively meaningless since BlueZ only supports | 249 // The agent path is relatively meaningless since BlueZ only supports |
| 166 // one per application at a time. | 250 // one per application at a time. |
| 167 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 251 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
| 168 agent_.reset(ExperimentalBluetoothAgentServiceProvider::Create( | 252 agent_.reset(ExperimentalBluetoothAgentServiceProvider::Create( |
| 169 system_bus, dbus::ObjectPath(kAgentPath), this)); | 253 system_bus, dbus::ObjectPath(kAgentPath), this)); |
| 170 DCHECK(agent_.get()); | 254 DCHECK(agent_.get()); |
| 171 | 255 |
| 172 VLOG(1) << object_path_.value() << ": Registering agent for pairing"; | 256 VLOG(1) << object_path_.value() << ": Registering agent for pairing"; |
| 173 DBusThreadManager::Get()->GetExperimentalBluetoothAgentManagerClient()-> | 257 DBusThreadManager::Get()->GetExperimentalBluetoothAgentManagerClient()-> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 UnregisterAgent(); | 387 UnregisterAgent(); |
| 304 } | 388 } |
| 305 | 389 |
| 306 void BluetoothDeviceExperimentalChromeOS::RequestPinCode( | 390 void BluetoothDeviceExperimentalChromeOS::RequestPinCode( |
| 307 const dbus::ObjectPath& device_path, | 391 const dbus::ObjectPath& device_path, |
| 308 const PinCodeCallback& callback) { | 392 const PinCodeCallback& callback) { |
| 309 DCHECK(agent_.get()); | 393 DCHECK(agent_.get()); |
| 310 DCHECK(device_path == object_path_); | 394 DCHECK(device_path == object_path_); |
| 311 VLOG(1) << object_path_.value() << ": RequestPinCode"; | 395 VLOG(1) << object_path_.value() << ": RequestPinCode"; |
| 312 | 396 |
| 397 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 398 UMA_PAIRING_METHOD_REQUEST_PINCODE, |
| 399 UMA_PAIRING_METHOD_COUNT); |
| 400 |
| 313 DCHECK(pairing_delegate_); | 401 DCHECK(pairing_delegate_); |
| 314 DCHECK(pincode_callback_.is_null()); | 402 DCHECK(pincode_callback_.is_null()); |
| 315 pincode_callback_ = callback; | 403 pincode_callback_ = callback; |
| 316 pairing_delegate_->RequestPinCode(this); | 404 pairing_delegate_->RequestPinCode(this); |
| 317 } | 405 } |
| 318 | 406 |
| 319 void BluetoothDeviceExperimentalChromeOS::DisplayPinCode( | 407 void BluetoothDeviceExperimentalChromeOS::DisplayPinCode( |
| 320 const dbus::ObjectPath& device_path, | 408 const dbus::ObjectPath& device_path, |
| 321 const std::string& pincode) { | 409 const std::string& pincode) { |
| 322 DCHECK(agent_.get()); | 410 DCHECK(agent_.get()); |
| 323 DCHECK(device_path == object_path_); | 411 DCHECK(device_path == object_path_); |
| 324 VLOG(1) << object_path_.value() << ": DisplayPinCode: " << pincode; | 412 VLOG(1) << object_path_.value() << ": DisplayPinCode: " << pincode; |
| 325 | 413 |
| 414 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 415 UMA_PAIRING_METHOD_DISPLAY_PINCODE, |
| 416 UMA_PAIRING_METHOD_COUNT); |
| 417 |
| 326 DCHECK(pairing_delegate_); | 418 DCHECK(pairing_delegate_); |
| 327 pairing_delegate_->DisplayPinCode(this, pincode); | 419 pairing_delegate_->DisplayPinCode(this, pincode); |
| 328 } | 420 } |
| 329 | 421 |
| 330 void BluetoothDeviceExperimentalChromeOS::RequestPasskey( | 422 void BluetoothDeviceExperimentalChromeOS::RequestPasskey( |
| 331 const dbus::ObjectPath& device_path, | 423 const dbus::ObjectPath& device_path, |
| 332 const PasskeyCallback& callback) { | 424 const PasskeyCallback& callback) { |
| 333 DCHECK(agent_.get()); | 425 DCHECK(agent_.get()); |
| 334 DCHECK(device_path == object_path_); | 426 DCHECK(device_path == object_path_); |
| 335 VLOG(1) << object_path_.value() << ": RequestPasskey"; | 427 VLOG(1) << object_path_.value() << ": RequestPasskey"; |
| 336 | 428 |
| 429 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 430 UMA_PAIRING_METHOD_REQUEST_PASSKEY, |
| 431 UMA_PAIRING_METHOD_COUNT); |
| 432 |
| 337 DCHECK(pairing_delegate_); | 433 DCHECK(pairing_delegate_); |
| 338 DCHECK(passkey_callback_.is_null()); | 434 DCHECK(passkey_callback_.is_null()); |
| 339 passkey_callback_ = callback; | 435 passkey_callback_ = callback; |
| 340 pairing_delegate_->RequestPasskey(this); | 436 pairing_delegate_->RequestPasskey(this); |
| 341 } | 437 } |
| 342 | 438 |
| 343 void BluetoothDeviceExperimentalChromeOS::DisplayPasskey( | 439 void BluetoothDeviceExperimentalChromeOS::DisplayPasskey( |
| 344 const dbus::ObjectPath& device_path, | 440 const dbus::ObjectPath& device_path, |
| 345 uint32 passkey, | 441 uint32 passkey, |
| 346 uint16 entered) { | 442 uint16 entered) { |
| 347 DCHECK(agent_.get()); | 443 DCHECK(agent_.get()); |
| 348 DCHECK(device_path == object_path_); | 444 DCHECK(device_path == object_path_); |
| 349 VLOG(1) << object_path_.value() << ": DisplayPasskey: " << passkey | 445 VLOG(1) << object_path_.value() << ": DisplayPasskey: " << passkey |
| 350 << " (" << entered << " entered)"; | 446 << " (" << entered << " entered)"; |
| 351 | 447 |
| 448 if (entered == 0) |
| 449 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 450 UMA_PAIRING_METHOD_DISPLAY_PASSKEY, |
| 451 UMA_PAIRING_METHOD_COUNT); |
| 452 |
| 352 DCHECK(pairing_delegate_); | 453 DCHECK(pairing_delegate_); |
| 353 if (entered == 0) | 454 if (entered == 0) |
| 354 pairing_delegate_->DisplayPasskey(this, passkey); | 455 pairing_delegate_->DisplayPasskey(this, passkey); |
| 355 pairing_delegate_->KeysEntered(this, entered); | 456 pairing_delegate_->KeysEntered(this, entered); |
| 356 } | 457 } |
| 357 | 458 |
| 358 void BluetoothDeviceExperimentalChromeOS::RequestConfirmation( | 459 void BluetoothDeviceExperimentalChromeOS::RequestConfirmation( |
| 359 const dbus::ObjectPath& device_path, | 460 const dbus::ObjectPath& device_path, |
| 360 uint32 passkey, | 461 uint32 passkey, |
| 361 const ConfirmationCallback& callback) { | 462 const ConfirmationCallback& callback) { |
| 362 DCHECK(agent_.get()); | 463 DCHECK(agent_.get()); |
| 363 DCHECK(device_path == object_path_); | 464 DCHECK(device_path == object_path_); |
| 364 VLOG(1) << object_path_.value() << ": RequestConfirmation: " << passkey; | 465 VLOG(1) << object_path_.value() << ": RequestConfirmation: " << passkey; |
| 365 | 466 |
| 467 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 468 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, |
| 469 UMA_PAIRING_METHOD_COUNT); |
| 470 |
| 366 DCHECK(pairing_delegate_); | 471 DCHECK(pairing_delegate_); |
| 367 DCHECK(confirmation_callback_.is_null()); | 472 DCHECK(confirmation_callback_.is_null()); |
| 368 confirmation_callback_ = callback; | 473 confirmation_callback_ = callback; |
| 369 pairing_delegate_->ConfirmPasskey(this, passkey); | 474 pairing_delegate_->ConfirmPasskey(this, passkey); |
| 370 } | 475 } |
| 371 | 476 |
| 372 void BluetoothDeviceExperimentalChromeOS::RequestAuthorization( | 477 void BluetoothDeviceExperimentalChromeOS::RequestAuthorization( |
| 373 const dbus::ObjectPath& device_path, | 478 const dbus::ObjectPath& device_path, |
| 374 const ConfirmationCallback& callback) { | 479 const ConfirmationCallback& callback) { |
| 375 // TODO(keybuk): implement | 480 // TODO(keybuk): implement |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 // Determine the error code from error_name. | 544 // Determine the error code from error_name. |
| 440 ConnectErrorCode error_code = ERROR_UNKNOWN; | 545 ConnectErrorCode error_code = ERROR_UNKNOWN; |
| 441 if (error_name == bluetooth_adapter::kErrorFailed) { | 546 if (error_name == bluetooth_adapter::kErrorFailed) { |
| 442 error_code = ERROR_FAILED; | 547 error_code = ERROR_FAILED; |
| 443 } else if (error_name == bluetooth_adapter::kErrorInProgress) { | 548 } else if (error_name == bluetooth_adapter::kErrorInProgress) { |
| 444 error_code = ERROR_INPROGRESS; | 549 error_code = ERROR_INPROGRESS; |
| 445 } else if (error_name == bluetooth_adapter::kErrorNotSupported) { | 550 } else if (error_name == bluetooth_adapter::kErrorNotSupported) { |
| 446 error_code = ERROR_UNSUPPORTED_DEVICE; | 551 error_code = ERROR_UNSUPPORTED_DEVICE; |
| 447 } | 552 } |
| 448 | 553 |
| 554 RecordPairingResult(false, error_code); |
| 449 error_callback.Run(error_code); | 555 error_callback.Run(error_code); |
| 450 } | 556 } |
| 451 | 557 |
| 452 void BluetoothDeviceExperimentalChromeOS::OnRegisterAgent( | 558 void BluetoothDeviceExperimentalChromeOS::OnRegisterAgent( |
| 453 const base::Closure& callback, | 559 const base::Closure& callback, |
| 454 const ConnectErrorCallback& error_callback) { | 560 const ConnectErrorCallback& error_callback) { |
| 455 VLOG(1) << object_path_.value() << ": Agent registered, now pairing"; | 561 VLOG(1) << object_path_.value() << ": Agent registered, now pairing"; |
| 456 | 562 |
| 457 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | 563 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| 458 Pair(object_path_, | 564 Pair(object_path_, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 479 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ | 585 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ |
| 480 << " still in progress"; | 586 << " still in progress"; |
| 481 | 587 |
| 482 UnregisterAgent(); | 588 UnregisterAgent(); |
| 483 | 589 |
| 484 // Determine the error code from error_name. | 590 // Determine the error code from error_name. |
| 485 ConnectErrorCode error_code = ERROR_UNKNOWN; | 591 ConnectErrorCode error_code = ERROR_UNKNOWN; |
| 486 if (error_name == bluetooth_adapter::kErrorAlreadyExists) | 592 if (error_name == bluetooth_adapter::kErrorAlreadyExists) |
| 487 error_code = ERROR_INPROGRESS; | 593 error_code = ERROR_INPROGRESS; |
| 488 | 594 |
| 595 RecordPairingResult(false, error_code); |
| 489 error_callback.Run(error_code); | 596 error_callback.Run(error_code); |
| 490 } | 597 } |
| 491 | 598 |
| 492 void BluetoothDeviceExperimentalChromeOS::OnPair( | 599 void BluetoothDeviceExperimentalChromeOS::OnPair( |
| 493 const base::Closure& callback, | 600 const base::Closure& callback, |
| 494 const ConnectErrorCallback& error_callback) { | 601 const ConnectErrorCallback& error_callback) { |
| 495 VLOG(1) << object_path_.value() << ": Paired"; | 602 VLOG(1) << object_path_.value() << ": Paired"; |
| 603 |
| 604 if (!pairing_delegate_used_) |
| 605 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 606 UMA_PAIRING_METHOD_NONE, |
| 607 UMA_PAIRING_METHOD_COUNT); |
| 496 UnregisterAgent(); | 608 UnregisterAgent(); |
| 497 SetTrusted(); | 609 SetTrusted(); |
| 498 ConnectInternal(callback, error_callback); | 610 ConnectInternal(callback, error_callback); |
| 499 } | 611 } |
| 500 | 612 |
| 501 void BluetoothDeviceExperimentalChromeOS::OnPairError( | 613 void BluetoothDeviceExperimentalChromeOS::OnPairError( |
| 502 const ConnectErrorCallback& error_callback, | 614 const ConnectErrorCallback& error_callback, |
| 503 const std::string& error_name, | 615 const std::string& error_name, |
| 504 const std::string& error_message) { | 616 const std::string& error_message) { |
| 505 if (--num_connecting_calls_ == 0) | 617 if (--num_connecting_calls_ == 0) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 520 } else if (error_name == bluetooth_adapter::kErrorAuthenticationFailed) { | 632 } else if (error_name == bluetooth_adapter::kErrorAuthenticationFailed) { |
| 521 error_code = ERROR_AUTH_FAILED; | 633 error_code = ERROR_AUTH_FAILED; |
| 522 } else if (error_name == bluetooth_adapter::kErrorAuthenticationCanceled) { | 634 } else if (error_name == bluetooth_adapter::kErrorAuthenticationCanceled) { |
| 523 error_code = ERROR_AUTH_CANCELED; | 635 error_code = ERROR_AUTH_CANCELED; |
| 524 } else if (error_name == bluetooth_adapter::kErrorAuthenticationRejected) { | 636 } else if (error_name == bluetooth_adapter::kErrorAuthenticationRejected) { |
| 525 error_code = ERROR_AUTH_REJECTED; | 637 error_code = ERROR_AUTH_REJECTED; |
| 526 } else if (error_name == bluetooth_adapter::kErrorAuthenticationTimeout) { | 638 } else if (error_name == bluetooth_adapter::kErrorAuthenticationTimeout) { |
| 527 error_code = ERROR_AUTH_TIMEOUT; | 639 error_code = ERROR_AUTH_TIMEOUT; |
| 528 } | 640 } |
| 529 | 641 |
| 642 RecordPairingResult(false, error_code); |
| 530 error_callback.Run(error_code); | 643 error_callback.Run(error_code); |
| 531 } | 644 } |
| 532 | 645 |
| 533 void BluetoothDeviceExperimentalChromeOS::OnCancelPairingError( | 646 void BluetoothDeviceExperimentalChromeOS::OnCancelPairingError( |
| 534 const std::string& error_name, | 647 const std::string& error_name, |
| 535 const std::string& error_message) { | 648 const std::string& error_message) { |
| 536 LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: " | 649 LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: " |
| 537 << error_name << ": " << error_message; | 650 << error_name << ": " << error_message; |
| 538 } | 651 } |
| 539 | 652 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 | 742 |
| 630 if (!confirmation_callback_.is_null()) { | 743 if (!confirmation_callback_.is_null()) { |
| 631 confirmation_callback_.Run(status); | 744 confirmation_callback_.Run(status); |
| 632 confirmation_callback_.Reset(); | 745 confirmation_callback_.Reset(); |
| 633 callback_run = true; | 746 callback_run = true; |
| 634 } | 747 } |
| 635 | 748 |
| 636 return callback_run; | 749 return callback_run; |
| 637 } | 750 } |
| 638 | 751 |
| 752 void BluetoothDeviceExperimentalChromeOS::RecordPairingResult( |
| 753 bool success, |
| 754 ConnectErrorCode error_code) { |
| 755 UMAPairingResult pairing_result; |
| 756 if (success) { |
| 757 pairing_result = UMA_PAIRING_RESULT_SUCCESS; |
| 758 } else { |
| 759 switch (error_code) { |
| 760 case ERROR_INPROGRESS: |
| 761 pairing_result = UMA_PAIRING_RESULT_INPROGRESS; |
| 762 break; |
| 763 case ERROR_FAILED: |
| 764 pairing_result = UMA_PAIRING_RESULT_FAILED; |
| 765 break; |
| 766 case ERROR_AUTH_FAILED: |
| 767 pairing_result = UMA_PAIRING_RESULT_AUTH_FAILED; |
| 768 break; |
| 769 case ERROR_AUTH_CANCELED: |
| 770 pairing_result = UMA_PAIRING_RESULT_AUTH_CANCELED; |
| 771 break; |
| 772 case ERROR_AUTH_REJECTED: |
| 773 pairing_result = UMA_PAIRING_RESULT_AUTH_REJECTED; |
| 774 break; |
| 775 case ERROR_AUTH_TIMEOUT: |
| 776 pairing_result = UMA_PAIRING_RESULT_AUTH_TIMEOUT; |
| 777 break; |
| 778 case ERROR_UNSUPPORTED_DEVICE: |
| 779 pairing_result = UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE; |
| 780 break; |
| 781 default: |
| 782 pairing_result = UMA_PAIRING_RESULT_UNKNOWN_ERROR; |
| 783 } |
| 784 } |
| 785 |
| 786 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", |
| 787 pairing_result, |
| 788 UMA_PAIRING_RESULT_COUNT); |
| 789 } |
| 790 |
| 639 } // namespace chromeos | 791 } // namespace chromeos |
| OLD | NEW |