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

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

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback, simplify threading model. Created 6 years, 9 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/objc/IOBluetoothDevice.h> 7 #import <IOBluetooth/objc/IOBluetoothDevice.h>
8 #import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h> 8 #import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
9 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> 9 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
10 10
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 << base::SysNSStringToUTF8([device addressString]) << "): (" << status 116 << base::SysNSStringToUTF8([device addressString]) << "): (" << status
117 << ")"; 117 << ")";
118 } 118 }
119 } 119 }
120 120
121 // TODO(youngki): Add support for L2CAP sockets as well. 121 // TODO(youngki): Add support for L2CAP sockets as well.
122 122
123 return scoped_refptr<BluetoothSocketMac>(bluetooth_socket); 123 return scoped_refptr<BluetoothSocketMac>(bluetooth_socket);
124 } 124 }
125 125
126 void BluetoothSocketMac::Disconnect(const base::Closure& callback) {
127 NOTIMPLEMENTED();
128 }
129
130 void BluetoothSocketMac::Receive(
131 int count,
132 const ReceiveCompletionCallback& success_callback,
133 const ReceiveErrorCompletionCallback& error_callback) {
134 NOTIMPLEMENTED();
135 }
136
137 void BluetoothSocketMac::Send(scoped_refptr<net::IOBuffer> buffer,
138 int buffer_size,
139 const SendCompletionCallback& success_callback,
140 const ErrorCompletionCallback& error_callback) {
141 NOTIMPLEMENTED();
142 }
143
144 #if 0
126 bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) { 145 bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) {
127 CHECK(buffer->offset() == 0); 146 CHECK(buffer->offset() == 0);
128 int length = incoming_data_buffer_->offset(); 147 int length = incoming_data_buffer_->offset();
129 if (length > 0) { 148 if (length > 0) {
130 buffer->SetCapacity(length); 149 buffer->SetCapacity(length);
131 memcpy(buffer->data(), incoming_data_buffer_->StartOfBuffer(), length); 150 memcpy(buffer->data(), incoming_data_buffer_->StartOfBuffer(), length);
132 buffer->set_offset(length); 151 buffer->set_offset(length);
133 152
134 ResetIncomingDataBuffer(); 153 ResetIncomingDataBuffer();
135 } 154 }
(...skipping 11 matching lines...) Expand all
147 return false; 166 return false;
148 } 167 }
149 168
150 buffer->DidConsume(bytes_written); 169 buffer->DidConsume(bytes_written);
151 return true; 170 return true;
152 } 171 }
153 172
154 std::string BluetoothSocketMac::GetLastErrorMessage() const { 173 std::string BluetoothSocketMac::GetLastErrorMessage() const {
155 return error_message_; 174 return error_message_;
156 } 175 }
157 176 #endif
158 void BluetoothSocketMac::OnDataReceived( 177 void BluetoothSocketMac::OnDataReceived(
159 IOBluetoothRFCOMMChannel* rfcomm_channel, void* data, size_t length) { 178 IOBluetoothRFCOMMChannel* rfcomm_channel, void* data, size_t length) {
160 DCHECK(rfcomm_channel_ == rfcomm_channel); 179 DCHECK(rfcomm_channel_ == rfcomm_channel);
161 CHECK_LT(length, static_cast<size_t>(std::numeric_limits<int>::max())); 180 CHECK_LT(length, static_cast<size_t>(std::numeric_limits<int>::max()));
162 int data_size = static_cast<int>(length); 181 int data_size = static_cast<int>(length);
163 if (incoming_data_buffer_->RemainingCapacity() < data_size) { 182 if (incoming_data_buffer_->RemainingCapacity() < data_size) {
164 int additional_capacity = 183 int additional_capacity =
165 std::max(data_size, incoming_data_buffer_->capacity()); 184 std::max(data_size, incoming_data_buffer_->capacity());
166 CHECK_LT( 185 CHECK_LT(
167 additional_capacity, 186 additional_capacity,
168 std::numeric_limits<int>::max() - incoming_data_buffer_->capacity()); 187 std::numeric_limits<int>::max() - incoming_data_buffer_->capacity());
169 incoming_data_buffer_->SetCapacity( 188 incoming_data_buffer_->SetCapacity(
170 incoming_data_buffer_->capacity() + additional_capacity); 189 incoming_data_buffer_->capacity() + additional_capacity);
171 } 190 }
172 memcpy(incoming_data_buffer_->data(), data, data_size); 191 memcpy(incoming_data_buffer_->data(), data, data_size);
173 incoming_data_buffer_->set_offset( 192 incoming_data_buffer_->set_offset(
174 incoming_data_buffer_->offset() + data_size); 193 incoming_data_buffer_->offset() + data_size);
175 } 194 }
176 195
177 void BluetoothSocketMac::ResetIncomingDataBuffer() { 196 void BluetoothSocketMac::ResetIncomingDataBuffer() {
178 incoming_data_buffer_ = new net::GrowableIOBuffer(); 197 incoming_data_buffer_ = new net::GrowableIOBuffer();
179 incoming_data_buffer_->SetCapacity(1024); 198 incoming_data_buffer_->SetCapacity(1024);
180 } 199 }
181 200
182 } // namespace device 201 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698