| Index: device/bluetooth/bluetooth_adapter_chromeos.cc
|
| diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc
|
| index e69c479a77fe63c0a96faa5085b1efd95935c11e..ce1eae945bb6a433477ebd5ed424921944ef65e1 100644
|
| --- a/device/bluetooth/bluetooth_adapter_chromeos.cc
|
| +++ b/device/bluetooth/bluetooth_adapter_chromeos.cc
|
| @@ -72,8 +72,33 @@ base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() {
|
| return adapter->weak_ptr_factory_.GetWeakPtr();
|
| }
|
|
|
| +void BluetoothAdapterChromeOS::OnDBusThreadManagerShutdown() {
|
| + if (dbus_is_shutdown_)
|
| + return;
|
| + DCHECK(DBusThreadManager::IsInitialized())
|
| + << "Call BluetoothAdapterFactory::OnDBusThreadManagerShutdown() before "
|
| + "DBusThreadManager::Shutdown().";
|
| +
|
| + if (IsPresent())
|
| + RemoveAdapter(); // Also deletes devices_.
|
| + DCHECK(devices_.empty());
|
| +
|
| + DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this);
|
| + DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this);
|
| + DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this);
|
| +
|
| + VLOG(1) << "Unregistering pairing agent";
|
| + DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->UnregisterAgent(
|
| + dbus::ObjectPath(kAgentPath), base::Bind(&base::DoNothing),
|
| + base::Bind(&OnUnregisterAgentError));
|
| +
|
| + agent_.reset();
|
| + dbus_is_shutdown_ = true;
|
| +}
|
| +
|
| BluetoothAdapterChromeOS::BluetoothAdapterChromeOS()
|
| - : num_discovery_sessions_(0),
|
| + : dbus_is_shutdown_(false),
|
| + num_discovery_sessions_(0),
|
| discovery_request_pending_(false),
|
| weak_ptr_factory_(this) {
|
| ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
| @@ -99,16 +124,7 @@ BluetoothAdapterChromeOS::BluetoothAdapterChromeOS()
|
| }
|
|
|
| BluetoothAdapterChromeOS::~BluetoothAdapterChromeOS() {
|
| - DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this);
|
| - DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this);
|
| - DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this);
|
| -
|
| - VLOG(1) << "Unregistering pairing agent";
|
| - DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->
|
| - UnregisterAgent(
|
| - dbus::ObjectPath(kAgentPath),
|
| - base::Bind(&base::DoNothing),
|
| - base::Bind(&OnUnregisterAgentError));
|
| + OnDBusThreadManagerShutdown();
|
| }
|
|
|
| void BluetoothAdapterChromeOS::DeleteOnCorrectThread() const {
|
| @@ -175,7 +191,7 @@ bool BluetoothAdapterChromeOS::IsInitialized() const {
|
| }
|
|
|
| bool BluetoothAdapterChromeOS::IsPresent() const {
|
| - return !object_path_.value().empty();
|
| + return !dbus_is_shutdown_ && !object_path_.value().empty();
|
| }
|
|
|
| bool BluetoothAdapterChromeOS::IsPowered() const {
|
| @@ -252,6 +268,7 @@ void BluetoothAdapterChromeOS::CreateRfcommService(
|
| const ServiceOptions& options,
|
| const CreateServiceCallback& callback,
|
| const CreateServiceErrorCallback& error_callback) {
|
| + DCHECK(!dbus_is_shutdown_);
|
| VLOG(1) << object_path_.value() << ": Creating RFCOMM service: "
|
| << uuid.canonical_value();
|
| scoped_refptr<BluetoothSocketChromeOS> socket =
|
| @@ -270,6 +287,7 @@ void BluetoothAdapterChromeOS::CreateL2capService(
|
| const ServiceOptions& options,
|
| const CreateServiceCallback& callback,
|
| const CreateServiceErrorCallback& error_callback) {
|
| + DCHECK(!dbus_is_shutdown_);
|
| VLOG(1) << object_path_.value() << ": Creating L2CAP service: "
|
| << uuid.canonical_value();
|
| scoped_refptr<BluetoothSocketChromeOS> socket =
|
| @@ -285,6 +303,7 @@ void BluetoothAdapterChromeOS::CreateL2capService(
|
|
|
| void BluetoothAdapterChromeOS::RemovePairingDelegateInternal(
|
| BluetoothDevice::PairingDelegate* pairing_delegate) {
|
| + DCHECK(IsPresent());
|
| // Before removing a pairing delegate make sure that there aren't any devices
|
| // currently using it; if there are, clear the pairing context which will
|
| // make any responses no-ops.
|
| @@ -315,6 +334,7 @@ void BluetoothAdapterChromeOS::AdapterRemoved(
|
| void BluetoothAdapterChromeOS::AdapterPropertyChanged(
|
| const dbus::ObjectPath& object_path,
|
| const std::string& property_name) {
|
| + DCHECK(IsPresent());
|
| if (object_path != object_path_)
|
| return;
|
|
|
| @@ -332,6 +352,7 @@ void BluetoothAdapterChromeOS::AdapterPropertyChanged(
|
|
|
| void BluetoothAdapterChromeOS::DeviceAdded(
|
| const dbus::ObjectPath& object_path) {
|
| + DCHECK(IsPresent());
|
| BluetoothDeviceClient::Properties* properties =
|
| DBusThreadManager::Get()->GetBluetoothDeviceClient()->
|
| GetProperties(object_path);
|
| @@ -353,6 +374,7 @@ void BluetoothAdapterChromeOS::DeviceAdded(
|
|
|
| void BluetoothAdapterChromeOS::DeviceRemoved(
|
| const dbus::ObjectPath& object_path) {
|
| + DCHECK(IsPresent());
|
| for (DevicesMap::iterator iter = devices_.begin();
|
| iter != devices_.end(); ++iter) {
|
| BluetoothDeviceChromeOS* device_chromeos =
|
| @@ -371,6 +393,7 @@ void BluetoothAdapterChromeOS::DeviceRemoved(
|
| void BluetoothAdapterChromeOS::DevicePropertyChanged(
|
| const dbus::ObjectPath& object_path,
|
| const std::string& property_name) {
|
| + DCHECK(IsPresent());
|
| BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path);
|
| if (!device_chromeos)
|
| return;
|
| @@ -419,6 +442,7 @@ void BluetoothAdapterChromeOS::DevicePropertyChanged(
|
| void BluetoothAdapterChromeOS::InputPropertyChanged(
|
| const dbus::ObjectPath& object_path,
|
| const std::string& property_name) {
|
| + DCHECK(IsPresent());
|
| BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path);
|
| if (!device_chromeos)
|
| return;
|
| @@ -436,6 +460,7 @@ void BluetoothAdapterChromeOS::InputPropertyChanged(
|
| }
|
|
|
| void BluetoothAdapterChromeOS::Released() {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << "Release";
|
|
|
| @@ -446,6 +471,7 @@ void BluetoothAdapterChromeOS::Released() {
|
| void BluetoothAdapterChromeOS::RequestPinCode(
|
| const dbus::ObjectPath& device_path,
|
| const PinCodeCallback& callback) {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << device_path.value() << ": RequestPinCode";
|
|
|
| @@ -461,6 +487,7 @@ void BluetoothAdapterChromeOS::RequestPinCode(
|
| void BluetoothAdapterChromeOS::DisplayPinCode(
|
| const dbus::ObjectPath& device_path,
|
| const std::string& pincode) {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << device_path.value() << ": DisplayPinCode: " << pincode;
|
|
|
| @@ -474,6 +501,7 @@ void BluetoothAdapterChromeOS::DisplayPinCode(
|
| void BluetoothAdapterChromeOS::RequestPasskey(
|
| const dbus::ObjectPath& device_path,
|
| const PasskeyCallback& callback) {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << device_path.value() << ": RequestPasskey";
|
|
|
| @@ -490,6 +518,7 @@ void BluetoothAdapterChromeOS::DisplayPasskey(
|
| const dbus::ObjectPath& device_path,
|
| uint32 passkey,
|
| uint16 entered) {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << device_path.value() << ": DisplayPasskey: " << passkey
|
| << " (" << entered << " entered)";
|
| @@ -508,6 +537,7 @@ void BluetoothAdapterChromeOS::RequestConfirmation(
|
| const dbus::ObjectPath& device_path,
|
| uint32 passkey,
|
| const ConfirmationCallback& callback) {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << device_path.value() << ": RequestConfirmation: " << passkey;
|
|
|
| @@ -523,6 +553,7 @@ void BluetoothAdapterChromeOS::RequestConfirmation(
|
| void BluetoothAdapterChromeOS::RequestAuthorization(
|
| const dbus::ObjectPath& device_path,
|
| const ConfirmationCallback& callback) {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << device_path.value() << ": RequestAuthorization";
|
|
|
| @@ -539,6 +570,7 @@ void BluetoothAdapterChromeOS::AuthorizeService(
|
| const dbus::ObjectPath& device_path,
|
| const std::string& uuid,
|
| const ConfirmationCallback& callback) {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << device_path.value() << ": AuthorizeService: " << uuid;
|
|
|
| @@ -565,11 +597,13 @@ void BluetoothAdapterChromeOS::AuthorizeService(
|
| }
|
|
|
| void BluetoothAdapterChromeOS::Cancel() {
|
| + DCHECK(IsPresent());
|
| DCHECK(agent_.get());
|
| VLOG(1) << "Cancel";
|
| }
|
|
|
| void BluetoothAdapterChromeOS::OnRegisterAgent() {
|
| + DCHECK(IsPresent());
|
| VLOG(1) << "Pairing agent registered, requesting to be made default";
|
|
|
| DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->
|
| @@ -585,6 +619,7 @@ void BluetoothAdapterChromeOS::OnRegisterAgent() {
|
| void BluetoothAdapterChromeOS::OnRegisterAgentError(
|
| const std::string& error_name,
|
| const std::string& error_message) {
|
| + DCHECK(IsPresent());
|
| // Our agent being already registered isn't an error.
|
| if (error_name == bluetooth_agent_manager::kErrorAlreadyExists)
|
| return;
|
| @@ -594,12 +629,14 @@ void BluetoothAdapterChromeOS::OnRegisterAgentError(
|
| }
|
|
|
| void BluetoothAdapterChromeOS::OnRequestDefaultAgent() {
|
| + DCHECK(IsPresent());
|
| VLOG(1) << "Pairing agent now default";
|
| }
|
|
|
| void BluetoothAdapterChromeOS::OnRequestDefaultAgentError(
|
| const std::string& error_name,
|
| const std::string& error_message) {
|
| + DCHECK(IsPresent());
|
| LOG(WARNING) << ": Failed to make pairing agent default: "
|
| << error_name << ": " << error_message;
|
| }
|
| @@ -607,8 +644,11 @@ void BluetoothAdapterChromeOS::OnRequestDefaultAgentError(
|
| BluetoothDeviceChromeOS*
|
| BluetoothAdapterChromeOS::GetDeviceWithPath(
|
| const dbus::ObjectPath& object_path) {
|
| - for (DevicesMap::iterator iter = devices_.begin();
|
| - iter != devices_.end(); ++iter) {
|
| + if (!IsPresent())
|
| + return NULL;
|
| +
|
| + for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end();
|
| + ++iter) {
|
| BluetoothDeviceChromeOS* device_chromeos =
|
| static_cast<BluetoothDeviceChromeOS*>(iter->second);
|
| if (device_chromeos->object_path() == object_path)
|
| @@ -621,6 +661,7 @@ BluetoothAdapterChromeOS::GetDeviceWithPath(
|
| BluetoothPairingChromeOS* BluetoothAdapterChromeOS::GetPairing(
|
| const dbus::ObjectPath& object_path)
|
| {
|
| + DCHECK(IsPresent());
|
| BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path);
|
| if (!device_chromeos) {
|
| LOG(WARNING) << "Pairing Agent request for unknown device: "
|
| @@ -643,6 +684,7 @@ BluetoothPairingChromeOS* BluetoothAdapterChromeOS::GetPairing(
|
|
|
| void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) {
|
| DCHECK(!IsPresent());
|
| + DCHECK(!dbus_is_shutdown_);
|
| object_path_ = object_path;
|
|
|
| VLOG(1) << object_path_.value() << ": using adapter.";
|
| @@ -683,6 +725,7 @@ void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) {
|
| }
|
|
|
| void BluetoothAdapterChromeOS::SetDefaultAdapterName() {
|
| + DCHECK(IsPresent());
|
| std::string board = base::SysInfo::GetLsbReleaseBoard();
|
| std::string alias;
|
| if (board.substr(0, 6) == "stumpy") {
|
| @@ -881,6 +924,7 @@ void BluetoothAdapterChromeOS::OnSetDiscoverable(
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback,
|
| bool success) {
|
| + DCHECK(IsPresent());
|
| // Set the discoverable_timeout property to zero so the adapter remains
|
| // discoverable forever.
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| @@ -896,6 +940,7 @@ void BluetoothAdapterChromeOS::OnPropertyChangeCompleted(
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback,
|
| bool success) {
|
| + DCHECK(IsPresent());
|
| if (success)
|
| callback.Run();
|
| else
|
| @@ -905,6 +950,7 @@ void BluetoothAdapterChromeOS::OnPropertyChangeCompleted(
|
| void BluetoothAdapterChromeOS::AddDiscoverySession(
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback) {
|
| + DCHECK(IsPresent());
|
| VLOG(1) << __func__;
|
| if (discovery_request_pending_) {
|
| // The pending request is either to stop a previous session or to start a
|
| @@ -945,6 +991,7 @@ void BluetoothAdapterChromeOS::AddDiscoverySession(
|
| void BluetoothAdapterChromeOS::RemoveDiscoverySession(
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback) {
|
| + DCHECK(IsPresent());
|
| VLOG(1) << __func__;
|
| // There are active sessions other than the one currently being removed.
|
| if (num_discovery_sessions_ > 1) {
|
| @@ -989,6 +1036,7 @@ void BluetoothAdapterChromeOS::RemoveDiscoverySession(
|
| }
|
|
|
| void BluetoothAdapterChromeOS::OnStartDiscovery(const base::Closure& callback) {
|
| + DCHECK(IsPresent());
|
| // Report success on the original request and increment the count.
|
| VLOG(1) << __func__;
|
| DCHECK(discovery_request_pending_);
|
| @@ -1006,6 +1054,7 @@ void BluetoothAdapterChromeOS::OnStartDiscoveryError(
|
| const ErrorCallback& error_callback,
|
| const std::string& error_name,
|
| const std::string& error_message) {
|
| + DCHECK(IsPresent());
|
| LOG(WARNING) << object_path_.value() << ": Failed to start discovery: "
|
| << error_name << ": " << error_message;
|
|
|
| @@ -1030,6 +1079,7 @@ void BluetoothAdapterChromeOS::OnStartDiscoveryError(
|
| }
|
|
|
| void BluetoothAdapterChromeOS::OnStopDiscovery(const base::Closure& callback) {
|
| + DCHECK(IsPresent());
|
| // Report success on the original request and decrement the count.
|
| VLOG(1) << __func__;
|
| DCHECK(discovery_request_pending_);
|
| @@ -1046,6 +1096,7 @@ void BluetoothAdapterChromeOS::OnStopDiscoveryError(
|
| const ErrorCallback& error_callback,
|
| const std::string& error_name,
|
| const std::string& error_message) {
|
| + DCHECK(IsPresent());
|
| LOG(WARNING) << object_path_.value() << ": Failed to stop discovery: "
|
| << error_name << ": " << error_message;
|
|
|
|
|