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

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

Issue 1220713006: Renaming BluetoothDeviceMac as BluetoothClassicDeviceMac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dm
Patch Set: learning alphabet Created 5 years, 5 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_socket_mac.h" 5 #include "device/bluetooth/bluetooth_socket_mac.h"
6 6
7 #import <IOBluetooth/IOBluetooth.h> 7 #import <IOBluetooth/IOBluetooth.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <sstream> 10 #include <sstream>
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/callback_helpers.h" 16 #include "base/callback_helpers.h"
17 #include "base/mac/scoped_cftyperef.h" 17 #include "base/mac/scoped_cftyperef.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/numerics/safe_conversions.h" 19 #include "base/numerics/safe_conversions.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/strings/sys_string_conversions.h" 22 #include "base/strings/sys_string_conversions.h"
23 #include "base/threading/thread_restrictions.h" 23 #include "base/threading/thread_restrictions.h"
24 #include "device/bluetooth/bluetooth_adapter_mac.h" 24 #include "device/bluetooth/bluetooth_adapter_mac.h"
25 #include "device/bluetooth/bluetooth_channel_mac.h" 25 #include "device/bluetooth/bluetooth_channel_mac.h"
26 #include "device/bluetooth/bluetooth_classic_device_mac.h"
26 #include "device/bluetooth/bluetooth_device.h" 27 #include "device/bluetooth/bluetooth_device.h"
27 #include "device/bluetooth/bluetooth_device_mac.h"
28 #include "device/bluetooth/bluetooth_l2cap_channel_mac.h" 28 #include "device/bluetooth/bluetooth_l2cap_channel_mac.h"
29 #include "device/bluetooth/bluetooth_rfcomm_channel_mac.h" 29 #include "device/bluetooth/bluetooth_rfcomm_channel_mac.h"
30 #include "net/base/io_buffer.h" 30 #include "net/base/io_buffer.h"
31 #include "net/base/net_errors.h" 31 #include "net/base/net_errors.h"
32 32
33 #if !defined(MAC_OS_X_VERSION_10_7) || \ 33 #if !defined(MAC_OS_X_VERSION_10_7) || \
34 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 34 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7
35 35
36 @interface IOBluetoothDevice (LionSDKDeclarations) 36 @interface IOBluetoothDevice (LionSDKDeclarations)
37 - (IOReturn)performSDPQuery:(id)target uuids:(NSArray*)uuids; 37 - (IOReturn)performSDPQuery:(id)target uuids:(NSArray*)uuids;
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 const BluetoothUUID& uuid, 464 const BluetoothUUID& uuid,
465 const base::Closure& success_callback, 465 const base::Closure& success_callback,
466 const ErrorCompletionCallback& error_callback) { 466 const ErrorCompletionCallback& error_callback) {
467 DCHECK(thread_checker_.CalledOnValidThread()); 467 DCHECK(thread_checker_.CalledOnValidThread());
468 468
469 uuid_ = uuid; 469 uuid_ = uuid;
470 470
471 // Perform an SDP query on the |device| to refresh the cache, in case the 471 // Perform an SDP query on the |device| to refresh the cache, in case the
472 // services that the |device| advertises have changed since the previous 472 // services that the |device| advertises have changed since the previous
473 // query. 473 // query.
474 DVLOG(1) << BluetoothDeviceMac::GetDeviceAddress(device) << " " 474 DVLOG(1) << BluetoothClassicDeviceMac::GetDeviceAddress(device) << " "
475 << uuid_.canonical_value() << ": Sending SDP query."; 475 << uuid_.canonical_value() << ": Sending SDP query.";
476 SDPQueryListener* listener = 476 SDPQueryListener* listener =
477 [[SDPQueryListener alloc] initWithSocket:this 477 [[SDPQueryListener alloc] initWithSocket:this
478 device:device 478 device:device
479 success_callback:success_callback 479 success_callback:success_callback
480 error_callback:error_callback]; 480 error_callback:error_callback];
481 [device performSDPQuery:[listener autorelease] 481 [device performSDPQuery:[listener autorelease]
482 uuids:@[GetIOBluetoothSDPUUID(uuid_)]]; 482 uuids:@[GetIOBluetoothSDPUUID(uuid_)]];
483 } 483 }
484 484
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 535
536 success_callback.Run(); 536 success_callback.Run();
537 } 537 }
538 538
539 void BluetoothSocketMac::OnSDPQueryComplete( 539 void BluetoothSocketMac::OnSDPQueryComplete(
540 IOReturn status, 540 IOReturn status,
541 IOBluetoothDevice* device, 541 IOBluetoothDevice* device,
542 const base::Closure& success_callback, 542 const base::Closure& success_callback,
543 const ErrorCompletionCallback& error_callback) { 543 const ErrorCompletionCallback& error_callback) {
544 DCHECK(thread_checker_.CalledOnValidThread()); 544 DCHECK(thread_checker_.CalledOnValidThread());
545 DVLOG(1) << BluetoothDeviceMac::GetDeviceAddress(device) << " " 545 DVLOG(1) << BluetoothClassicDeviceMac::GetDeviceAddress(device) << " "
546 << uuid_.canonical_value() << ": SDP query complete."; 546 << uuid_.canonical_value() << ": SDP query complete.";
547 547
548 if (status != kIOReturnSuccess) { 548 if (status != kIOReturnSuccess) {
549 error_callback.Run(kSDPQueryFailed); 549 error_callback.Run(kSDPQueryFailed);
550 return; 550 return;
551 } 551 }
552 552
553 IOBluetoothSDPServiceRecord* record = [device 553 IOBluetoothSDPServiceRecord* record = [device
554 getServiceRecordForUUID:GetIOBluetoothSDPUUID(uuid_)]; 554 getServiceRecordForUUID:GetIOBluetoothSDPUUID(uuid_)];
555 if (record == nil) { 555 if (record == nil) {
(...skipping 18 matching lines...) Expand all
574 status = [record getRFCOMMChannelID:&rfcomm_channel_id]; 574 status = [record getRFCOMMChannelID:&rfcomm_channel_id];
575 if (status != kIOReturnSuccess) { 575 if (status != kIOReturnSuccess) {
576 status = [record getL2CAPPSM:&l2cap_psm]; 576 status = [record getL2CAPPSM:&l2cap_psm];
577 if (status != kIOReturnSuccess) { 577 if (status != kIOReturnSuccess) {
578 error_callback.Run(kProfileNotFound); 578 error_callback.Run(kProfileNotFound);
579 return; 579 return;
580 } 580 }
581 } 581 }
582 582
583 if (rfcomm_channel_id != kInvalidRfcommChannelId) { 583 if (rfcomm_channel_id != kInvalidRfcommChannelId) {
584 DVLOG(1) << BluetoothDeviceMac::GetDeviceAddress(device) << " " 584 DVLOG(1) << BluetoothClassicDeviceMac::GetDeviceAddress(device) << " "
585 << uuid_.canonical_value() << ": Opening RFCOMM channel: " 585 << uuid_.canonical_value()
586 << rfcomm_channel_id; 586 << ": Opening RFCOMM channel: " << rfcomm_channel_id;
587 } else { 587 } else {
588 DCHECK_NE(l2cap_psm, kInvalidL2capPsm); 588 DCHECK_NE(l2cap_psm, kInvalidL2capPsm);
589 DVLOG(1) << BluetoothDeviceMac::GetDeviceAddress(device) << " " 589 DVLOG(1) << BluetoothClassicDeviceMac::GetDeviceAddress(device) << " "
590 << uuid_.canonical_value() << ": Opening L2CAP channel: " 590 << uuid_.canonical_value()
591 << l2cap_psm; 591 << ": Opening L2CAP channel: " << l2cap_psm;
592 } 592 }
593 593
594 // Note: It's important to set the connect callbacks *prior* to opening the 594 // Note: It's important to set the connect callbacks *prior* to opening the
595 // channel, as opening the channel can synchronously call into 595 // channel, as opening the channel can synchronously call into
596 // OnChannelOpenComplete(). 596 // OnChannelOpenComplete().
597 connect_callbacks_.reset(new ConnectCallbacks()); 597 connect_callbacks_.reset(new ConnectCallbacks());
598 connect_callbacks_->success_callback = success_callback; 598 connect_callbacks_->success_callback = success_callback;
599 connect_callbacks_->error_callback = error_callback; 599 connect_callbacks_->error_callback = error_callback;
600 600
601 if (rfcomm_channel_id != kInvalidRfcommChannelId) { 601 if (rfcomm_channel_id != kInvalidRfcommChannelId) {
602 channel_ = BluetoothRfcommChannelMac::OpenAsync( 602 channel_ = BluetoothRfcommChannelMac::OpenAsync(
603 this, device, rfcomm_channel_id, &status); 603 this, device, rfcomm_channel_id, &status);
604 } else { 604 } else {
605 DCHECK_NE(l2cap_psm, kInvalidL2capPsm); 605 DCHECK_NE(l2cap_psm, kInvalidL2capPsm);
606 channel_ = 606 channel_ =
607 BluetoothL2capChannelMac::OpenAsync(this, device, l2cap_psm, &status); 607 BluetoothL2capChannelMac::OpenAsync(this, device, l2cap_psm, &status);
608 } 608 }
609 if (status != kIOReturnSuccess) { 609 if (status != kIOReturnSuccess) {
610 ReleaseChannel(); 610 ReleaseChannel();
611 std::stringstream error; 611 std::stringstream error;
612 error << "Failed to connect bluetooth socket (" 612 error << "Failed to connect bluetooth socket ("
613 << BluetoothDeviceMac::GetDeviceAddress(device) << "): (" << status 613 << BluetoothClassicDeviceMac::GetDeviceAddress(device) << "): ("
614 << ")"; 614 << status << ")";
615 error_callback.Run(error.str()); 615 error_callback.Run(error.str());
616 return; 616 return;
617 } 617 }
618 618
619 DVLOG(1) << BluetoothDeviceMac::GetDeviceAddress(device) << " " 619 DVLOG(1) << BluetoothClassicDeviceMac::GetDeviceAddress(device) << " "
620 << uuid_.canonical_value() 620 << uuid_.canonical_value() << ": channel opening in background.";
621 << ": channel opening in background.";
622 } 621 }
623 622
624 void BluetoothSocketMac::OnChannelOpened( 623 void BluetoothSocketMac::OnChannelOpened(
625 scoped_ptr<BluetoothChannelMac> channel) { 624 scoped_ptr<BluetoothChannelMac> channel) {
626 DCHECK(thread_checker_.CalledOnValidThread()); 625 DCHECK(thread_checker_.CalledOnValidThread());
627 DVLOG(1) << uuid_.canonical_value() << ": Incoming channel pending."; 626 DVLOG(1) << uuid_.canonical_value() << ": Incoming channel pending.";
628 627
629 accept_queue_.push(linked_ptr<BluetoothChannelMac>(channel.release())); 628 accept_queue_.push(linked_ptr<BluetoothChannelMac>(channel.release()));
630 if (accept_request_) 629 if (accept_request_)
631 AcceptConnectionRequest(); 630 AcceptConnectionRequest();
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 rfcomm_connection_listener_.reset(); 941 rfcomm_connection_listener_.reset();
943 l2cap_connection_listener_.reset(); 942 l2cap_connection_listener_.reset();
944 943
945 // Destroying the listener above prevents the callback delegate from being 944 // Destroying the listener above prevents the callback delegate from being
946 // called so it is now safe to release all callback state. 945 // called so it is now safe to release all callback state.
947 accept_request_.reset(); 946 accept_request_.reset();
948 empty_queue(accept_queue_); 947 empty_queue(accept_queue_);
949 } 948 }
950 949
951 } // namespace device 950 } // namespace device
OLDNEW
« device/bluetooth/BUILD.gn ('K') | « device/bluetooth/bluetooth_rfcomm_channel_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698