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

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

Issue 1216583003: Adding Hashed Address to BluetoothLowEnergyDeviceMac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timeinfo
Patch Set: Created 5 years, 5 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 9
10 #include <string> 10 #include <string>
(...skipping 13 matching lines...) Expand all
24 #include "device/bluetooth/bluetooth_classic_device_mac.h" 24 #include "device/bluetooth/bluetooth_classic_device_mac.h"
25 #include "device/bluetooth/bluetooth_discovery_session.h" 25 #include "device/bluetooth/bluetooth_discovery_session.h"
26 #include "device/bluetooth/bluetooth_socket_mac.h" 26 #include "device/bluetooth/bluetooth_socket_mac.h"
27 #include "device/bluetooth/bluetooth_uuid.h" 27 #include "device/bluetooth/bluetooth_uuid.h"
28 28
29 namespace { 29 namespace {
30 30
31 // The frequency with which to poll the adapter for updates. 31 // The frequency with which to poll the adapter for updates.
32 const int kPollIntervalMs = 500; 32 const int kPollIntervalMs = 500;
33 33
34 // The length of time that must elapse since the last Inquiry response before a
35 // discovered Classic device is considered to be no longer available.
36 const NSTimeInterval kDiscoveryTimeoutSec = 3 * 60; // 3 minutes
37
38 } // namespace 34 } // namespace
39 35
40 namespace device { 36 namespace device {
41 37
38 const NSTimeInterval BluetoothAdapterMac::kDiscoveryTimeoutSec =
39 3 * 60; // 3 minutes
40
42 // static 41 // static
43 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( 42 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
44 const InitCallback& init_callback) { 43 const InitCallback& init_callback) {
45 return BluetoothAdapterMac::CreateAdapter(); 44 return BluetoothAdapterMac::CreateAdapter();
46 } 45 }
47 46
48 // static 47 // static
49 base::WeakPtr<BluetoothAdapter> BluetoothAdapterMac::CreateAdapter() { 48 base::WeakPtr<BluetoothAdapter> BluetoothAdapterMac::CreateAdapter() {
50 BluetoothAdapterMac* adapter = new BluetoothAdapterMac(); 49 BluetoothAdapterMac* adapter = new BluetoothAdapterMac();
51 adapter->Init(); 50 adapter->Init();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 288 }
290 289
291 void BluetoothAdapterMac::Init() { 290 void BluetoothAdapterMac::Init() {
292 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 291 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
293 PollAdapter(); 292 PollAdapter();
294 } 293 }
295 294
296 void BluetoothAdapterMac::InitForTest( 295 void BluetoothAdapterMac::InitForTest(
297 scoped_refptr<base::SequencedTaskRunner> ui_task_runner) { 296 scoped_refptr<base::SequencedTaskRunner> ui_task_runner) {
298 ui_task_runner_ = ui_task_runner; 297 ui_task_runner_ = ui_task_runner;
299 PollAdapter();
300 } 298 }
301 299
302 void BluetoothAdapterMac::PollAdapter() { 300 void BluetoothAdapterMac::PollAdapter() {
303 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 301 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181
304 // is fixed. 302 // is fixed.
305 tracked_objects::ScopedTracker tracking_profile1( 303 tracked_objects::ScopedTracker tracking_profile1(
306 FROM_HERE_WITH_EXPLICIT_FUNCTION( 304 FROM_HERE_WITH_EXPLICIT_FUNCTION(
307 "461181 BluetoothAdapterMac::PollAdapter::Start")); 305 "461181 BluetoothAdapterMac::PollAdapter::Start"));
308 bool was_present = IsPresent(); 306 bool was_present = IsPresent();
309 std::string address; 307 std::string address;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 if (powered_ != powered) { 350 if (powered_ != powered) {
353 powered_ = powered; 351 powered_ = powered;
354 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 352 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
355 AdapterPoweredChanged(this, powered_)); 353 AdapterPoweredChanged(this, powered_));
356 } 354 }
357 355
358 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 356 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181
359 // is fixed. 357 // is fixed.
360 tracked_objects::ScopedTracker tracking_profile5( 358 tracked_objects::ScopedTracker tracking_profile5(
361 FROM_HERE_WITH_EXPLICIT_FUNCTION( 359 FROM_HERE_WITH_EXPLICIT_FUNCTION(
362 "461181 BluetoothAdapterMac::PollAdapter::UpdateDevices")); 360 "461181 BluetoothAdapterMac::PollAdapter::RemoveTimedOutDevices"));
363 UpdateDevices(); 361 RemoveTimedOutDevices();
362
363 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181
364 // is fixed.
365 tracked_objects::ScopedTracker tracking_profile6(
366 FROM_HERE_WITH_EXPLICIT_FUNCTION(
367 "461181 BluetoothAdapterMac::PollAdapter::AddPairedDevices"));
368 AddPairedDevices();
364 369
365 ui_task_runner_->PostDelayedTask( 370 ui_task_runner_->PostDelayedTask(
366 FROM_HERE, 371 FROM_HERE,
367 base::Bind(&BluetoothAdapterMac::PollAdapter, 372 base::Bind(&BluetoothAdapterMac::PollAdapter,
368 weak_ptr_factory_.GetWeakPtr()), 373 weak_ptr_factory_.GetWeakPtr()),
369 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); 374 base::TimeDelta::FromMilliseconds(kPollIntervalMs));
370 } 375 }
371 376
372 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { 377 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) {
373 std::string device_address = 378 std::string device_address =
374 BluetoothClassicDeviceMac::GetDeviceAddress(device); 379 BluetoothClassicDeviceMac::GetDeviceAddress(device);
375 380
376 // Only notify observers once per device. 381 // Only notify observers once per device.
377 if (devices_.count(device_address)) 382 if (devices_.count(device_address))
378 return; 383 return;
379 384
380 devices_[device_address] = new BluetoothClassicDeviceMac(device); 385 devices_[device_address] = new BluetoothClassicDeviceMac(device);
381 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 386 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
382 observers_, 387 observers_,
383 DeviceAdded(this, devices_[device_address])); 388 DeviceAdded(this, devices_[device_address]));
384 } 389 }
385 390
386 // TODO(krstnmnlsn): This method to be implemented as soon as UpdateDevices can 391 // TODO(krstnmnlsn): Implement method.
scheib 2015/07/01 17:29:44 Have an issue number. The previous comment is prob
krstnmnlsn 2015/07/02 00:25:30 Sure. I removed the comment because as of this ch
387 // handle instances of LowEnergyBluetoothDevice in |devices_|. crbug.com/498009
388 void BluetoothAdapterMac::LowEnergyDeviceUpdated( 392 void BluetoothAdapterMac::LowEnergyDeviceUpdated(
389 CBPeripheral* peripheral, 393 CBPeripheral* peripheral,
390 NSDictionary* advertisementData, 394 NSDictionary* advertisementData,
391 int rssi) { 395 int rssi) {
392 } 396 }
393 397
394 void BluetoothAdapterMac::UpdateDevices() { 398 void BluetoothAdapterMac::RemoveTimedOutDevices() {
395 // Notify observers if any previously seen devices are no longer available, 399 // Notify observers if any previously seen devices are no longer available,
396 // i.e. if they are no longer paired, connected, nor recently discovered via 400 // i.e. if they are no longer paired, connected, nor recently discovered via
397 // an inquiry. 401 // an inquiry.
398 std::set<std::string> removed_devices; 402 std::set<std::string> removed_devices;
399 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) { 403 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) {
400 BluetoothDevice* device = it->second; 404 BluetoothDevice* device = it->second;
401 if (device->IsPaired() || device->IsConnected()) 405 if (device->IsPaired() || device->IsConnected())
402 continue; 406 continue;
403 407
404 NSDate* last_update_time = 408 NSDate* last_update_time =
405 static_cast<BluetoothDeviceMac*>(device)->GetLastUpdateTime(); 409 static_cast<BluetoothDeviceMac*>(device)->GetLastUpdateTime();
406 if (last_update_time && 410 if (last_update_time &&
407 -[last_update_time timeIntervalSinceNow] < kDiscoveryTimeoutSec) 411 -[last_update_time timeIntervalSinceNow] < kDiscoveryTimeoutSec)
408 continue; 412 continue;
409 413
410 FOR_EACH_OBSERVER( 414 FOR_EACH_OBSERVER(
411 BluetoothAdapter::Observer, observers_, DeviceRemoved(this, device)); 415 BluetoothAdapter::Observer, observers_, DeviceRemoved(this, device));
412 delete device; 416 delete device;
413 removed_devices.insert(it->first); 417 removed_devices.insert(it->first);
414 // The device will be erased from the map in the loop immediately below. 418 // The device will be erased from the map in the loop immediately below.
415 } 419 }
416 for (const std::string& device_address : removed_devices) { 420 for (const std::string& device_address : removed_devices) {
417 size_t num_removed = devices_.erase(device_address); 421 size_t num_removed = devices_.erase(device_address);
418 DCHECK_EQ(num_removed, 1U); 422 DCHECK_EQ(num_removed, 1U);
419 } 423 }
424 }
420 425
426 void BluetoothAdapterMac::AddPairedDevices() {
421 // Add any new paired devices. 427 // Add any new paired devices.
422 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 428 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
423 ClassicDeviceAdded(device); 429 ClassicDeviceAdded(device);
424 } 430 }
425 } 431 }
426 432
427 } // namespace device 433 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698