OLD | NEW |
---|---|
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 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/mac/mac_util.h" | |
16 #include "base/mac/sdk_forward_declarations.h" | 17 #include "base/mac/sdk_forward_declarations.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/profiler/scoped_tracker.h" | 19 #include "base/profiler/scoped_tracker.h" |
19 #include "base/sequenced_task_runner.h" | 20 #include "base/sequenced_task_runner.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/sys_string_conversions.h" | 22 #include "base/strings/sys_string_conversions.h" |
22 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
24 #include "device/bluetooth/bluetooth_classic_device_mac.h" | 25 #include "device/bluetooth/bluetooth_classic_device_mac.h" |
25 #include "device/bluetooth/bluetooth_discovery_session.h" | 26 #include "device/bluetooth/bluetooth_discovery_session.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
51 adapter->Init(); | 52 adapter->Init(); |
52 return adapter->weak_ptr_factory_.GetWeakPtr(); | 53 return adapter->weak_ptr_factory_.GetWeakPtr(); |
53 } | 54 } |
54 | 55 |
55 BluetoothAdapterMac::BluetoothAdapterMac() | 56 BluetoothAdapterMac::BluetoothAdapterMac() |
56 : BluetoothAdapter(), | 57 : BluetoothAdapter(), |
57 powered_(false), | 58 powered_(false), |
58 num_discovery_sessions_(0), | 59 num_discovery_sessions_(0), |
59 classic_discovery_manager_( | 60 classic_discovery_manager_( |
60 BluetoothDiscoveryManagerMac::CreateClassic(this)), | 61 BluetoothDiscoveryManagerMac::CreateClassic(this)), |
61 low_energy_discovery_manager_( | |
62 BluetoothLowEnergyDiscoveryManagerMac::Create(this)), | |
63 weak_ptr_factory_(this) { | 62 weak_ptr_factory_(this) { |
63 if (base::mac::IsOSYosemiteOrLater()) | |
64 low_energy_discovery_manager_.reset( | |
65 BluetoothLowEnergyDiscoveryManagerMac::Create(this)); | |
64 DCHECK(classic_discovery_manager_.get()); | 66 DCHECK(classic_discovery_manager_.get()); |
65 } | 67 } |
66 | 68 |
67 BluetoothAdapterMac::~BluetoothAdapterMac() { | 69 BluetoothAdapterMac::~BluetoothAdapterMac() { |
68 } | 70 } |
69 | 71 |
70 std::string BluetoothAdapterMac::GetAddress() const { | 72 std::string BluetoothAdapterMac::GetAddress() const { |
71 return address_; | 73 return address_; |
72 } | 74 } |
73 | 75 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 } | 107 } |
106 | 108 |
107 void BluetoothAdapterMac::SetDiscoverable( | 109 void BluetoothAdapterMac::SetDiscoverable( |
108 bool discoverable, | 110 bool discoverable, |
109 const base::Closure& callback, | 111 const base::Closure& callback, |
110 const ErrorCallback& error_callback) { | 112 const ErrorCallback& error_callback) { |
111 NOTIMPLEMENTED(); | 113 NOTIMPLEMENTED(); |
112 } | 114 } |
113 | 115 |
114 bool BluetoothAdapterMac::IsDiscovering() const { | 116 bool BluetoothAdapterMac::IsDiscovering() const { |
115 return (classic_discovery_manager_->IsDiscovering() || | 117 bool is_discovering = classic_discovery_manager_->IsDiscovering(); |
116 low_energy_discovery_manager_->IsDiscovering()); | 118 if (base::mac::IsOSYosemiteOrLater()) |
119 is_discovering = | |
120 is_discovering || low_energy_discovery_manager_->IsDiscovering(); | |
scheib
2015/07/09 19:51:23
In many of these checks, perhaps just do a pointer
krstnmnlsn
2015/07/10 17:17:46
Ended up using IsLowEnergyAvailable() as a sort of
| |
121 return is_discovering; | |
117 } | 122 } |
118 | 123 |
119 void BluetoothAdapterMac::CreateRfcommService( | 124 void BluetoothAdapterMac::CreateRfcommService( |
120 const BluetoothUUID& uuid, | 125 const BluetoothUUID& uuid, |
121 const ServiceOptions& options, | 126 const ServiceOptions& options, |
122 const CreateServiceCallback& callback, | 127 const CreateServiceCallback& callback, |
123 const CreateServiceErrorCallback& error_callback) { | 128 const CreateServiceErrorCallback& error_callback) { |
124 scoped_refptr<BluetoothSocketMac> socket = BluetoothSocketMac::CreateSocket(); | 129 scoped_refptr<BluetoothSocketMac> socket = BluetoothSocketMac::CreateSocket(); |
125 socket->ListenUsingRfcomm( | 130 socket->ListenUsingRfcomm( |
126 this, uuid, options, base::Bind(callback, socket), error_callback); | 131 this, uuid, options, base::Bind(callback, socket), error_callback); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 transport = discovery_filter->GetTransport(); | 244 transport = discovery_filter->GetTransport(); |
240 | 245 |
241 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC) { | 246 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC) { |
242 if (!classic_discovery_manager_->StopDiscovery()) { | 247 if (!classic_discovery_manager_->StopDiscovery()) { |
243 DVLOG(1) << "Failed to stop classic discovery"; | 248 DVLOG(1) << "Failed to stop classic discovery"; |
244 error_callback.Run(); | 249 error_callback.Run(); |
245 return; | 250 return; |
246 } | 251 } |
247 } | 252 } |
248 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_LE) { | 253 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_LE) { |
249 low_energy_discovery_manager_->StopDiscovery(); | 254 if (base::mac::IsOSYosemiteOrLater()) |
255 low_energy_discovery_manager_->StopDiscovery(); | |
250 } | 256 } |
251 | 257 |
252 DVLOG(1) << "Discovery stopped"; | 258 DVLOG(1) << "Discovery stopped"; |
253 num_discovery_sessions_--; | 259 num_discovery_sessions_--; |
254 callback.Run(); | 260 callback.Run(); |
255 } | 261 } |
256 | 262 |
257 void BluetoothAdapterMac::SetDiscoveryFilter( | 263 void BluetoothAdapterMac::SetDiscoveryFilter( |
258 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 264 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
259 const base::Closure& callback, | 265 const base::Closure& callback, |
(...skipping 16 matching lines...) Expand all Loading... | |
276 // TODO(krstnmnlsn): If a classic discovery session is already running then | 282 // TODO(krstnmnlsn): If a classic discovery session is already running then |
277 // we should update its filter. crbug.com/498056 | 283 // we should update its filter. crbug.com/498056 |
278 if (!classic_discovery_manager_->StartDiscovery()) { | 284 if (!classic_discovery_manager_->StartDiscovery()) { |
279 DVLOG(1) << "Failed to add a classic discovery session"; | 285 DVLOG(1) << "Failed to add a classic discovery session"; |
280 return false; | 286 return false; |
281 } | 287 } |
282 } | 288 } |
283 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_LE) { | 289 if (transport & BluetoothDiscoveryFilter::Transport::TRANSPORT_LE) { |
284 // Begin a low energy discovery session or update it if one is already | 290 // Begin a low energy discovery session or update it if one is already |
285 // running. | 291 // running. |
286 low_energy_discovery_manager_->StartDiscovery(BluetoothDevice::UUIDList()); | 292 if (base::mac::IsOSYosemiteOrLater()) |
293 low_energy_discovery_manager_->StartDiscovery( | |
294 BluetoothDevice::UUIDList()); | |
287 } | 295 } |
288 return true; | 296 return true; |
289 } | 297 } |
290 | 298 |
291 void BluetoothAdapterMac::Init() { | 299 void BluetoothAdapterMac::Init() { |
292 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 300 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
293 PollAdapter(); | 301 PollAdapter(); |
294 } | 302 } |
295 | 303 |
296 void BluetoothAdapterMac::InitForTest( | 304 void BluetoothAdapterMac::InitForTest( |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 DCHECK_EQ(num_removed, 1U); | 426 DCHECK_EQ(num_removed, 1U); |
419 } | 427 } |
420 | 428 |
421 // Add any new paired devices. | 429 // Add any new paired devices. |
422 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { | 430 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { |
423 ClassicDeviceAdded(device); | 431 ClassicDeviceAdded(device); |
424 } | 432 } |
425 } | 433 } |
426 | 434 |
427 } // namespace device | 435 } // namespace device |
OLD | NEW |