| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 NOTIMPLEMENTED(); | 166 NOTIMPLEMENTED(); |
| 157 } | 167 } |
| 158 | 168 |
| 159 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) { | 169 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) { |
| 160 NOTIMPLEMENTED(); | 170 NOTIMPLEMENTED(); |
| 161 } | 171 } |
| 162 | 172 |
| 163 void BluetoothDeviceWin::ConnectToService( | 173 void BluetoothDeviceWin::ConnectToService( |
| 164 const std::string& service_uuid, | 174 const std::string& service_uuid, |
| 165 const SocketCallback& callback) { | 175 const SocketCallback& callback) { |
| 166 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); | 176 NOTIMPLEMENTED(); |
| 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 } | |
| 179 } | 177 } |
| 180 | 178 |
| 181 void BluetoothDeviceWin::ConnectToProfile( | 179 void BluetoothDeviceWin::ConnectToProfile( |
| 182 device::BluetoothProfile* profile, | 180 device::BluetoothProfile* profile, |
| 183 const base::Closure& callback, | 181 const base::Closure& callback, |
| 184 const ErrorCallback& error_callback) { | 182 const ConnectToProfileErrorCallback& error_callback) { |
| 185 if (static_cast<BluetoothProfileWin*>(profile)->Connect(this)) | 183 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 186 callback.Run(); | 184 static_cast<BluetoothProfileWin*>(profile)->Connect(this, |
| 187 else | 185 ui_task_runner_, |
| 188 error_callback.Run(); | 186 socket_thread_, |
| 187 net_log_, |
| 188 net_log_source_, |
| 189 callback, |
| 190 error_callback); |
| 189 } | 191 } |
| 190 | 192 |
| 191 void BluetoothDeviceWin::SetOutOfBandPairingData( | 193 void BluetoothDeviceWin::SetOutOfBandPairingData( |
| 192 const BluetoothOutOfBandPairingData& data, | 194 const BluetoothOutOfBandPairingData& data, |
| 193 const base::Closure& callback, | 195 const base::Closure& callback, |
| 194 const ErrorCallback& error_callback) { | 196 const ErrorCallback& error_callback) { |
| 195 NOTIMPLEMENTED(); | 197 NOTIMPLEMENTED(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 void BluetoothDeviceWin::ClearOutOfBandPairingData( | 200 void BluetoothDeviceWin::ClearOutOfBandPairingData( |
| 199 const base::Closure& callback, | 201 const base::Closure& callback, |
| 200 const ErrorCallback& error_callback) { | 202 const ErrorCallback& error_callback) { |
| 201 NOTIMPLEMENTED(); | 203 NOTIMPLEMENTED(); |
| 202 } | 204 } |
| 203 | 205 |
| 204 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord( | 206 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord( |
| 205 const std::string& uuid) const { | 207 const std::string& uuid) const { |
| 206 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); | 208 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); |
| 207 iter != service_record_list_.end(); | 209 iter != service_record_list_.end(); |
| 208 ++iter) { | 210 ++iter) { |
| 209 if ((*iter)->uuid().compare(uuid) == 0) | 211 if ((*iter)->uuid().compare(uuid) == 0) |
| 210 return *iter; | 212 return *iter; |
| 211 } | 213 } |
| 212 return NULL; | 214 return NULL; |
| 213 } | 215 } |
| 214 | 216 |
| 215 } // namespace device | 217 } // namespace device |
| OLD | NEW |