Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 1685963003: Adding the last test related with connect/disconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@connectdisconnect
Patch Set: Using FAILED instead of UNKNOWN error code Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> 7 #import <IOBluetooth/objc/IOBluetoothDevice.h>
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> 8 #import <IOBluetooth/objc/IOBluetoothHostController.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 24 matching lines...) Expand all
35 // The frequency with which to poll the adapter for updates. 35 // The frequency with which to poll the adapter for updates.
36 const int kPollIntervalMs = 500; 36 const int kPollIntervalMs = 500;
37 37
38 } // namespace 38 } // namespace
39 39
40 namespace device { 40 namespace device {
41 41
42 // static 42 // static
43 const NSTimeInterval BluetoothAdapterMac::kDiscoveryTimeoutSec = 43 const NSTimeInterval BluetoothAdapterMac::kDiscoveryTimeoutSec =
44 180; // 3 minutes 44 180; // 3 minutes
45 static NSString* const kErrorDomain = @"ConnectErrorCode";
45 46
46 // static 47 // static
47 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( 48 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
48 const InitCallback& init_callback) { 49 const InitCallback& init_callback) {
49 return BluetoothAdapterMac::CreateAdapter(); 50 return BluetoothAdapterMac::CreateAdapter();
50 } 51 }
51 52
52 // static 53 // static
53 base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() { 54 base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() {
54 BluetoothAdapterMac* adapter = new BluetoothAdapterMac(); 55 BluetoothAdapterMac* adapter = new BluetoothAdapterMac();
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 565 }
565 566
566 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, 567 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral,
567 NSError* error) { 568 NSError* error) {
568 BluetoothLowEnergyDeviceMac* device_mac = 569 BluetoothLowEnergyDeviceMac* device_mac =
569 GetBluetoothLowEnergyDeviceMac(peripheral); 570 GetBluetoothLowEnergyDeviceMac(peripheral);
570 if (!device_mac) { 571 if (!device_mac) {
571 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; 572 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
572 return; 573 return;
573 } 574 }
575 BluetoothDevice::ConnectErrorCode error_code =
576 BluetoothAdapterMac::GetConnectErrorCodeFromNSError(error);
574 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String 577 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String
575 << ", error code: " << error.code; 578 << ", error code: " << error.code
576 // TODO(http://crbug.com/585894): Need to convert the error. 579 << ", converted into: " << error_code;
577 device_mac->DidFailToConnectGatt(BluetoothClassicDeviceMac::ERROR_UNKNOWN); 580 device_mac->DidFailToConnectGatt(error_code);
578 } 581 }
579 582
580 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, 583 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral,
581 NSError* error) { 584 NSError* error) {
582 BluetoothLowEnergyDeviceMac* device_mac = 585 BluetoothLowEnergyDeviceMac* device_mac =
583 GetBluetoothLowEnergyDeviceMac(peripheral); 586 GetBluetoothLowEnergyDeviceMac(peripheral);
584 if (!device_mac) { 587 if (!device_mac) {
585 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; 588 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
586 return; 589 return;
587 } 590 }
588 // TODO(http://crbug.com/585897): Need to pass the error. 591 BluetoothDevice::ConnectErrorCode error_code =
589 device_mac->DidDisconnectPeripheral(); 592 BluetoothAdapterMac::GetConnectErrorCodeFromNSError(error);
593 device_mac->DidDisconnectPeripheral(error_code);
590 } 594 }
591 595
592 BluetoothLowEnergyDeviceMac* 596 BluetoothLowEnergyDeviceMac*
593 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { 597 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) {
594 std::string device_address = 598 std::string device_address =
595 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 599 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
596 DevicesMap::const_iterator iter = devices_.find(device_address); 600 DevicesMap::const_iterator iter = devices_.find(device_address);
597 if (iter == devices_.end()) { 601 if (iter == devices_.end()) {
598 return nil; 602 return nil;
599 } 603 }
600 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 604 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
601 } 605 }
602 606
607 NSError* BluetoothAdapterMac::GetNSErrorFromConnectErrorCode(
608 BluetoothDevice::ConnectErrorCode error_code) {
609 // TODO(http://crbug.com/585894): Need to convert the error.
610 return [NSError errorWithDomain:kErrorDomain code:error_code userInfo:nil];
611 }
612
613 BluetoothDevice::ConnectErrorCode
614 BluetoothAdapterMac::GetConnectErrorCodeFromNSError(NSError* error) {
615 if ([error.domain isEqualToString:kErrorDomain]) {
616 switch ((BluetoothDevice::ConnectErrorCode)error.code) {
617 case BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID:
618 return BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID;
619 case BluetoothDevice::ERROR_AUTH_CANCELED:
620 return BluetoothDevice::ERROR_AUTH_CANCELED;
621 case BluetoothDevice::ERROR_AUTH_FAILED:
622 return BluetoothDevice::ERROR_AUTH_FAILED;
623 case BluetoothDevice::ERROR_AUTH_REJECTED:
624 return BluetoothDevice::ERROR_AUTH_REJECTED;
625 case BluetoothDevice::ERROR_AUTH_TIMEOUT:
626 return BluetoothDevice::ERROR_AUTH_TIMEOUT;
627 case BluetoothDevice::ERROR_CONNECTION_CONGESTED:
628 return BluetoothDevice::ERROR_CONNECTION_CONGESTED;
629 case BluetoothDevice::ERROR_FAILED:
630 return BluetoothDevice::ERROR_FAILED;
631 case BluetoothDevice::ERROR_INPROGRESS:
632 return BluetoothDevice::ERROR_INPROGRESS;
633 case BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION:
634 return BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION;
635 case BluetoothDevice::ERROR_OFFSET_INVALID:
636 return BluetoothDevice::ERROR_OFFSET_INVALID;
637 case BluetoothDevice::ERROR_READ_NOT_PERMITTED:
638 return BluetoothDevice::ERROR_READ_NOT_PERMITTED;
639 case BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED:
640 return BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED;
641 case BluetoothDevice::ERROR_UNKNOWN:
642 return BluetoothDevice::ERROR_UNKNOWN;
643 case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE:
644 return BluetoothDevice::ERROR_UNSUPPORTED_DEVICE;
645 case BluetoothDevice::ERROR_WRITE_NOT_PERMITTED:
646 return BluetoothDevice::ERROR_WRITE_NOT_PERMITTED;
647 case BluetoothDevice::NUM_CONNECT_ERROR_CODES:
648 DCHECK(false);
649 return BluetoothDevice::ERROR_FAILED;
650 }
651 }
652 // TODO(http://crbug.com/585894): Need to convert the error.
653 return BluetoothDevice::ERROR_FAILED;
654 }
655
603 } // namespace device 656 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698