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

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 2063353002: device/bluetooth: split out transport enum (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: renaming header, moving TransportMask back into filter Created 4 years, 6 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_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> 7 #import <IOBluetooth/objc/IOBluetoothDevice.h>
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> 8 #import <IOBluetooth/objc/IOBluetoothHostController.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "base/sequenced_task_runner.h" 22 #include "base/sequenced_task_runner.h"
23 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
24 #include "base/strings/sys_string_conversions.h" 24 #include "base/strings/sys_string_conversions.h"
25 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
26 #include "base/time/time.h" 26 #include "base/time/time.h"
27 #include "device/bluetooth/bluetooth_classic_device_mac.h" 27 #include "device/bluetooth/bluetooth_classic_device_mac.h"
28 #include "device/bluetooth/bluetooth_discovery_session.h" 28 #include "device/bluetooth/bluetooth_discovery_session.h"
29 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" 29 #include "device/bluetooth/bluetooth_discovery_session_outcome.h"
30 #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h" 30 #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h"
31 #include "device/bluetooth/bluetooth_socket_mac.h" 31 #include "device/bluetooth/bluetooth_socket_mac.h"
32 #include "device/bluetooth/bluetooth_types.h"
32 33
33 namespace { 34 namespace {
34 35
35 // The frequency with which to poll the adapter for updates. 36 // The frequency with which to poll the adapter for updates.
36 const int kPollIntervalMs = 500; 37 const int kPollIntervalMs = 500;
37 38
38 } // namespace 39 } // namespace
39 40
40 namespace device { 41 namespace device {
41 42
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 315 }
315 316
316 if (num_discovery_sessions_ == 0) { 317 if (num_discovery_sessions_ == 0) {
317 DVLOG(1) << "No active discovery sessions. Returning error."; 318 DVLOG(1) << "No active discovery sessions. Returning error.";
318 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_ACTIVE); 319 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_ACTIVE);
319 return; 320 return;
320 } 321 }
321 322
322 // Default to dual discovery if |discovery_filter| is NULL. 323 // Default to dual discovery if |discovery_filter| is NULL.
323 BluetoothDiscoveryFilter::TransportMask transport = 324 BluetoothDiscoveryFilter::TransportMask transport =
324 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL; 325 BluetoothTransport::TRANSPORT_DUAL;
325 if (discovery_filter) 326 if (discovery_filter)
326 transport = discovery_filter->GetTransport(); 327 transport = discovery_filter->GetTransport();
327 328
328 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC) { 329 if (transport & BluetoothTransport::TRANSPORT_CLASSIC) {
329 if (!classic_discovery_manager_->StopDiscovery()) { 330 if (!classic_discovery_manager_->StopDiscovery()) {
330 DVLOG(1) << "Failed to stop classic discovery"; 331 DVLOG(1) << "Failed to stop classic discovery";
331 // TODO: Provide a more precise error here. 332 // TODO: Provide a more precise error here.
332 error_callback.Run(UMABluetoothDiscoverySessionOutcome::UNKNOWN); 333 error_callback.Run(UMABluetoothDiscoverySessionOutcome::UNKNOWN);
333 return; 334 return;
334 } 335 }
335 } 336 }
336 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_LE) { 337 if (transport & BluetoothTransport::TRANSPORT_LE) {
337 if (IsLowEnergyAvailable()) 338 if (IsLowEnergyAvailable())
338 low_energy_discovery_manager_->StopDiscovery(); 339 low_energy_discovery_manager_->StopDiscovery();
339 } 340 }
340 341
341 DVLOG(1) << "Discovery stopped"; 342 DVLOG(1) << "Discovery stopped";
342 num_discovery_sessions_--; 343 num_discovery_sessions_--;
343 callback.Run(); 344 callback.Run();
344 } 345 }
345 346
346 void BluetoothAdapterMac::SetDiscoveryFilter( 347 void BluetoothAdapterMac::SetDiscoveryFilter(
347 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter, 348 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
348 const base::Closure& callback, 349 const base::Closure& callback,
349 const DiscoverySessionErrorCallback& error_callback) { 350 const DiscoverySessionErrorCallback& error_callback) {
350 NOTIMPLEMENTED(); 351 NOTIMPLEMENTED();
351 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); 352 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED);
352 } 353 }
353 354
354 bool BluetoothAdapterMac::StartDiscovery( 355 bool BluetoothAdapterMac::StartDiscovery(
355 BluetoothDiscoveryFilter* discovery_filter) { 356 BluetoothDiscoveryFilter* discovery_filter) {
356 // Default to dual discovery if |discovery_filter| is NULL. IOBluetooth seems 357 // Default to dual discovery if |discovery_filter| is NULL. IOBluetooth seems
357 // allow starting low energy and classic discovery at once. 358 // allow starting low energy and classic discovery at once.
358 BluetoothDiscoveryFilter::TransportMask transport = 359 BluetoothDiscoveryFilter::TransportMask transport =
359 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL; 360 BluetoothTransport::TRANSPORT_DUAL;
360 if (discovery_filter) 361 if (discovery_filter)
361 transport = discovery_filter->GetTransport(); 362 transport = discovery_filter->GetTransport();
362 363
363 if ((transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC) && 364 if ((transport & BluetoothTransport::TRANSPORT_CLASSIC) &&
364 !classic_discovery_manager_->IsDiscovering()) { 365 !classic_discovery_manager_->IsDiscovering()) {
365 // TODO(krstnmnlsn): If a classic discovery session is already running then 366 // TODO(krstnmnlsn): If a classic discovery session is already running then
366 // we should update its filter. crbug.com/498056 367 // we should update its filter. crbug.com/498056
367 if (!classic_discovery_manager_->StartDiscovery()) { 368 if (!classic_discovery_manager_->StartDiscovery()) {
368 DVLOG(1) << "Failed to add a classic discovery session"; 369 DVLOG(1) << "Failed to add a classic discovery session";
369 return false; 370 return false;
370 } 371 }
371 } 372 }
372 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_LE) { 373 if (transport & BluetoothTransport::TRANSPORT_LE) {
373 // Begin a low energy discovery session or update it if one is already 374 // Begin a low energy discovery session or update it if one is already
374 // running. 375 // running.
375 if (IsLowEnergyAvailable()) 376 if (IsLowEnergyAvailable())
376 low_energy_discovery_manager_->StartDiscovery( 377 low_energy_discovery_manager_->StartDiscovery(
377 BluetoothDevice::UUIDList()); 378 BluetoothDevice::UUIDList());
378 } 379 }
379 return true; 380 return true;
380 } 381 }
381 382
382 void BluetoothAdapterMac::Init() { 383 void BluetoothAdapterMac::Init() {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 std::string device_address = 625 std::string device_address =
625 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 626 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
626 DevicesMap::const_iterator iter = devices_.find(device_address); 627 DevicesMap::const_iterator iter = devices_.find(device_address);
627 if (iter == devices_.end()) { 628 if (iter == devices_.end()) {
628 return nil; 629 return nil;
629 } 630 }
630 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 631 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
631 } 632 }
632 633
633 } // namespace device 634 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698