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_task_manager_win.h" | 5 #include "device/bluetooth/bluetooth_task_manager_win.h" |
6 | 6 |
7 #include <winsock2.h> | 7 #include <winsock2.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 BluetoothTaskManagerWin::Observer, observers_, DevicesPolled(*devices)); | 284 BluetoothTaskManagerWin::Observer, observers_, DevicesPolled(*devices)); |
285 } | 285 } |
286 | 286 |
287 void BluetoothTaskManagerWin::PollAdapter() { | 287 void BluetoothTaskManagerWin::PollAdapter() { |
288 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 288 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
289 | 289 |
290 // Skips updating the adapter info if the adapter is in discovery mode. | 290 // Skips updating the adapter info if the adapter is in discovery mode. |
291 if (!discovering_) { | 291 if (!discovering_) { |
292 const BLUETOOTH_FIND_RADIO_PARAMS adapter_param = | 292 const BLUETOOTH_FIND_RADIO_PARAMS adapter_param = |
293 { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; | 293 { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; |
294 if (adapter_handle_) | 294 if (adapter_handle_.IsValid()) |
295 adapter_handle_.Close(); | 295 adapter_handle_.Close(); |
296 HANDLE temp_adapter_handle; | 296 HANDLE temp_adapter_handle; |
297 HBLUETOOTH_RADIO_FIND handle = BluetoothFindFirstRadio( | 297 HBLUETOOTH_RADIO_FIND handle = BluetoothFindFirstRadio( |
298 &adapter_param, &temp_adapter_handle); | 298 &adapter_param, &temp_adapter_handle); |
299 | 299 |
300 if (handle) { | 300 if (handle) { |
301 adapter_handle_.Set(temp_adapter_handle); | 301 adapter_handle_.Set(temp_adapter_handle); |
302 GetKnownDevices(); | 302 GetKnownDevices(); |
303 BluetoothFindRadioClose(handle); | 303 BluetoothFindRadioClose(handle); |
304 } | 304 } |
305 | 305 |
306 PostAdapterStateToUi(); | 306 PostAdapterStateToUi(); |
307 } | 307 } |
308 | 308 |
309 // Re-poll. | 309 // Re-poll. |
310 bluetooth_task_runner_->PostDelayedTask( | 310 bluetooth_task_runner_->PostDelayedTask( |
311 FROM_HERE, | 311 FROM_HERE, |
312 base::Bind(&BluetoothTaskManagerWin::PollAdapter, | 312 base::Bind(&BluetoothTaskManagerWin::PollAdapter, |
313 this), | 313 this), |
314 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); | 314 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); |
315 } | 315 } |
316 | 316 |
317 void BluetoothTaskManagerWin::PostAdapterStateToUi() { | 317 void BluetoothTaskManagerWin::PostAdapterStateToUi() { |
318 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 318 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
319 AdapterState* state = new AdapterState(); | 319 AdapterState* state = new AdapterState(); |
320 GetAdapterState(adapter_handle_, state); | 320 GetAdapterState(adapter_handle_.Get(), state); |
321 ui_task_runner_->PostTask( | 321 ui_task_runner_->PostTask( |
322 FROM_HERE, | 322 FROM_HERE, |
323 base::Bind(&BluetoothTaskManagerWin::OnAdapterStateChanged, | 323 base::Bind(&BluetoothTaskManagerWin::OnAdapterStateChanged, |
324 this, | 324 this, |
325 base::Owned(state))); | 325 base::Owned(state))); |
326 } | 326 } |
327 | 327 |
328 void BluetoothTaskManagerWin::SetPowered( | 328 void BluetoothTaskManagerWin::SetPowered( |
329 bool powered, | 329 bool powered, |
330 const base::Closure& callback, | 330 const base::Closure& callback, |
331 const BluetoothAdapter::ErrorCallback& error_callback) { | 331 const BluetoothAdapter::ErrorCallback& error_callback) { |
332 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 332 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
333 bool success = false; | 333 bool success = false; |
334 if (adapter_handle_) { | 334 if (adapter_handle_.IsValid()) { |
335 if (!powered) | 335 if (!powered) |
336 BluetoothEnableDiscovery(adapter_handle_, false); | 336 BluetoothEnableDiscovery(adapter_handle_.Get(), false); |
337 success = !!BluetoothEnableIncomingConnections(adapter_handle_, powered); | 337 success = |
| 338 !!BluetoothEnableIncomingConnections(adapter_handle_.Get(), powered); |
338 } | 339 } |
339 | 340 |
340 if (success) { | 341 if (success) { |
341 PostAdapterStateToUi(); | 342 PostAdapterStateToUi(); |
342 ui_task_runner_->PostTask(FROM_HERE, callback); | 343 ui_task_runner_->PostTask(FROM_HERE, callback); |
343 } else { | 344 } else { |
344 ui_task_runner_->PostTask(FROM_HERE, error_callback); | 345 ui_task_runner_->PostTask(FROM_HERE, error_callback); |
345 } | 346 } |
346 } | 347 } |
347 | 348 |
348 void BluetoothTaskManagerWin::StartDiscovery() { | 349 void BluetoothTaskManagerWin::StartDiscovery() { |
349 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 350 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
350 ui_task_runner_->PostTask( | 351 ui_task_runner_->PostTask( |
351 FROM_HERE, | 352 FROM_HERE, |
352 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStarted, | 353 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStarted, |
353 this, | 354 this, |
354 !!adapter_handle_)); | 355 adapter_handle_.IsValid())); |
355 if (!adapter_handle_) | 356 if (!adapter_handle_.IsValid()) |
356 return; | 357 return; |
357 discovering_ = true; | 358 discovering_ = true; |
358 | 359 |
359 DiscoverDevices(1); | 360 DiscoverDevices(1); |
360 } | 361 } |
361 | 362 |
362 void BluetoothTaskManagerWin::StopDiscovery() { | 363 void BluetoothTaskManagerWin::StopDiscovery() { |
363 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 364 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
364 discovering_ = false; | 365 discovering_ = false; |
365 ui_task_runner_->PostTask( | 366 ui_task_runner_->PostTask( |
366 FROM_HERE, | 367 FROM_HERE, |
367 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this)); | 368 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this)); |
368 } | 369 } |
369 | 370 |
370 void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) { | 371 void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) { |
371 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 372 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
372 if (!discovering_ || !adapter_handle_) { | 373 if (!discovering_ || !adapter_handle_.IsValid()) { |
373 ui_task_runner_->PostTask( | 374 ui_task_runner_->PostTask( |
374 FROM_HERE, | 375 FROM_HERE, |
375 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this)); | 376 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this)); |
376 return; | 377 return; |
377 } | 378 } |
378 | 379 |
379 scoped_ptr<ScopedVector<DeviceState> > device_list( | 380 scoped_ptr<ScopedVector<DeviceState> > device_list( |
380 new ScopedVector<DeviceState>()); | 381 new ScopedVector<DeviceState>()); |
381 if (SearchDevices(timeout_multiplier, false, device_list.get())) { | 382 if (SearchDevices(timeout_multiplier, false, device_list.get())) { |
382 ui_task_runner_->PostTask( | 383 ui_task_runner_->PostTask( |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 ++iter2) { | 649 ++iter2) { |
649 ServiceRecordState* service_state = new ServiceRecordState(); | 650 ServiceRecordState* service_state = new ServiceRecordState(); |
650 service_state->gatt_uuid = | 651 service_state->gatt_uuid = |
651 BluetoothLowEnergyUuidToBluetoothUuid((*iter2)->uuid); | 652 BluetoothLowEnergyUuidToBluetoothUuid((*iter2)->uuid); |
652 service_record_states->push_back(service_state); | 653 service_record_states->push_back(service_state); |
653 } | 654 } |
654 return true; | 655 return true; |
655 } | 656 } |
656 | 657 |
657 } // namespace device | 658 } // namespace device |
OLD | NEW |