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 // static | 21 // static |
22 BluetoothAdapterProfileChromeOS* BluetoothAdapterProfileChromeOS::Register( | 22 BluetoothAdapterProfileChromeOS* BluetoothAdapterProfileChromeOS::Register( |
| 23 BluetoothAdapterChromeOS* adapter, |
23 const device::BluetoothUUID& uuid, | 24 const device::BluetoothUUID& uuid, |
24 const BluetoothProfileManagerClient::Options& options, | 25 const BluetoothProfileManagerClient::Options& options, |
25 const BluetoothAdapterChromeOS::ProfileRegisteredCallback& success_callback, | 26 const base::Closure& success_callback, |
26 const BluetoothProfileManagerClient::ErrorCallback& error_callback) { | 27 const BluetoothProfileManagerClient::ErrorCallback& error_callback) { |
| 28 DCHECK(adapter); |
| 29 |
27 BluetoothAdapterProfileChromeOS* profile = | 30 BluetoothAdapterProfileChromeOS* profile = |
28 new BluetoothAdapterProfileChromeOS(uuid); | 31 new BluetoothAdapterProfileChromeOS(adapter, uuid); |
29 | 32 |
30 VLOG(1) << "Registering profile: " << profile->object_path().value(); | 33 VLOG(1) << "Registering profile: " << profile->object_path().value(); |
31 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()->RegisterProfile( | 34 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()->RegisterProfile( |
32 profile->object_path(), | 35 profile->object_path(), uuid.canonical_value(), options, success_callback, |
33 uuid.canonical_value(), | |
34 options, | |
35 base::Bind(success_callback, profile), | |
36 error_callback); | 36 error_callback); |
37 | 37 |
38 return profile; | 38 return profile; |
39 } | 39 } |
40 | 40 |
41 BluetoothAdapterProfileChromeOS::BluetoothAdapterProfileChromeOS( | 41 BluetoothAdapterProfileChromeOS::BluetoothAdapterProfileChromeOS( |
| 42 BluetoothAdapterChromeOS* adapter, |
42 const device::BluetoothUUID& uuid) | 43 const device::BluetoothUUID& uuid) |
43 : uuid_(uuid), weak_ptr_factory_(this) { | 44 : uuid_(uuid), adapter_(adapter), weak_ptr_factory_(this) { |
44 std::string uuid_path; | 45 std::string uuid_path; |
45 base::ReplaceChars(uuid.canonical_value(), ":-", "_", &uuid_path); | 46 base::ReplaceChars(uuid.canonical_value(), ":-", "_", &uuid_path); |
46 object_path_ = | 47 object_path_ = |
47 dbus::ObjectPath("/org/chromium/bluetooth_profile/" + uuid_path); | 48 dbus::ObjectPath("/org/chromium/bluetooth_profile/" + uuid_path); |
48 | 49 |
49 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 50 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
50 profile_.reset( | 51 profile_.reset( |
51 BluetoothProfileServiceProvider::Create(system_bus, object_path_, this)); | 52 BluetoothProfileServiceProvider::Create(system_bus, object_path_, this)); |
52 DCHECK(profile_.get()); | 53 DCHECK(profile_.get()); |
53 } | 54 } |
54 | 55 |
55 BluetoothAdapterProfileChromeOS::~BluetoothAdapterProfileChromeOS() { | 56 BluetoothAdapterProfileChromeOS::~BluetoothAdapterProfileChromeOS() { |
| 57 profile_.reset(); |
56 } | 58 } |
57 | 59 |
58 bool BluetoothAdapterProfileChromeOS::SetDelegate( | 60 bool BluetoothAdapterProfileChromeOS::SetDelegate( |
59 const dbus::ObjectPath& device_path, | 61 const dbus::ObjectPath& device_path, |
60 BluetoothProfileServiceProvider::Delegate* delegate) { | 62 BluetoothProfileServiceProvider::Delegate* delegate) { |
61 DCHECK(delegate); | 63 DCHECK(delegate); |
62 VLOG(1) << "SetDelegate: " << object_path_.value() << " dev " | 64 VLOG(1) << "SetDelegate: " << object_path_.value() << " dev " |
63 << device_path.value(); | 65 << device_path.value(); |
64 | 66 |
65 if (delegates_.find(device_path.value()) != delegates_.end()) { | 67 if (delegates_.find(device_path.value()) != delegates_.end()) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Cancel() should only go to a delegate accepting connections. | 156 // Cancel() should only go to a delegate accepting connections. |
155 if (delegates_.find("") == delegates_.end()) { | 157 if (delegates_.find("") == delegates_.end()) { |
156 VLOG(1) << object_path_.value() << ": Cancel with no delegate!"; | 158 VLOG(1) << object_path_.value() << ": Cancel with no delegate!"; |
157 return; | 159 return; |
158 } | 160 } |
159 | 161 |
160 delegates_[""]->Cancel(); | 162 delegates_[""]->Cancel(); |
161 } | 163 } |
162 | 164 |
163 } // namespace chromeos | 165 } // namespace chromeos |
OLD | NEW |