| 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" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 14 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
| 14 #include "device/bluetooth/bluetooth_profile_win.h" | 15 #include "device/bluetooth/bluetooth_profile_win.h" |
| 15 #include "device/bluetooth/bluetooth_service_record_win.h" | 16 #include "device/bluetooth/bluetooth_service_record_win.h" |
| 17 #include "device/bluetooth/bluetooth_socket_thread_win.h" |
| 16 #include "device/bluetooth/bluetooth_socket_win.h" | 18 #include "device/bluetooth/bluetooth_socket_win.h" |
| 17 #include "device/bluetooth/bluetooth_task_manager_win.h" | 19 #include "device/bluetooth/bluetooth_task_manager_win.h" |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 const int kSdpBytesBufferSize = 1024; | 23 const int kSdpBytesBufferSize = 1024; |
| 22 | 24 |
| 23 } // namespace | 25 } // namespace |
| 24 | 26 |
| 25 namespace device { | 27 namespace device { |
| 26 | 28 |
| 27 BluetoothDeviceWin::BluetoothDeviceWin( | 29 BluetoothDeviceWin::BluetoothDeviceWin( |
| 28 const BluetoothTaskManagerWin::DeviceState& state) | 30 const BluetoothTaskManagerWin::DeviceState& state, |
| 29 : BluetoothDevice() { | 31 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 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) { |
| 30 name_ = state.name; | 40 name_ = state.name; |
| 31 address_ = state.address; | 41 address_ = state.address; |
| 32 bluetooth_class_ = state.bluetooth_class; | 42 bluetooth_class_ = state.bluetooth_class; |
| 33 visible_ = state.visible; | 43 visible_ = state.visible; |
| 34 connected_ = state.connected; | 44 connected_ = state.connected; |
| 35 paired_ = state.authenticated; | 45 paired_ = state.authenticated; |
| 36 | 46 |
| 37 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator | 47 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator |
| 38 iter = state.service_record_states.begin(); | 48 iter = state.service_record_states.begin(); |
| 39 iter != state.service_record_states.end(); | 49 iter != state.service_record_states.end(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 NOTIMPLEMENTED(); | 186 NOTIMPLEMENTED(); |
| 177 } | 187 } |
| 178 | 188 |
| 179 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) { | 189 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) { |
| 180 NOTIMPLEMENTED(); | 190 NOTIMPLEMENTED(); |
| 181 } | 191 } |
| 182 | 192 |
| 183 void BluetoothDeviceWin::ConnectToService( | 193 void BluetoothDeviceWin::ConnectToService( |
| 184 const std::string& service_uuid, | 194 const std::string& service_uuid, |
| 185 const SocketCallback& callback) { | 195 const SocketCallback& callback) { |
| 186 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); | 196 NOTIMPLEMENTED(); |
| 187 iter != service_record_list_.end(); | |
| 188 ++iter) { | |
| 189 if ((*iter)->uuid() == service_uuid) { | |
| 190 // If multiple service records are found, use the first one that works. | |
| 191 scoped_refptr<BluetoothSocket> socket( | |
| 192 BluetoothSocketWin::CreateBluetoothSocket(**iter)); | |
| 193 if (socket.get() != NULL) { | |
| 194 callback.Run(socket); | |
| 195 return; | |
| 196 } | |
| 197 } | |
| 198 } | |
| 199 } | 197 } |
| 200 | 198 |
| 201 void BluetoothDeviceWin::ConnectToProfile( | 199 void BluetoothDeviceWin::ConnectToProfile( |
| 202 device::BluetoothProfile* profile, | 200 device::BluetoothProfile* profile, |
| 203 const base::Closure& callback, | 201 const base::Closure& callback, |
| 204 const ErrorCallback& error_callback) { | 202 const ConnectToProfileErrorCallback& error_callback) { |
| 205 if (static_cast<BluetoothProfileWin*>(profile)->Connect(this)) | 203 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 206 callback.Run(); | 204 static_cast<BluetoothProfileWin*>(profile)->Connect(this, |
| 207 else | 205 ui_task_runner_, |
| 208 error_callback.Run(); | 206 socket_thread_, |
| 207 net_log_, |
| 208 net_log_source_, |
| 209 callback, |
| 210 error_callback); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void BluetoothDeviceWin::SetOutOfBandPairingData( | 213 void BluetoothDeviceWin::SetOutOfBandPairingData( |
| 212 const BluetoothOutOfBandPairingData& data, | 214 const BluetoothOutOfBandPairingData& data, |
| 213 const base::Closure& callback, | 215 const base::Closure& callback, |
| 214 const ErrorCallback& error_callback) { | 216 const ErrorCallback& error_callback) { |
| 215 NOTIMPLEMENTED(); | 217 NOTIMPLEMENTED(); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void BluetoothDeviceWin::ClearOutOfBandPairingData( | 220 void BluetoothDeviceWin::ClearOutOfBandPairingData( |
| 219 const base::Closure& callback, | 221 const base::Closure& callback, |
| 220 const ErrorCallback& error_callback) { | 222 const ErrorCallback& error_callback) { |
| 221 NOTIMPLEMENTED(); | 223 NOTIMPLEMENTED(); |
| 222 } | 224 } |
| 223 | 225 |
| 224 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord( | 226 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord( |
| 225 const std::string& uuid) const { | 227 const std::string& uuid) const { |
| 226 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); | 228 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); |
| 227 iter != service_record_list_.end(); | 229 iter != service_record_list_.end(); |
| 228 ++iter) { | 230 ++iter) { |
| 229 if ((*iter)->uuid().compare(uuid) == 0) | 231 if ((*iter)->uuid().compare(uuid) == 0) |
| 230 return *iter; | 232 return *iter; |
| 231 } | 233 } |
| 232 return NULL; | 234 return NULL; |
| 233 } | 235 } |
| 234 | 236 |
| 235 } // namespace device | 237 } // namespace device |
| OLD | NEW |