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

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: fixing new use in components/arc/bluetooth 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
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/mac/mac_util.h" 18 #include "base/mac/mac_util.h"
19 #include "base/mac/sdk_forward_declarations.h" 19 #include "base/mac/sdk_forward_declarations.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/profiler/scoped_tracker.h" 21 #include "base/profiler/scoped_tracker.h"
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_common.h"
28 #include "device/bluetooth/bluetooth_discovery_session.h" 29 #include "device/bluetooth/bluetooth_discovery_session.h"
29 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" 30 #include "device/bluetooth/bluetooth_discovery_session_outcome.h"
30 #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h" 31 #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h"
31 #include "device/bluetooth/bluetooth_socket_mac.h" 32 #include "device/bluetooth/bluetooth_socket_mac.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
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 return; 314 return;
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 BluetoothTransport transport = BLUETOOTH_TRANSPORT_DUAL;
324 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL;
325 if (discovery_filter) 325 if (discovery_filter)
326 transport = discovery_filter->GetTransport(); 326 transport = discovery_filter->GetTransport();
327 327
328 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC) { 328 if (transport & BLUETOOTH_TRANSPORT_CLASSIC) {
329 if (!classic_discovery_manager_->StopDiscovery()) { 329 if (!classic_discovery_manager_->StopDiscovery()) {
330 DVLOG(1) << "Failed to stop classic discovery"; 330 DVLOG(1) << "Failed to stop classic discovery";
331 // TODO: Provide a more precise error here. 331 // TODO: Provide a more precise error here.
332 error_callback.Run(UMABluetoothDiscoverySessionOutcome::UNKNOWN); 332 error_callback.Run(UMABluetoothDiscoverySessionOutcome::UNKNOWN);
333 return; 333 return;
334 } 334 }
335 } 335 }
336 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_LE) { 336 if (transport & BLUETOOTH_TRANSPORT_LE) {
337 if (IsLowEnergyAvailable()) 337 if (IsLowEnergyAvailable())
338 low_energy_discovery_manager_->StopDiscovery(); 338 low_energy_discovery_manager_->StopDiscovery();
339 } 339 }
340 340
341 DVLOG(1) << "Discovery stopped"; 341 DVLOG(1) << "Discovery stopped";
342 num_discovery_sessions_--; 342 num_discovery_sessions_--;
343 callback.Run(); 343 callback.Run();
344 } 344 }
345 345
346 void BluetoothAdapterMac::SetDiscoveryFilter( 346 void BluetoothAdapterMac::SetDiscoveryFilter(
347 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter, 347 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
348 const base::Closure& callback, 348 const base::Closure& callback,
349 const DiscoverySessionErrorCallback& error_callback) { 349 const DiscoverySessionErrorCallback& error_callback) {
350 NOTIMPLEMENTED(); 350 NOTIMPLEMENTED();
351 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); 351 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED);
352 } 352 }
353 353
354 bool BluetoothAdapterMac::StartDiscovery( 354 bool BluetoothAdapterMac::StartDiscovery(
355 BluetoothDiscoveryFilter* discovery_filter) { 355 BluetoothDiscoveryFilter* discovery_filter) {
356 // Default to dual discovery if |discovery_filter| is NULL. IOBluetooth seems 356 // Default to dual discovery if |discovery_filter| is NULL. IOBluetooth seems
357 // allow starting low energy and classic discovery at once. 357 // allow starting low energy and classic discovery at once.
358 BluetoothDiscoveryFilter::TransportMask transport = 358 BluetoothTransport transport = BLUETOOTH_TRANSPORT_DUAL;
359 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL;
360 if (discovery_filter) 359 if (discovery_filter)
361 transport = discovery_filter->GetTransport(); 360 transport = discovery_filter->GetTransport();
362 361
363 if ((transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC) && 362 if ((transport & BLUETOOTH_TRANSPORT_CLASSIC) &&
364 !classic_discovery_manager_->IsDiscovering()) { 363 !classic_discovery_manager_->IsDiscovering()) {
365 // TODO(krstnmnlsn): If a classic discovery session is already running then 364 // TODO(krstnmnlsn): If a classic discovery session is already running then
366 // we should update its filter. crbug.com/498056 365 // we should update its filter. crbug.com/498056
367 if (!classic_discovery_manager_->StartDiscovery()) { 366 if (!classic_discovery_manager_->StartDiscovery()) {
368 DVLOG(1) << "Failed to add a classic discovery session"; 367 DVLOG(1) << "Failed to add a classic discovery session";
369 return false; 368 return false;
370 } 369 }
371 } 370 }
372 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_LE) { 371 if (transport & BLUETOOTH_TRANSPORT_LE) {
373 // Begin a low energy discovery session or update it if one is already 372 // Begin a low energy discovery session or update it if one is already
374 // running. 373 // running.
375 if (IsLowEnergyAvailable()) 374 if (IsLowEnergyAvailable())
376 low_energy_discovery_manager_->StartDiscovery( 375 low_energy_discovery_manager_->StartDiscovery(
377 BluetoothDevice::UUIDList()); 376 BluetoothDevice::UUIDList());
378 } 377 }
379 return true; 378 return true;
380 } 379 }
381 380
382 void BluetoothAdapterMac::Init() { 381 void BluetoothAdapterMac::Init() {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 std::string device_address = 623 std::string device_address =
625 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 624 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
626 DevicesMap::const_iterator iter = devices_.find(device_address); 625 DevicesMap::const_iterator iter = devices_.find(device_address);
627 if (iter == devices_.end()) { 626 if (iter == devices_.end()) {
628 return nil; 627 return nil;
629 } 628 }
630 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 629 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
631 } 630 }
632 631
633 } // namespace device 632 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter.cc ('k') | device/bluetooth/bluetooth_adapter_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698