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

Side by Side Diff: device/bluetooth/bluez/bluetooth_device_bluez.cc

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Mac bustage Created 3 years, 12 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/bluez/bluetooth_device_bluez.h" 5 #include "device/bluetooth/bluez/bluetooth_device_bluez.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ->GetBluetoothGattServiceClient() 173 ->GetBluetoothGattServiceClient()
174 ->RemoveObserver(this); 174 ->RemoveObserver(this);
175 175
176 // Copy the GATT services list here and clear the original so that when we 176 // Copy the GATT services list here and clear the original so that when we
177 // send GattServiceRemoved(), GetGattServices() returns no services. 177 // send GattServiceRemoved(), GetGattServices() returns no services.
178 GattServiceMap gatt_services_swapped; 178 GattServiceMap gatt_services_swapped;
179 gatt_services_swapped.swap(gatt_services_); 179 gatt_services_swapped.swap(gatt_services_);
180 for (const auto& iter : gatt_services_swapped) { 180 for (const auto& iter : gatt_services_swapped) {
181 DCHECK(adapter()); 181 DCHECK(adapter());
182 adapter()->NotifyGattServiceRemoved( 182 adapter()->NotifyGattServiceRemoved(
183 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter.second)); 183 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter.second.get()));
184 } 184 }
185 } 185 }
186 186
187 uint32_t BluetoothDeviceBlueZ::GetBluetoothClass() const { 187 uint32_t BluetoothDeviceBlueZ::GetBluetoothClass() const {
188 bluez::BluetoothDeviceClient::Properties* properties = 188 bluez::BluetoothDeviceClient::Properties* properties =
189 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( 189 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
190 object_path_); 190 object_path_);
191 DCHECK(properties); 191 DCHECK(properties);
192 192
193 return properties->bluetooth_class.value(); 193 return properties->bluetooth_class.value();
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 ->GetBluetoothGattServiceClient() 668 ->GetBluetoothGattServiceClient()
669 ->GetProperties(object_path); 669 ->GetProperties(object_path);
670 DCHECK(properties); 670 DCHECK(properties);
671 if (properties->device.value() != object_path_) { 671 if (properties->device.value() != object_path_) {
672 VLOG(2) << "Remote GATT service does not belong to this device."; 672 VLOG(2) << "Remote GATT service does not belong to this device.";
673 return; 673 return;
674 } 674 }
675 675
676 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); 676 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress();
677 677
678 BluetoothRemoteGattServiceBlueZ* service = 678 std::unique_ptr<device::BluetoothRemoteGattService> service(
679 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path); 679 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path));
680 680 auto insertion = gatt_services_.insert(
681 gatt_services_.set(service->GetIdentifier(), 681 std::make_pair(service->GetIdentifier(), std::move(service)));
682 std::unique_ptr<BluetoothRemoteGattService>(service)); 682 if (!insertion.second) {
683 DCHECK(service->object_path() == object_path); 683 // insertion failed.
684 DCHECK(service->GetUUID().IsValid()); 684 VLOG(1) << "Insertion of new remote GATT service failed for device: "
685 << GetAddress();
686 return;
687 }
688 BluetoothRemoteGattServiceBlueZ* bluez =
689 static_cast<BluetoothRemoteGattServiceBlueZ*>(
690 insertion.first->second.get());
691 DCHECK(bluez->object_path() == object_path);
692 DCHECK(bluez->GetUUID().IsValid());
685 693
686 DCHECK(adapter()); 694 DCHECK(adapter());
687 adapter()->NotifyGattServiceAdded(service); 695 adapter()->NotifyGattServiceAdded(bluez);
688 } 696 }
689 697
690 void BluetoothDeviceBlueZ::GattServiceRemoved( 698 void BluetoothDeviceBlueZ::GattServiceRemoved(
691 const dbus::ObjectPath& object_path) { 699 const dbus::ObjectPath& object_path) {
692 GattServiceMap::const_iterator iter = 700 auto iter = gatt_services_.find(object_path.value());
693 gatt_services_.find(object_path.value());
694 if (iter == gatt_services_.end()) { 701 if (iter == gatt_services_.end()) {
695 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); 702 VLOG(3) << "Unknown GATT service removed: " << object_path.value();
696 return; 703 return;
697 } 704 }
705 // Hold onto the service so that we can erase it safely.
706 auto scoped_service = std::move(iter->second);
707 gatt_services_.erase(iter);
708 discovery_complete_notified_.erase(scoped_service.get());
698 709
699 BluetoothRemoteGattServiceBlueZ* service = 710 BluetoothRemoteGattServiceBlueZ* bluez =
700 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second); 711 static_cast<BluetoothRemoteGattServiceBlueZ*>(scoped_service.get());
701 712 DCHECK(bluez->object_path() == object_path);
702 VLOG(1) << "Removing remote GATT service with UUID: '" 713 VLOG(1) << "Removing remote GATT service with UUID: '"
703 << service->GetUUID().canonical_value() 714 << scoped_service->GetUUID().canonical_value()
704 << "' from device: " << GetAddress(); 715 << "' from device: " << GetAddress();
705 716
706 DCHECK(service->object_path() == object_path);
707 std::unique_ptr<BluetoothRemoteGattService> scoped_service =
708 gatt_services_.take_and_erase(iter->first);
709
710 DCHECK(adapter()); 717 DCHECK(adapter());
711 discovery_complete_notified_.erase(service); 718 adapter()->NotifyGattServiceRemoved(scoped_service.get());
712 adapter()->NotifyGattServiceRemoved(service);
713 } 719 }
714 720
715 void BluetoothDeviceBlueZ::UpdateGattServices( 721 void BluetoothDeviceBlueZ::UpdateGattServices(
716 const dbus::ObjectPath& object_path) { 722 const dbus::ObjectPath& object_path) {
717 if (object_path != object_path_) { 723 if (object_path != object_path_) {
718 // No need to update map if update is for a different device. 724 // No need to update map if update is for a different device.
719 return; 725 return;
720 } 726 }
721 727
722 DCHECK(IsGattServicesDiscoveryComplete()); 728 DCHECK(IsGattServicesDiscoveryComplete());
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, 950 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback,
945 const std::string& error_name, 951 const std::string& error_name,
946 const std::string& error_message) { 952 const std::string& error_message) {
947 LOG(WARNING) << object_path_.value() 953 LOG(WARNING) << object_path_.value()
948 << ": Failed to remove device: " << error_name << ": " 954 << ": Failed to remove device: " << error_name << ": "
949 << error_message; 955 << error_message;
950 error_callback.Run(); 956 error_callback.Run();
951 } 957 }
952 958
953 } // namespace bluez 959 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698