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

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

Issue 2423793002: Remove usage of FOR_EACH_OBSERVER macro in device/ (Closed)
Patch Set: rebase Created 4 years, 2 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void BluetoothAdapterMac::ClassicDeviceFound(IOBluetoothDevice* device) { 227 void BluetoothAdapterMac::ClassicDeviceFound(IOBluetoothDevice* device) {
228 ClassicDeviceAdded(device); 228 ClassicDeviceAdded(device);
229 } 229 }
230 230
231 void BluetoothAdapterMac::ClassicDiscoveryStopped(bool unexpected) { 231 void BluetoothAdapterMac::ClassicDiscoveryStopped(bool unexpected) {
232 if (unexpected) { 232 if (unexpected) {
233 DVLOG(1) << "Discovery stopped unexpectedly"; 233 DVLOG(1) << "Discovery stopped unexpectedly";
234 num_discovery_sessions_ = 0; 234 num_discovery_sessions_ = 0;
235 MarkDiscoverySessionsAsInactive(); 235 MarkDiscoverySessionsAsInactive();
236 } 236 }
237 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 237 for (auto& observer : observers_)
238 observers_, 238 observer.AdapterDiscoveringChanged(this, false);
239 AdapterDiscoveringChanged(this, false));
240 } 239 }
241 240
242 void BluetoothAdapterMac::DeviceConnected(IOBluetoothDevice* device) { 241 void BluetoothAdapterMac::DeviceConnected(IOBluetoothDevice* device) {
243 // TODO(isherman): Investigate whether this method can be replaced with a call 242 // TODO(isherman): Investigate whether this method can be replaced with a call
244 // to +registerForConnectNotifications:selector:. 243 // to +registerForConnectNotifications:selector:.
245 DVLOG(1) << "Adapter registered a new connection from device with address: " 244 DVLOG(1) << "Adapter registered a new connection from device with address: "
246 << BluetoothClassicDeviceMac::GetDeviceAddress(device); 245 << BluetoothClassicDeviceMac::GetDeviceAddress(device);
247 ClassicDeviceAdded(device); 246 ClassicDeviceAdded(device);
248 } 247 }
249 248
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 DCHECK_EQ(0, num_discovery_sessions_); 290 DCHECK_EQ(0, num_discovery_sessions_);
292 291
293 if (!StartDiscovery(discovery_filter)) { 292 if (!StartDiscovery(discovery_filter)) {
294 // TODO: Provide a more precise error here. 293 // TODO: Provide a more precise error here.
295 error_callback.Run(UMABluetoothDiscoverySessionOutcome::UNKNOWN); 294 error_callback.Run(UMABluetoothDiscoverySessionOutcome::UNKNOWN);
296 return; 295 return;
297 } 296 }
298 297
299 DVLOG(1) << "Added a discovery session"; 298 DVLOG(1) << "Added a discovery session";
300 num_discovery_sessions_++; 299 num_discovery_sessions_++;
301 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 300 for (auto& observer : observers_)
302 observers_, 301 observer.AdapterDiscoveringChanged(this, true);
303 AdapterDiscoveringChanged(this, true));
304 callback.Run(); 302 callback.Run();
305 } 303 }
306 304
307 void BluetoothAdapterMac::RemoveDiscoverySession( 305 void BluetoothAdapterMac::RemoveDiscoverySession(
308 BluetoothDiscoveryFilter* discovery_filter, 306 BluetoothDiscoveryFilter* discovery_filter,
309 const base::Closure& callback, 307 const base::Closure& callback,
310 const DiscoverySessionErrorCallback& error_callback) { 308 const DiscoverySessionErrorCallback& error_callback) {
311 DVLOG(1) << __func__; 309 DVLOG(1) << __func__;
312 310
313 if (num_discovery_sessions_ > 1) { 311 if (num_discovery_sessions_ > 1) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 422
425 bool is_present = !address.empty(); 423 bool is_present = !address.empty();
426 address_ = address; 424 address_ = address;
427 425
428 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 426 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181
429 // is fixed. 427 // is fixed.
430 tracked_objects::ScopedTracker tracking_profile3( 428 tracked_objects::ScopedTracker tracking_profile3(
431 FROM_HERE_WITH_EXPLICIT_FUNCTION( 429 FROM_HERE_WITH_EXPLICIT_FUNCTION(
432 "461181 BluetoothAdapterMac::PollAdapter::AdapterPresentChanged")); 430 "461181 BluetoothAdapterMac::PollAdapter::AdapterPresentChanged"));
433 if (was_present != is_present) { 431 if (was_present != is_present) {
434 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 432 for (auto& observer : observers_)
435 AdapterPresentChanged(this, is_present)); 433 observer.AdapterPresentChanged(this, is_present);
436 } 434 }
437 435
438 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 436 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181
439 // is fixed. 437 // is fixed.
440 tracked_objects::ScopedTracker tracking_profile4( 438 tracked_objects::ScopedTracker tracking_profile4(
441 FROM_HERE_WITH_EXPLICIT_FUNCTION( 439 FROM_HERE_WITH_EXPLICIT_FUNCTION(
442 "461181 BluetoothAdapterMac::PollAdapter::AdapterPowerChanged")); 440 "461181 BluetoothAdapterMac::PollAdapter::AdapterPowerChanged"));
443 if (classic_powered_ != classic_powered) { 441 if (classic_powered_ != classic_powered) {
444 classic_powered_ = classic_powered; 442 classic_powered_ = classic_powered;
445 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 443 for (auto& observer : observers_)
446 AdapterPoweredChanged(this, classic_powered_)); 444 observer.AdapterPoweredChanged(this, classic_powered_);
447 } 445 }
448 446
449 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 447 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181
450 // is fixed. 448 // is fixed.
451 tracked_objects::ScopedTracker tracking_profile5( 449 tracked_objects::ScopedTracker tracking_profile5(
452 FROM_HERE_WITH_EXPLICIT_FUNCTION( 450 FROM_HERE_WITH_EXPLICIT_FUNCTION(
453 "461181 BluetoothAdapterMac::PollAdapter::RemoveTimedOutDevices")); 451 "461181 BluetoothAdapterMac::PollAdapter::RemoveTimedOutDevices"));
454 RemoveTimedOutDevices(); 452 RemoveTimedOutDevices();
455 453
456 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 454 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181
(...skipping 20 matching lines...) Expand all
477 if (device_classic != nullptr) { 475 if (device_classic != nullptr) {
478 VLOG(3) << "Updating classic device: " << device_classic->GetAddress(); 476 VLOG(3) << "Updating classic device: " << device_classic->GetAddress();
479 device_classic->UpdateTimestamp(); 477 device_classic->UpdateTimestamp();
480 return; 478 return;
481 } 479 }
482 480
483 device_classic = new BluetoothClassicDeviceMac(this, device); 481 device_classic = new BluetoothClassicDeviceMac(this, device);
484 devices_.set(device_address, base::WrapUnique(device_classic)); 482 devices_.set(device_address, base::WrapUnique(device_classic));
485 VLOG(1) << "Adding new classic device: " << device_classic->GetAddress(); 483 VLOG(1) << "Adding new classic device: " << device_classic->GetAddress();
486 484
487 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 485 for (auto& observer : observers_)
488 DeviceAdded(this, device_classic)); 486 observer.DeviceAdded(this, device_classic);
489 } 487 }
490 488
491 void BluetoothAdapterMac::LowEnergyDeviceUpdated( 489 void BluetoothAdapterMac::LowEnergyDeviceUpdated(
492 CBPeripheral* peripheral, 490 CBPeripheral* peripheral,
493 NSDictionary* advertisement_data, 491 NSDictionary* advertisement_data,
494 int rssi) { 492 int rssi) {
495 BluetoothLowEnergyDeviceMac* device_mac = 493 BluetoothLowEnergyDeviceMac* device_mac =
496 GetBluetoothLowEnergyDeviceMac(peripheral); 494 GetBluetoothLowEnergyDeviceMac(peripheral);
497 // If has no entry in the map, create new device and insert into |devices_|, 495 // If has no entry in the map, create new device and insert into |devices_|,
498 // otherwise update the existing device. 496 // otherwise update the existing device.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 553
556 device_mac->UpdateAdvertisementData( 554 device_mac->UpdateAdvertisementData(
557 BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids), 555 BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids),
558 std::move(service_data_map), 556 std::move(service_data_map),
559 tx_power == nil ? nullptr : &clamped_tx_power); 557 tx_power == nil ? nullptr : &clamped_tx_power);
560 558
561 if (is_new_device) { 559 if (is_new_device) {
562 std::string device_address = 560 std::string device_address =
563 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 561 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
564 devices_.add(device_address, std::unique_ptr<BluetoothDevice>(device_mac)); 562 devices_.add(device_address, std::unique_ptr<BluetoothDevice>(device_mac));
565 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 563 for (auto& observer : observers_)
566 DeviceAdded(this, device_mac)); 564 observer.DeviceAdded(this, device_mac);
567 } else { 565 } else {
568 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 566 for (auto& observer : observers_)
569 DeviceChanged(this, device_mac)); 567 observer.DeviceChanged(this, device_mac);
570 } 568 }
571 } 569 }
572 570
573 // TODO(krstnmnlsn): Implement. crbug.com/511025 571 // TODO(krstnmnlsn): Implement. crbug.com/511025
574 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {} 572 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {}
575 573
576 void BluetoothAdapterMac::AddPairedDevices() { 574 void BluetoothAdapterMac::AddPairedDevices() {
577 // Add any new paired devices. 575 // Add any new paired devices.
578 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 576 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
579 // pairedDevices sometimes includes unknown devices that are not paired. 577 // pairedDevices sometimes includes unknown devices that are not paired.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 std::string device_address = 646 std::string device_address =
649 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 647 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
650 DevicesMap::const_iterator iter = devices_.find(device_address); 648 DevicesMap::const_iterator iter = devices_.find(device_address);
651 if (iter == devices_.end()) { 649 if (iter == devices_.end()) {
652 return nil; 650 return nil;
653 } 651 }
654 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 652 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
655 } 653 }
656 654
657 } // namespace device 655 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_android.cc ('k') | device/bluetooth/bluetooth_adapter_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698