OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
6 | 6 |
7 #include <map> | |
7 #include <string> | 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/weak_ptr.h" | |
12 #include "base/string16.h" | 14 #include "base/string16.h" |
13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 18 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
19 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" | |
17 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" | 20 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" |
18 #include "chrome/browser/chromeos/dbus/bluetooth_agent_service_provider.h" | 21 #include "chrome/browser/chromeos/dbus/bluetooth_agent_service_provider.h" |
19 #include "chrome/browser/chromeos/dbus/bluetooth_device_client.h" | 22 #include "chrome/browser/chromeos/dbus/bluetooth_device_client.h" |
20 #include "chrome/browser/chromeos/dbus/bluetooth_input_client.h" | 23 #include "chrome/browser/chromeos/dbus/bluetooth_input_client.h" |
24 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | |
21 #include "chrome/browser/chromeos/dbus/introspectable_client.h" | 25 #include "chrome/browser/chromeos/dbus/introspectable_client.h" |
22 #include "chrome/browser/chromeos/dbus/introspect_util.h" | 26 #include "chrome/browser/chromeos/dbus/introspect_util.h" |
23 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | |
24 #include "dbus/bus.h" | 27 #include "dbus/bus.h" |
25 #include "dbus/object_path.h" | 28 #include "dbus/object_path.h" |
26 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
27 #include "third_party/cros_system_api/dbus/service_constants.h" | 30 #include "third_party/cros_system_api/dbus/service_constants.h" |
28 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
29 | 32 |
30 namespace chromeos { | 33 namespace chromeos { |
31 | 34 |
32 BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter) | 35 BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter) |
33 : weak_ptr_factory_(this), | 36 : weak_ptr_factory_(this), |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 DCHECK(device_path == object_path_); | 393 DCHECK(device_path == object_path_); |
391 if (success) { | 394 if (success) { |
392 DVLOG(1) << "Disconnection successful: " << address_; | 395 DVLOG(1) << "Disconnection successful: " << address_; |
393 } else { | 396 } else { |
394 LOG(WARNING) << "Disconnection failed: " << address_; | 397 LOG(WARNING) << "Disconnection failed: " << address_; |
395 error_callback.Run(); | 398 error_callback.Run(); |
396 } | 399 } |
397 } | 400 } |
398 | 401 |
399 void BluetoothDevice::Forget(ErrorCallback error_callback) { | 402 void BluetoothDevice::Forget(ErrorCallback error_callback) { |
403 CloseAllSockets(); | |
400 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 404 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
401 RemoveDevice(adapter_->object_path_, | 405 RemoveDevice(adapter_->object_path_, |
402 object_path_, | 406 object_path_, |
403 base::Bind(&BluetoothDevice::ForgetCallback, | 407 base::Bind(&BluetoothDevice::ForgetCallback, |
404 weak_ptr_factory_.GetWeakPtr(), | 408 weak_ptr_factory_.GetWeakPtr(), |
405 error_callback)); | 409 error_callback)); |
406 } | 410 } |
407 | 411 |
412 void BluetoothDevice::CloseAllSockets() { | |
413 for (SocketMap::const_iterator i = socket_map_.begin(); | |
414 i != socket_map_.end(); ++i) { | |
415 BluetoothSocket* socket = i->second; | |
416 socket->Close(); | |
417 delete socket; | |
keybuk
2012/04/16 22:25:36
Could this be encapsulated as simply dropping the
| |
418 } | |
419 socket_map_.clear(); | |
420 } | |
421 | |
422 base::WeakPtr<BluetoothSocket> BluetoothDevice::OpenSocket( | |
423 const std::string &service_uuid) { | |
keybuk
2012/04/16 22:25:36
nit: "& " not " &"
| |
424 // TODO(keybuk): dbus stuff | |
425 LOG(ERROR) << "NIY: returning dummy socket for now"; | |
426 | |
427 int socket_id = -1; | |
428 BluetoothSocket* socket = new BluetoothSocket(this, service_uuid, socket_id); | |
429 socket_map_[socket_id] = socket; | |
430 return socket->AsWeakPtr(); | |
431 } | |
432 | |
433 void BluetoothDevice::CloseSocket(int socket_id) { | |
434 SocketMap::iterator it = socket_map_.find(socket_id); | |
435 | |
436 if (it == socket_map_.end()) { | |
437 return; | |
438 } | |
439 | |
440 BluetoothSocket* socket = it->second; | |
441 socket->Close(); | |
442 delete socket; | |
keybuk
2012/04/16 22:25:36
As above, could this be a drop of a reference rath
| |
443 | |
444 socket_map_.erase(it); | |
445 } | |
446 | |
408 void BluetoothDevice::ForgetCallback(ErrorCallback error_callback, | 447 void BluetoothDevice::ForgetCallback(ErrorCallback error_callback, |
409 const dbus::ObjectPath& adapter_path, | 448 const dbus::ObjectPath& adapter_path, |
410 bool success) { | 449 bool success) { |
411 // It's quite normal that this path never gets called on success; we use a | 450 // It's quite normal that this path never gets called on success; we use a |
412 // weak pointer, and bluetoothd might send the DeviceRemoved signal before | 451 // weak pointer, and bluetoothd might send the DeviceRemoved signal before |
413 // the method reply, in which case this object is deleted and the | 452 // the method reply, in which case this object is deleted and the |
414 // callback never takes place. Therefore don't do anything here for the | 453 // callback never takes place. Therefore don't do anything here for the |
415 // success case. | 454 // success case. |
416 if (!success) { | 455 if (!success) { |
417 LOG(WARNING) << "Forget failed: " << address_; | 456 LOG(WARNING) << "Forget failed: " << address_; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 // static | 575 // static |
537 BluetoothDevice* BluetoothDevice::CreateUnbound( | 576 BluetoothDevice* BluetoothDevice::CreateUnbound( |
538 BluetoothAdapter* adapter, | 577 BluetoothAdapter* adapter, |
539 const BluetoothDeviceClient::Properties* properties) { | 578 const BluetoothDeviceClient::Properties* properties) { |
540 BluetoothDevice* device = new BluetoothDevice(adapter); | 579 BluetoothDevice* device = new BluetoothDevice(adapter); |
541 device->Update(properties, false); | 580 device->Update(properties, false); |
542 return device; | 581 return device; |
543 } | 582 } |
544 | 583 |
545 } // namespace chromeos | 584 } // namespace chromeos |
OLD | NEW |