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

Side by Side Diff: device/bluetooth/dbus/fake_bluetooth_device_client.cc

Issue 1486333002: Kill ScopedPtrMap and friends (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/dbus/fake_bluetooth_device_client.h" 5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <sys/socket.h> 8 #include <sys/socket.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 properties->adapter.ReplaceValue( 281 properties->adapter.ReplaceValue(
282 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); 282 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
283 283
284 std::vector<std::string> uuids; 284 std::vector<std::string> uuids;
285 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); 285 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb");
286 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); 286 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb");
287 properties->uuids.ReplaceValue(uuids); 287 properties->uuids.ReplaceValue(uuids);
288 288
289 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); 289 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306");
290 290
291 properties_map_.insert(dbus::ObjectPath(kPairedDevicePath), 291 properties_map_.insert(std::make_pair(dbus::ObjectPath(kPairedDevicePath),
292 properties.Pass()); 292 std::move(properties)));
293 device_list_.push_back(dbus::ObjectPath(kPairedDevicePath)); 293 device_list_.push_back(dbus::ObjectPath(kPairedDevicePath));
294 294
295 properties.reset(new Properties(base::Bind( 295 properties.reset(new Properties(base::Bind(
296 &FakeBluetoothDeviceClient::OnPropertyChanged, base::Unretained(this), 296 &FakeBluetoothDeviceClient::OnPropertyChanged, base::Unretained(this),
297 dbus::ObjectPath(kPairedUnconnectableDevicePath)))); 297 dbus::ObjectPath(kPairedUnconnectableDevicePath))));
298 properties->address.ReplaceValue(kPairedUnconnectableDeviceAddress); 298 properties->address.ReplaceValue(kPairedUnconnectableDeviceAddress);
299 properties->bluetooth_class.ReplaceValue(kPairedUnconnectableDeviceClass); 299 properties->bluetooth_class.ReplaceValue(kPairedUnconnectableDeviceClass);
300 properties->name.ReplaceValue("Fake Device 2 (Unconnectable)"); 300 properties->name.ReplaceValue("Fake Device 2 (Unconnectable)");
301 properties->alias.ReplaceValue(kPairedUnconnectableDeviceName); 301 properties->alias.ReplaceValue(kPairedUnconnectableDeviceName);
302 properties->paired.ReplaceValue(true); 302 properties->paired.ReplaceValue(true);
303 properties->trusted.ReplaceValue(true); 303 properties->trusted.ReplaceValue(true);
304 properties->adapter.ReplaceValue( 304 properties->adapter.ReplaceValue(
305 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); 305 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
306 306
307 properties->uuids.ReplaceValue(uuids); 307 properties->uuids.ReplaceValue(uuids);
308 308
309 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); 309 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306");
310 310
311 properties_map_.insert(dbus::ObjectPath(kPairedUnconnectableDevicePath), 311 properties_map_.insert(std::make_pair(
312 properties.Pass()); 312 dbus::ObjectPath(kPairedUnconnectableDevicePath), std::move(properties)));
313 device_list_.push_back(dbus::ObjectPath(kPairedUnconnectableDevicePath)); 313 device_list_.push_back(dbus::ObjectPath(kPairedUnconnectableDevicePath));
314 } 314 }
315 315
316 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() {} 316 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() {}
317 317
318 void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) {} 318 void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) {}
319 319
320 void FakeBluetoothDeviceClient::AddObserver(Observer* observer) { 320 void FakeBluetoothDeviceClient::AddObserver(Observer* observer) {
321 observers_.AddObserver(observer); 321 observers_.AddObserver(observer);
322 } 322 }
323 323
324 void FakeBluetoothDeviceClient::RemoveObserver(Observer* observer) { 324 void FakeBluetoothDeviceClient::RemoveObserver(Observer* observer) {
325 observers_.RemoveObserver(observer); 325 observers_.RemoveObserver(observer);
326 } 326 }
327 327
328 std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter( 328 std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter(
329 const dbus::ObjectPath& adapter_path) { 329 const dbus::ObjectPath& adapter_path) {
330 if (adapter_path == 330 if (adapter_path ==
331 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) 331 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath))
332 return device_list_; 332 return device_list_;
333 else 333 else
334 return std::vector<dbus::ObjectPath>(); 334 return std::vector<dbus::ObjectPath>();
335 } 335 }
336 336
337 FakeBluetoothDeviceClient::Properties* FakeBluetoothDeviceClient::GetProperties( 337 FakeBluetoothDeviceClient::Properties* FakeBluetoothDeviceClient::GetProperties(
338 const dbus::ObjectPath& object_path) { 338 const dbus::ObjectPath& object_path) {
339 PropertiesMap::const_iterator iter = properties_map_.find(object_path); 339 PropertiesMap::const_iterator iter = properties_map_.find(object_path);
340 if (iter != properties_map_.end()) 340 if (iter != properties_map_.end())
341 return iter->second; 341 return iter->second.get();
342 return NULL; 342 return NULL;
343 } 343 }
344 344
345 FakeBluetoothDeviceClient::SimulatedPairingOptions* 345 FakeBluetoothDeviceClient::SimulatedPairingOptions*
346 FakeBluetoothDeviceClient::GetPairingOptions( 346 FakeBluetoothDeviceClient::GetPairingOptions(
347 const dbus::ObjectPath& object_path) { 347 const dbus::ObjectPath& object_path) {
348 PairingOptionsMap::const_iterator iter = 348 PairingOptionsMap::const_iterator iter =
349 pairing_options_map_.find(object_path); 349 pairing_options_map_.find(object_path);
350 if (iter != pairing_options_map_.end()) 350 if (iter != pairing_options_map_.end())
351 return iter->second; 351 return iter->second.get();
352 return iter != pairing_options_map_.end() ? iter->second : nullptr; 352 return iter != pairing_options_map_.end() ? iter->second.get() : nullptr;
353 } 353 }
354 354
355 void FakeBluetoothDeviceClient::Connect(const dbus::ObjectPath& object_path, 355 void FakeBluetoothDeviceClient::Connect(const dbus::ObjectPath& object_path,
356 const base::Closure& callback, 356 const base::Closure& callback,
357 const ErrorCallback& error_callback) { 357 const ErrorCallback& error_callback) {
358 VLOG(1) << "Connect: " << object_path.value(); 358 VLOG(1) << "Connect: " << object_path.value();
359 Properties* properties = GetProperties(object_path); 359 Properties* properties = GetProperties(object_path);
360 360
361 if (properties->connected.value() == true) { 361 if (properties->connected.value() == true) {
362 // Already connected. 362 // Already connected.
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 kConnectedTrustedNotPairedDeviceClass); 699 kConnectedTrustedNotPairedDeviceClass);
700 properties->trusted.ReplaceValue(true); 700 properties->trusted.ReplaceValue(true);
701 properties->connected.ReplaceValue(true); 701 properties->connected.ReplaceValue(true);
702 properties->paired.ReplaceValue(false); 702 properties->paired.ReplaceValue(false);
703 properties->name.ReplaceValue("Connected Pairable Device"); 703 properties->name.ReplaceValue("Connected Pairable Device");
704 properties->alias.ReplaceValue(kConnectedTrustedNotPairedDeviceName); 704 properties->alias.ReplaceValue(kConnectedTrustedNotPairedDeviceName);
705 } else { 705 } else {
706 NOTREACHED(); 706 NOTREACHED();
707 } 707 }
708 708
709 properties_map_.insert(device_path, properties.Pass()); 709 properties_map_.insert(std::make_pair(device_path, std::move(properties)));
710 device_list_.push_back(device_path); 710 device_list_.push_back(device_path);
711 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, 711 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
712 DeviceAdded(device_path)); 712 DeviceAdded(device_path));
713 } 713 }
714 714
715 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( 715 void FakeBluetoothDeviceClient::CreateDeviceWithProperties(
716 const dbus::ObjectPath& adapter_path, 716 const dbus::ObjectPath& adapter_path,
717 const IncomingDeviceProperties& props) { 717 const IncomingDeviceProperties& props) {
718 dbus::ObjectPath device_path(props.device_path); 718 dbus::ObjectPath device_path(props.device_path);
719 if (std::find(device_list_.begin(), device_list_.end(), device_path) != 719 if (std::find(device_list_.begin(), device_list_.end(), device_path) !=
(...skipping 12 matching lines...) Expand all
732 732
733 if (props.is_trusted) 733 if (props.is_trusted)
734 properties->paired.ReplaceValue(true); 734 properties->paired.ReplaceValue(true);
735 735
736 scoped_ptr<SimulatedPairingOptions> options(new SimulatedPairingOptions); 736 scoped_ptr<SimulatedPairingOptions> options(new SimulatedPairingOptions);
737 options->pairing_method = props.pairing_method; 737 options->pairing_method = props.pairing_method;
738 options->pairing_auth_token = props.pairing_auth_token; 738 options->pairing_auth_token = props.pairing_auth_token;
739 options->pairing_action = props.pairing_action; 739 options->pairing_action = props.pairing_action;
740 options->incoming = props.incoming; 740 options->incoming = props.incoming;
741 741
742 properties_map_.insert(device_path, properties.Pass()); 742 properties_map_.insert(std::make_pair(device_path, std::move(properties)));
743 device_list_.push_back(device_path); 743 device_list_.push_back(device_path);
744 pairing_options_map_.insert(device_path, options.Pass()); 744 pairing_options_map_.insert(std::make_pair(device_path, std::move(options)));
745 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, 745 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
746 DeviceAdded(device_path)); 746 DeviceAdded(device_path));
747 } 747 }
748 748
749 scoped_ptr<base::ListValue> 749 scoped_ptr<base::ListValue>
750 FakeBluetoothDeviceClient::GetBluetoothDevicesAsDictionaries() const { 750 FakeBluetoothDeviceClient::GetBluetoothDevicesAsDictionaries() const {
751 scoped_ptr<base::ListValue> predefined_devices(new base::ListValue); 751 scoped_ptr<base::ListValue> predefined_devices(new base::ListValue);
752 scoped_ptr<base::DictionaryValue> pairedDevice(new base::DictionaryValue); 752 scoped_ptr<base::DictionaryValue> pairedDevice(new base::DictionaryValue);
753 pairedDevice->SetString("path", kPairedDevicePath); 753 pairedDevice->SetString("path", kPairedDevicePath);
754 pairedDevice->SetString("address", kPairedDeviceAddress); 754 pairedDevice->SetString("address", kPairedDeviceAddress);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 988
989 void FakeBluetoothDeviceClient::RemoveDevice( 989 void FakeBluetoothDeviceClient::RemoveDevice(
990 const dbus::ObjectPath& adapter_path, 990 const dbus::ObjectPath& adapter_path,
991 const dbus::ObjectPath& device_path) { 991 const dbus::ObjectPath& device_path) {
992 std::vector<dbus::ObjectPath>::iterator listiter = 992 std::vector<dbus::ObjectPath>::iterator listiter =
993 std::find(device_list_.begin(), device_list_.end(), device_path); 993 std::find(device_list_.begin(), device_list_.end(), device_path);
994 if (listiter == device_list_.end()) 994 if (listiter == device_list_.end())
995 return; 995 return;
996 996
997 PropertiesMap::const_iterator iter = properties_map_.find(device_path); 997 PropertiesMap::const_iterator iter = properties_map_.find(device_path);
998 Properties* properties = iter->second; 998 Properties* properties = iter->second.get();
999 999
1000 VLOG(1) << "removing device: " << properties->alias.value(); 1000 VLOG(1) << "removing device: " << properties->alias.value();
1001 device_list_.erase(listiter); 1001 device_list_.erase(listiter);
1002 1002
1003 // Remove the Input interface if it exists. This should be called before the 1003 // Remove the Input interface if it exists. This should be called before the
1004 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the 1004 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the
1005 // BluetoothDeviceBlueZ object, including the device_path referenced here. 1005 // BluetoothDeviceBlueZ object, including the device_path referenced here.
1006 FakeBluetoothInputClient* fake_bluetooth_input_client = 1006 FakeBluetoothInputClient* fake_bluetooth_input_client =
1007 static_cast<FakeBluetoothInputClient*>( 1007 static_cast<FakeBluetoothInputClient*>(
1008 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()); 1008 bluez::BluezDBusManager::Get()->GetBluetoothInputClient());
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1441 }
1442 1442
1443 void FakeBluetoothDeviceClient::UpdateDeviceRSSI( 1443 void FakeBluetoothDeviceClient::UpdateDeviceRSSI(
1444 const dbus::ObjectPath& object_path, 1444 const dbus::ObjectPath& object_path,
1445 int16 rssi) { 1445 int16 rssi) {
1446 PropertiesMap::const_iterator iter = properties_map_.find(object_path); 1446 PropertiesMap::const_iterator iter = properties_map_.find(object_path);
1447 if (iter == properties_map_.end()) { 1447 if (iter == properties_map_.end()) {
1448 VLOG(2) << "Fake device does not exist: " << object_path.value(); 1448 VLOG(2) << "Fake device does not exist: " << object_path.value();
1449 return; 1449 return;
1450 } 1450 }
1451 Properties* properties = iter->second; 1451 Properties* properties = iter->second.get();
1452 DCHECK(properties); 1452 DCHECK(properties);
1453 properties->rssi.ReplaceValue(rssi); 1453 properties->rssi.ReplaceValue(rssi);
1454 } 1454 }
1455 1455
1456 void FakeBluetoothDeviceClient::UpdateConnectionInfo( 1456 void FakeBluetoothDeviceClient::UpdateConnectionInfo(
1457 uint16 connection_rssi, 1457 uint16 connection_rssi,
1458 uint16 transmit_power, 1458 uint16 transmit_power,
1459 uint16 max_transmit_power) { 1459 uint16 max_transmit_power) {
1460 connection_rssi_ = connection_rssi; 1460 connection_rssi_ = connection_rssi;
1461 transmit_power_ = transmit_power; 1461 transmit_power_ = transmit_power;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 // TODO(keybuk): tear down this side of the connection 1661 // TODO(keybuk): tear down this side of the connection
1662 callback.Run(); 1662 callback.Run();
1663 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { 1663 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) {
1664 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); 1664 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled");
1665 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { 1665 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) {
1666 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); 1666 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected");
1667 } 1667 }
1668 } 1668 }
1669 1669
1670 } // namespace bluez 1670 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698