OLD | NEW |
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 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
11 #include <sstream> | 11 #include <sstream> |
12 #include <string> | 12 #include <string> |
| 13 #include <utility> |
13 | 14 |
14 #include "base/bind.h" | 15 #include "base/bind.h" |
15 #include "base/callback.h" | 16 #include "base/callback.h" |
16 #include "base/callback_helpers.h" | 17 #include "base/callback_helpers.h" |
17 #include "base/mac/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
19 #include "base/numerics/safe_conversions.h" | 20 #include "base/numerics/safe_conversions.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
22 #include "base/strings/sys_string_conversions.h" | 23 #include "base/strings/sys_string_conversions.h" |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 642 |
642 void BluetoothSocketMac::OnChannelOpenComplete( | 643 void BluetoothSocketMac::OnChannelOpenComplete( |
643 const std::string& device_address, | 644 const std::string& device_address, |
644 IOReturn status) { | 645 IOReturn status) { |
645 DCHECK(thread_checker_.CalledOnValidThread()); | 646 DCHECK(thread_checker_.CalledOnValidThread()); |
646 DCHECK(is_connecting()); | 647 DCHECK(is_connecting()); |
647 | 648 |
648 DVLOG(1) << device_address << " " << uuid_.canonical_value() | 649 DVLOG(1) << device_address << " " << uuid_.canonical_value() |
649 << ": channel open complete."; | 650 << ": channel open complete."; |
650 | 651 |
651 scoped_ptr<ConnectCallbacks> temp = connect_callbacks_.Pass(); | 652 scoped_ptr<ConnectCallbacks> temp = std::move(connect_callbacks_); |
652 if (status != kIOReturnSuccess) { | 653 if (status != kIOReturnSuccess) { |
653 ReleaseChannel(); | 654 ReleaseChannel(); |
654 std::stringstream error; | 655 std::stringstream error; |
655 error << "Failed to connect bluetooth socket (" << device_address << "): (" | 656 error << "Failed to connect bluetooth socket (" << device_address << "): (" |
656 << status << ")"; | 657 << status << ")"; |
657 temp->error_callback.Run(error.str()); | 658 temp->error_callback.Run(error.str()); |
658 return; | 659 return; |
659 } | 660 } |
660 | 661 |
661 temp->success_callback.Run(); | 662 temp->success_callback.Run(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 DCHECK(thread_checker_.CalledOnValidThread()); | 718 DCHECK(thread_checker_.CalledOnValidThread()); |
718 DCHECK(!is_connecting()); | 719 DCHECK(!is_connecting()); |
719 | 720 |
720 int data_size = base::checked_cast<int>(length); | 721 int data_size = base::checked_cast<int>(length); |
721 scoped_refptr<net::IOBufferWithSize> buffer( | 722 scoped_refptr<net::IOBufferWithSize> buffer( |
722 new net::IOBufferWithSize(data_size)); | 723 new net::IOBufferWithSize(data_size)); |
723 memcpy(buffer->data(), data, buffer->size()); | 724 memcpy(buffer->data(), data, buffer->size()); |
724 | 725 |
725 // If there is a pending read callback, call it now. | 726 // If there is a pending read callback, call it now. |
726 if (receive_callbacks_) { | 727 if (receive_callbacks_) { |
727 scoped_ptr<ReceiveCallbacks> temp = receive_callbacks_.Pass(); | 728 scoped_ptr<ReceiveCallbacks> temp = std::move(receive_callbacks_); |
728 temp->success_callback.Run(buffer->size(), buffer); | 729 temp->success_callback.Run(buffer->size(), buffer); |
729 return; | 730 return; |
730 } | 731 } |
731 | 732 |
732 // Otherwise, enqueue the buffer for later use | 733 // Otherwise, enqueue the buffer for later use |
733 receive_queue_.push(buffer); | 734 receive_queue_.push(buffer); |
734 } | 735 } |
735 | 736 |
736 void BluetoothSocketMac::Send(scoped_refptr<net::IOBuffer> buffer, | 737 void BluetoothSocketMac::Send(scoped_refptr<net::IOBuffer> buffer, |
737 int buffer_size, | 738 int buffer_size, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 } | 828 } |
828 } else { | 829 } else { |
829 request->success_callback.Run(request->buffer_size); | 830 request->success_callback.Run(request->buffer_size); |
830 } | 831 } |
831 } | 832 } |
832 | 833 |
833 void BluetoothSocketMac::OnChannelClosed() { | 834 void BluetoothSocketMac::OnChannelClosed() { |
834 DCHECK(thread_checker_.CalledOnValidThread()); | 835 DCHECK(thread_checker_.CalledOnValidThread()); |
835 | 836 |
836 if (receive_callbacks_) { | 837 if (receive_callbacks_) { |
837 scoped_ptr<ReceiveCallbacks> temp = receive_callbacks_.Pass(); | 838 scoped_ptr<ReceiveCallbacks> temp = std::move(receive_callbacks_); |
838 temp->error_callback.Run(BluetoothSocket::kDisconnected, | 839 temp->error_callback.Run(BluetoothSocket::kDisconnected, |
839 kSocketNotConnected); | 840 kSocketNotConnected); |
840 } | 841 } |
841 | 842 |
842 ReleaseChannel(); | 843 ReleaseChannel(); |
843 } | 844 } |
844 | 845 |
845 void BluetoothSocketMac::Accept( | 846 void BluetoothSocketMac::Accept( |
846 const AcceptCompletionCallback& success_callback, | 847 const AcceptCompletionCallback& success_callback, |
847 const ErrorCompletionCallback& error_callback) { | 848 const ErrorCompletionCallback& error_callback) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 rfcomm_connection_listener_.reset(); | 942 rfcomm_connection_listener_.reset(); |
942 l2cap_connection_listener_.reset(); | 943 l2cap_connection_listener_.reset(); |
943 | 944 |
944 // Destroying the listener above prevents the callback delegate from being | 945 // Destroying the listener above prevents the callback delegate from being |
945 // called so it is now safe to release all callback state. | 946 // called so it is now safe to release all callback state. |
946 accept_request_.reset(); | 947 accept_request_.reset(); |
947 empty_queue(accept_queue_); | 948 empty_queue(accept_queue_); |
948 } | 949 } |
949 | 950 |
950 } // namespace device | 951 } // namespace device |
OLD | NEW |