| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_device_win.h" | 5 #include "device/bluetooth/bluetooth_device_win.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/sequenced_task_runner.h" | |
| 13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 14 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 13 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
| 15 #include "device/bluetooth/bluetooth_profile_win.h" | 14 #include "device/bluetooth/bluetooth_profile_win.h" |
| 16 #include "device/bluetooth/bluetooth_service_record_win.h" | 15 #include "device/bluetooth/bluetooth_service_record_win.h" |
| 17 #include "device/bluetooth/bluetooth_socket_thread_win.h" | |
| 18 #include "device/bluetooth/bluetooth_socket_win.h" | 16 #include "device/bluetooth/bluetooth_socket_win.h" |
| 19 #include "device/bluetooth/bluetooth_task_manager_win.h" | 17 #include "device/bluetooth/bluetooth_task_manager_win.h" |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 const int kSdpBytesBufferSize = 1024; | 21 const int kSdpBytesBufferSize = 1024; |
| 24 | 22 |
| 25 } // namespace | 23 } // namespace |
| 26 | 24 |
| 27 namespace device { | 25 namespace device { |
| 28 | 26 |
| 29 BluetoothDeviceWin::BluetoothDeviceWin( | 27 BluetoothDeviceWin::BluetoothDeviceWin( |
| 30 const BluetoothTaskManagerWin::DeviceState& state, | 28 const BluetoothTaskManagerWin::DeviceState& state) |
| 31 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 29 : BluetoothDevice() { |
| 32 scoped_refptr<BluetoothSocketThreadWin> socket_thread, | |
| 33 net::NetLog* net_log, | |
| 34 const net::NetLog::Source& net_log_source) | |
| 35 : BluetoothDevice(), | |
| 36 ui_task_runner_(ui_task_runner), | |
| 37 socket_thread_(socket_thread), | |
| 38 net_log_(net_log), | |
| 39 net_log_source_(net_log_source) { | |
| 40 name_ = state.name; | 30 name_ = state.name; |
| 41 address_ = state.address; | 31 address_ = state.address; |
| 42 bluetooth_class_ = state.bluetooth_class; | 32 bluetooth_class_ = state.bluetooth_class; |
| 43 visible_ = state.visible; | 33 visible_ = state.visible; |
| 44 connected_ = state.connected; | 34 connected_ = state.connected; |
| 45 paired_ = state.authenticated; | 35 paired_ = state.authenticated; |
| 46 | 36 |
| 47 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator | 37 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator |
| 48 iter = state.service_record_states.begin(); | 38 iter = state.service_record_states.begin(); |
| 49 iter != state.service_record_states.end(); | 39 iter != state.service_record_states.end(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 NOTIMPLEMENTED(); | 156 NOTIMPLEMENTED(); |
| 167 } | 157 } |
| 168 | 158 |
| 169 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) { | 159 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) { |
| 170 NOTIMPLEMENTED(); | 160 NOTIMPLEMENTED(); |
| 171 } | 161 } |
| 172 | 162 |
| 173 void BluetoothDeviceWin::ConnectToService( | 163 void BluetoothDeviceWin::ConnectToService( |
| 174 const device::BluetoothUUID& service_uuid, | 164 const device::BluetoothUUID& service_uuid, |
| 175 const SocketCallback& callback) { | 165 const SocketCallback& callback) { |
| 176 NOTIMPLEMENTED(); | 166 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); |
| 167 iter != service_record_list_.end(); |
| 168 ++iter) { |
| 169 if ((*iter)->uuid() == service_uuid) { |
| 170 // If multiple service records are found, use the first one that works. |
| 171 scoped_refptr<BluetoothSocket> socket( |
| 172 BluetoothSocketWin::CreateBluetoothSocket(**iter)); |
| 173 if (socket.get() != NULL) { |
| 174 callback.Run(socket); |
| 175 return; |
| 176 } |
| 177 } |
| 178 } |
| 177 } | 179 } |
| 178 | 180 |
| 179 void BluetoothDeviceWin::ConnectToProfile( | 181 void BluetoothDeviceWin::ConnectToProfile( |
| 180 device::BluetoothProfile* profile, | 182 device::BluetoothProfile* profile, |
| 181 const base::Closure& callback, | 183 const base::Closure& callback, |
| 182 const ConnectToProfileErrorCallback& error_callback) { | 184 const ErrorCallback& error_callback) { |
| 183 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 185 if (static_cast<BluetoothProfileWin*>(profile)->Connect(this)) |
| 184 static_cast<BluetoothProfileWin*>(profile)->Connect(this, | 186 callback.Run(); |
| 185 ui_task_runner_, | 187 else |
| 186 socket_thread_, | 188 error_callback.Run(); |
| 187 net_log_, | |
| 188 net_log_source_, | |
| 189 callback, | |
| 190 error_callback); | |
| 191 } | 189 } |
| 192 | 190 |
| 193 void BluetoothDeviceWin::SetOutOfBandPairingData( | 191 void BluetoothDeviceWin::SetOutOfBandPairingData( |
| 194 const BluetoothOutOfBandPairingData& data, | 192 const BluetoothOutOfBandPairingData& data, |
| 195 const base::Closure& callback, | 193 const base::Closure& callback, |
| 196 const ErrorCallback& error_callback) { | 194 const ErrorCallback& error_callback) { |
| 197 NOTIMPLEMENTED(); | 195 NOTIMPLEMENTED(); |
| 198 } | 196 } |
| 199 | 197 |
| 200 void BluetoothDeviceWin::ClearOutOfBandPairingData( | 198 void BluetoothDeviceWin::ClearOutOfBandPairingData( |
| 201 const base::Closure& callback, | 199 const base::Closure& callback, |
| 202 const ErrorCallback& error_callback) { | 200 const ErrorCallback& error_callback) { |
| 203 NOTIMPLEMENTED(); | 201 NOTIMPLEMENTED(); |
| 204 } | 202 } |
| 205 | 203 |
| 206 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord( | 204 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord( |
| 207 const device::BluetoothUUID& uuid) const { | 205 const device::BluetoothUUID& uuid) const { |
| 208 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); | 206 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); |
| 209 iter != service_record_list_.end(); | 207 iter != service_record_list_.end(); |
| 210 ++iter) { | 208 ++iter) { |
| 211 if ((*iter)->uuid() == uuid) | 209 if ((*iter)->uuid() == uuid) |
| 212 return *iter; | 210 return *iter; |
| 213 } | 211 } |
| 214 return NULL; | 212 return NULL; |
| 215 } | 213 } |
| 216 | 214 |
| 217 } // namespace device | 215 } // namespace device |
| OLD | NEW |