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

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: Fix threading ownership related to ApiResourceManager<BluetoothApiSocket> and BluetoothSocketEventD… 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::Connect(
127 const base::Closure& success_callback,
128 const ErrorCompletionCallback& error_callback) {
129 NOTIMPLEMENTED();
130 }
131
132 void BluetoothSocketMac::Disconnect(const base::Closure& callback) {
133 NOTIMPLEMENTED();
134 }
135
136 void BluetoothSocketMac::Receive(
137 int count,
138 const ReceiveCompletionCallback& success_callback,
139 const ReceiveErrorCompletionCallback& error_callback) {
140 NOTIMPLEMENTED();
141 }
142
143 void BluetoothSocketMac::Send(scoped_refptr<net::DrainableIOBuffer> buffer,
144 const SendCompletionCallback& success_callback,
145 const ErrorCompletionCallback& error_callback) {
146 NOTIMPLEMENTED();
147 }
148
149 #if false
126 bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) { 150 bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) {
127 CHECK(buffer->offset() == 0); 151 CHECK(buffer->offset() == 0);
128 int length = incoming_data_buffer_->offset(); 152 int length = incoming_data_buffer_->offset();
129 if (length > 0) { 153 if (length > 0) {
130 buffer->SetCapacity(length); 154 buffer->SetCapacity(length);
131 memcpy(buffer->data(), incoming_data_buffer_->StartOfBuffer(), length); 155 memcpy(buffer->data(), incoming_data_buffer_->StartOfBuffer(), length);
132 buffer->set_offset(length); 156 buffer->set_offset(length);
133 157
134 ResetIncomingDataBuffer(); 158 ResetIncomingDataBuffer();
135 } 159 }
(...skipping 11 matching lines...) Expand all
147 return false; 171 return false;
148 } 172 }
149 173
150 buffer->DidConsume(bytes_written); 174 buffer->DidConsume(bytes_written);
151 return true; 175 return true;
152 } 176 }
153 177
154 std::string BluetoothSocketMac::GetLastErrorMessage() const { 178 std::string BluetoothSocketMac::GetLastErrorMessage() const {
155 return error_message_; 179 return error_message_;
156 } 180 }
157 181 #endif
158 void BluetoothSocketMac::OnDataReceived( 182 void BluetoothSocketMac::OnDataReceived(
159 IOBluetoothRFCOMMChannel* rfcomm_channel, void* data, size_t length) { 183 IOBluetoothRFCOMMChannel* rfcomm_channel, void* data, size_t length) {
160 DCHECK(rfcomm_channel_ == rfcomm_channel); 184 DCHECK(rfcomm_channel_ == rfcomm_channel);
161 CHECK_LT(length, static_cast<size_t>(std::numeric_limits<int>::max())); 185 CHECK_LT(length, static_cast<size_t>(std::numeric_limits<int>::max()));
162 int data_size = static_cast<int>(length); 186 int data_size = static_cast<int>(length);
163 if (incoming_data_buffer_->RemainingCapacity() < data_size) { 187 if (incoming_data_buffer_->RemainingCapacity() < data_size) {
164 int additional_capacity = 188 int additional_capacity =
165 std::max(data_size, incoming_data_buffer_->capacity()); 189 std::max(data_size, incoming_data_buffer_->capacity());
166 CHECK_LT( 190 CHECK_LT(
167 additional_capacity, 191 additional_capacity,
168 std::numeric_limits<int>::max() - incoming_data_buffer_->capacity()); 192 std::numeric_limits<int>::max() - incoming_data_buffer_->capacity());
169 incoming_data_buffer_->SetCapacity( 193 incoming_data_buffer_->SetCapacity(
170 incoming_data_buffer_->capacity() + additional_capacity); 194 incoming_data_buffer_->capacity() + additional_capacity);
171 } 195 }
172 memcpy(incoming_data_buffer_->data(), data, data_size); 196 memcpy(incoming_data_buffer_->data(), data, data_size);
173 incoming_data_buffer_->set_offset( 197 incoming_data_buffer_->set_offset(
174 incoming_data_buffer_->offset() + data_size); 198 incoming_data_buffer_->offset() + data_size);
175 } 199 }
176 200
177 void BluetoothSocketMac::ResetIncomingDataBuffer() { 201 void BluetoothSocketMac::ResetIncomingDataBuffer() {
178 incoming_data_buffer_ = new net::GrowableIOBuffer(); 202 incoming_data_buffer_ = new net::GrowableIOBuffer();
179 incoming_data_buffer_->SetCapacity(1024); 203 incoming_data_buffer_->SetCapacity(1024);
180 } 204 }
181 205
182 } // namespace device 206 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698