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

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

Issue 2606823002: Remove base::ScopedPtrHashMap from device/. (Closed)
Patch Set: one last fix Created 3 years, 11 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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "dbus/bus.h" 18 #include "dbus/bus.h"
18 #include "device/bluetooth/bluetooth_socket.h" 19 #include "device/bluetooth/bluetooth_socket.h"
19 #include "device/bluetooth/bluetooth_socket_thread.h" 20 #include "device/bluetooth/bluetooth_socket_thread.h"
20 #include "device/bluetooth/bluetooth_uuid.h" 21 #include "device/bluetooth/bluetooth_uuid.h"
21 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 22 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
22 #include "device/bluetooth/bluez/bluetooth_gatt_connection_bluez.h" 23 #include "device/bluetooth/bluez/bluetooth_gatt_connection_bluez.h"
23 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" 24 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ->GetBluetoothGattServiceClient() 174 ->GetBluetoothGattServiceClient()
174 ->RemoveObserver(this); 175 ->RemoveObserver(this);
175 176
176 // Copy the GATT services list here and clear the original so that when we 177 // Copy the GATT services list here and clear the original so that when we
177 // send GattServiceRemoved(), GetGattServices() returns no services. 178 // send GattServiceRemoved(), GetGattServices() returns no services.
178 GattServiceMap gatt_services_swapped; 179 GattServiceMap gatt_services_swapped;
179 gatt_services_swapped.swap(gatt_services_); 180 gatt_services_swapped.swap(gatt_services_);
180 for (const auto& iter : gatt_services_swapped) { 181 for (const auto& iter : gatt_services_swapped) {
181 DCHECK(adapter()); 182 DCHECK(adapter());
182 adapter()->NotifyGattServiceRemoved( 183 adapter()->NotifyGattServiceRemoved(
183 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter.second)); 184 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter.second.get()));
184 } 185 }
185 } 186 }
186 187
187 uint32_t BluetoothDeviceBlueZ::GetBluetoothClass() const { 188 uint32_t BluetoothDeviceBlueZ::GetBluetoothClass() const {
188 bluez::BluetoothDeviceClient::Properties* properties = 189 bluez::BluetoothDeviceClient::Properties* properties =
189 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( 190 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
190 object_path_); 191 object_path_);
191 DCHECK(properties); 192 DCHECK(properties);
192 193
193 return properties->bluetooth_class.value(); 194 return properties->bluetooth_class.value();
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 if (properties->device.value() != object_path_) { 672 if (properties->device.value() != object_path_) {
672 VLOG(2) << "Remote GATT service does not belong to this device."; 673 VLOG(2) << "Remote GATT service does not belong to this device.";
673 return; 674 return;
674 } 675 }
675 676
676 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); 677 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress();
677 678
678 BluetoothRemoteGattServiceBlueZ* service = 679 BluetoothRemoteGattServiceBlueZ* service =
679 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path); 680 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path);
680 681
681 gatt_services_.set(service->GetIdentifier(), 682 gatt_services_[service->GetIdentifier()] = base::WrapUnique(service);
682 std::unique_ptr<BluetoothRemoteGattService>(service));
683 DCHECK(service->object_path() == object_path); 683 DCHECK(service->object_path() == object_path);
684 DCHECK(service->GetUUID().IsValid()); 684 DCHECK(service->GetUUID().IsValid());
685 685
686 DCHECK(adapter()); 686 DCHECK(adapter());
687 adapter()->NotifyGattServiceAdded(service); 687 adapter()->NotifyGattServiceAdded(service);
688 } 688 }
689 689
690 void BluetoothDeviceBlueZ::GattServiceRemoved( 690 void BluetoothDeviceBlueZ::GattServiceRemoved(
691 const dbus::ObjectPath& object_path) { 691 const dbus::ObjectPath& object_path) {
692 GattServiceMap::const_iterator iter = 692 auto iter = gatt_services_.find(object_path.value());
693 gatt_services_.find(object_path.value());
694 if (iter == gatt_services_.end()) { 693 if (iter == gatt_services_.end()) {
695 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); 694 VLOG(3) << "Unknown GATT service removed: " << object_path.value();
696 return; 695 return;
697 } 696 }
698 697
699 BluetoothRemoteGattServiceBlueZ* service = 698 BluetoothRemoteGattServiceBlueZ* service =
700 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second); 699 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second.get());
701 700
702 VLOG(1) << "Removing remote GATT service with UUID: '" 701 VLOG(1) << "Removing remote GATT service with UUID: '"
703 << service->GetUUID().canonical_value() 702 << service->GetUUID().canonical_value()
704 << "' from device: " << GetAddress(); 703 << "' from device: " << GetAddress();
705 704
706 DCHECK(service->object_path() == object_path); 705 DCHECK(service->object_path() == object_path);
707 std::unique_ptr<BluetoothRemoteGattService> scoped_service = 706 std::unique_ptr<BluetoothRemoteGattService> scoped_service =
708 gatt_services_.take_and_erase(iter->first); 707 std::move(gatt_services_[object_path.value()]);
708 gatt_services_.erase(iter);
709 709
710 DCHECK(adapter()); 710 DCHECK(adapter());
711 discovery_complete_notified_.erase(service); 711 discovery_complete_notified_.erase(service);
712 adapter()->NotifyGattServiceRemoved(service); 712 adapter()->NotifyGattServiceRemoved(service);
713 } 713 }
714 714
715 void BluetoothDeviceBlueZ::UpdateGattServices( 715 void BluetoothDeviceBlueZ::UpdateGattServices(
716 const dbus::ObjectPath& object_path) { 716 const dbus::ObjectPath& object_path) {
717 if (object_path != object_path_) { 717 if (object_path != object_path_) {
718 // No need to update map if update is for a different device. 718 // No need to update map if update is for a different device.
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, 944 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback,
945 const std::string& error_name, 945 const std::string& error_name,
946 const std::string& error_message) { 946 const std::string& error_message) {
947 LOG(WARNING) << object_path_.value() 947 LOG(WARNING) << object_path_.value()
948 << ": Failed to remove device: " << error_name << ": " 948 << ": Failed to remove device: " << error_name << ": "
949 << error_message; 949 << error_message;
950 error_callback.Run(); 950 error_callback.Run();
951 } 951 }
952 952
953 } // namespace bluez 953 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698