Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bluetooth_adapter_profile_chromeos.h" | 5 #include "device/bluetooth/bluetooth_adapter_profile_chromeos.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "chromeos/dbus/bluetooth_profile_service_provider.h" | 12 #include "chromeos/dbus/bluetooth_profile_service_provider.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
| 15 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 16 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 16 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 17 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
| 18 | 18 |
| 19 namespace chromeos { | 19 namespace chromeos { |
| 20 | 20 |
| 21 namespace { | |
| 22 | |
| 23 void OnRegisterProfileError( | |
| 24 scoped_ptr<BluetoothAdapterProfileChromeOS> profile, | |
| 25 const BluetoothProfileManagerClient::ErrorCallback& error_callback, | |
| 26 const std::string& error_name, | |
| 27 const std::string& error_message) { | |
| 28 error_callback.Run(error_name, error_message); | |
| 29 } | |
| 30 | |
| 31 } // anonymous namespace | |
| 32 | |
| 21 // static | 33 // static |
| 22 BluetoothAdapterProfileChromeOS* BluetoothAdapterProfileChromeOS::Register( | 34 void BluetoothAdapterProfileChromeOS::Register( |
| 23 BluetoothAdapterChromeOS* adapter, | |
| 24 const device::BluetoothUUID& uuid, | 35 const device::BluetoothUUID& uuid, |
| 25 const BluetoothProfileManagerClient::Options& options, | 36 const BluetoothProfileManagerClient::Options& options, |
| 26 const base::Closure& success_callback, | 37 const ProfileRegisteredCallback& success_callback, |
| 27 const BluetoothProfileManagerClient::ErrorCallback& error_callback) { | 38 const BluetoothProfileManagerClient::ErrorCallback& error_callback) { |
| 28 DCHECK(adapter); | 39 scoped_ptr<BluetoothAdapterProfileChromeOS> profile( |
| 29 | 40 new BluetoothAdapterProfileChromeOS(uuid)); |
| 30 BluetoothAdapterProfileChromeOS* profile = | |
| 31 new BluetoothAdapterProfileChromeOS(adapter, uuid); | |
| 32 | 41 |
| 33 VLOG(1) << "Registering profile: " << profile->object_path().value(); | 42 VLOG(1) << "Registering profile: " << profile->object_path().value(); |
| 34 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()->RegisterProfile( | 43 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()->RegisterProfile( |
| 35 profile->object_path(), uuid.canonical_value(), options, success_callback, | 44 profile->object_path(), |
| 36 error_callback); | 45 uuid.canonical_value(), |
| 37 | 46 options, |
| 38 return profile; | 47 base::Bind(success_callback, base::Passed(&profile)), |
| 48 base::Bind(OnRegisterProfileError, base::Passed(&profile), | |
| 49 error_callback)); | |
|
Ilya Sherman
2015/03/05 04:33:54
This looks to me like it will actually lead to a d
Marie Janssen
2015/03/09 16:22:49
Done.
| |
| 39 } | 50 } |
| 40 | 51 |
| 41 BluetoothAdapterProfileChromeOS::BluetoothAdapterProfileChromeOS( | 52 BluetoothAdapterProfileChromeOS::BluetoothAdapterProfileChromeOS( |
| 42 BluetoothAdapterChromeOS* adapter, | |
| 43 const device::BluetoothUUID& uuid) | 53 const device::BluetoothUUID& uuid) |
| 44 : uuid_(uuid), adapter_(adapter), weak_ptr_factory_(this) { | 54 : uuid_(uuid), weak_ptr_factory_(this) { |
| 45 std::string uuid_path; | 55 std::string uuid_path; |
| 46 base::ReplaceChars(uuid.canonical_value(), ":-", "_", &uuid_path); | 56 base::ReplaceChars(uuid.canonical_value(), ":-", "_", &uuid_path); |
| 47 object_path_ = | 57 object_path_ = |
| 48 dbus::ObjectPath("/org/chromium/bluetooth_profile/" + uuid_path); | 58 dbus::ObjectPath("/org/chromium/bluetooth_profile/" + uuid_path); |
| 49 | 59 |
| 50 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 60 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
| 51 profile_.reset( | 61 profile_.reset( |
| 52 BluetoothProfileServiceProvider::Create(system_bus, object_path_, this)); | 62 BluetoothProfileServiceProvider::Create(system_bus, object_path_, this)); |
| 53 DCHECK(profile_.get()); | 63 DCHECK(profile_.get()); |
| 54 } | 64 } |
| 55 | 65 |
| 56 BluetoothAdapterProfileChromeOS::~BluetoothAdapterProfileChromeOS() { | 66 BluetoothAdapterProfileChromeOS::~BluetoothAdapterProfileChromeOS() { |
| 57 profile_.reset(); | |
| 58 } | 67 } |
| 59 | 68 |
| 60 bool BluetoothAdapterProfileChromeOS::SetDelegate( | 69 bool BluetoothAdapterProfileChromeOS::SetDelegate( |
| 61 const dbus::ObjectPath& device_path, | 70 const dbus::ObjectPath& device_path, |
| 62 BluetoothProfileServiceProvider::Delegate* delegate) { | 71 BluetoothProfileServiceProvider::Delegate* delegate) { |
| 63 DCHECK(delegate); | 72 DCHECK(delegate); |
| 64 VLOG(1) << "SetDelegate: " << object_path_.value() << " dev " | 73 VLOG(1) << "SetDelegate: " << object_path_.value() << " dev " |
| 65 << device_path.value(); | 74 << device_path.value(); |
| 66 | 75 |
| 67 if (delegates_.find(device_path.value()) != delegates_.end()) { | 76 if (delegates_.find(device_path.value()) != delegates_.end()) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 // Cancel() should only go to a delegate accepting connections. | 165 // Cancel() should only go to a delegate accepting connections. |
| 157 if (delegates_.find("") == delegates_.end()) { | 166 if (delegates_.find("") == delegates_.end()) { |
| 158 VLOG(1) << object_path_.value() << ": Cancel with no delegate!"; | 167 VLOG(1) << object_path_.value() << ": Cancel with no delegate!"; |
| 159 return; | 168 return; |
| 160 } | 169 } |
| 161 | 170 |
| 162 delegates_[""]->Cancel(); | 171 delegates_[""]->Cancel(); |
| 163 } | 172 } |
| 164 | 173 |
| 165 } // namespace chromeos | 174 } // namespace chromeos |
| OLD | NEW |