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" | |
13 #include "chromeos/dbus/dbus_thread_manager.h" | |
14 #include "dbus/bus.h" | 12 #include "dbus/bus.h" |
15 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
16 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 14 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
17 #include "device/bluetooth/bluetooth_uuid.h" | 15 #include "device/bluetooth/bluetooth_uuid.h" |
| 16 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" |
| 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
18 | 18 |
19 namespace chromeos { | 19 namespace chromeos { |
20 | 20 |
21 // static | 21 // static |
22 void BluetoothAdapterProfileChromeOS::Register( | 22 void BluetoothAdapterProfileChromeOS::Register( |
23 const device::BluetoothUUID& uuid, | 23 const device::BluetoothUUID& uuid, |
24 const BluetoothProfileManagerClient::Options& options, | 24 const bluez::BluetoothProfileManagerClient::Options& options, |
25 const ProfileRegisteredCallback& success_callback, | 25 const ProfileRegisteredCallback& success_callback, |
26 const BluetoothProfileManagerClient::ErrorCallback& error_callback) { | 26 const bluez::BluetoothProfileManagerClient::ErrorCallback& error_callback) { |
27 scoped_ptr<BluetoothAdapterProfileChromeOS> profile( | 27 scoped_ptr<BluetoothAdapterProfileChromeOS> profile( |
28 new BluetoothAdapterProfileChromeOS(uuid)); | 28 new BluetoothAdapterProfileChromeOS(uuid)); |
29 | 29 |
30 VLOG(1) << "Registering profile: " << profile->object_path().value(); | 30 VLOG(1) << "Registering profile: " << profile->object_path().value(); |
31 const dbus::ObjectPath& object_path = profile->object_path(); | 31 const dbus::ObjectPath& object_path = profile->object_path(); |
32 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()->RegisterProfile( | 32 bluez::BluezDBusManager::Get() |
33 object_path, | 33 ->GetBluetoothProfileManagerClient() |
34 uuid.canonical_value(), | 34 ->RegisterProfile(object_path, uuid.canonical_value(), options, |
35 options, | 35 base::Bind(success_callback, base::Passed(&profile)), |
36 base::Bind(success_callback, base::Passed(&profile)), | 36 error_callback); |
37 error_callback); | |
38 } | 37 } |
39 | 38 |
40 BluetoothAdapterProfileChromeOS::BluetoothAdapterProfileChromeOS( | 39 BluetoothAdapterProfileChromeOS::BluetoothAdapterProfileChromeOS( |
41 const device::BluetoothUUID& uuid) | 40 const device::BluetoothUUID& uuid) |
42 : uuid_(uuid), weak_ptr_factory_(this) { | 41 : uuid_(uuid), weak_ptr_factory_(this) { |
43 std::string uuid_path; | 42 std::string uuid_path; |
44 base::ReplaceChars(uuid.canonical_value(), ":-", "_", &uuid_path); | 43 base::ReplaceChars(uuid.canonical_value(), ":-", "_", &uuid_path); |
45 object_path_ = | 44 object_path_ = |
46 dbus::ObjectPath("/org/chromium/bluetooth_profile/" + uuid_path); | 45 dbus::ObjectPath("/org/chromium/bluetooth_profile/" + uuid_path); |
47 | 46 |
48 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 47 dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus(); |
49 profile_.reset( | 48 profile_.reset(bluez::BluetoothProfileServiceProvider::Create( |
50 BluetoothProfileServiceProvider::Create(system_bus, object_path_, this)); | 49 system_bus, object_path_, this)); |
51 DCHECK(profile_.get()); | 50 DCHECK(profile_.get()); |
52 } | 51 } |
53 | 52 |
54 BluetoothAdapterProfileChromeOS::~BluetoothAdapterProfileChromeOS() { | 53 BluetoothAdapterProfileChromeOS::~BluetoothAdapterProfileChromeOS() { |
55 } | 54 } |
56 | 55 |
57 bool BluetoothAdapterProfileChromeOS::SetDelegate( | 56 bool BluetoothAdapterProfileChromeOS::SetDelegate( |
58 const dbus::ObjectPath& device_path, | 57 const dbus::ObjectPath& device_path, |
59 BluetoothProfileServiceProvider::Delegate* delegate) { | 58 bluez::BluetoothProfileServiceProvider::Delegate* delegate) { |
60 DCHECK(delegate); | 59 DCHECK(delegate); |
61 VLOG(1) << "SetDelegate: " << object_path_.value() << " dev " | 60 VLOG(1) << "SetDelegate: " << object_path_.value() << " dev " |
62 << device_path.value(); | 61 << device_path.value(); |
63 | 62 |
64 if (delegates_.find(device_path.value()) != delegates_.end()) { | 63 if (delegates_.find(device_path.value()) != delegates_.end()) { |
65 return false; | 64 return false; |
66 } | 65 } |
67 | 66 |
68 delegates_[device_path.value()] = delegate; | 67 delegates_[device_path.value()] = delegate; |
69 return true; | 68 return true; |
70 } | 69 } |
71 | 70 |
72 void BluetoothAdapterProfileChromeOS::RemoveDelegate( | 71 void BluetoothAdapterProfileChromeOS::RemoveDelegate( |
73 const dbus::ObjectPath& device_path, | 72 const dbus::ObjectPath& device_path, |
74 const base::Closure& unregistered_callback) { | 73 const base::Closure& unregistered_callback) { |
75 VLOG(1) << object_path_.value() << " dev " << device_path.value() | 74 VLOG(1) << object_path_.value() << " dev " << device_path.value() |
76 << ": RemoveDelegate"; | 75 << ": RemoveDelegate"; |
77 | 76 |
78 if (delegates_.find(device_path.value()) == delegates_.end()) | 77 if (delegates_.find(device_path.value()) == delegates_.end()) |
79 return; | 78 return; |
80 | 79 |
81 delegates_.erase(device_path.value()); | 80 delegates_.erase(device_path.value()); |
82 | 81 |
83 if (delegates_.size() != 0) | 82 if (delegates_.size() != 0) |
84 return; | 83 return; |
85 | 84 |
86 VLOG(1) << device_path.value() << " No delegates left, unregistering."; | 85 VLOG(1) << device_path.value() << " No delegates left, unregistering."; |
87 | 86 |
88 // No users left, release the profile. | 87 // No users left, release the profile. |
89 DBusThreadManager::Get() | 88 bluez::BluezDBusManager::Get() |
90 ->GetBluetoothProfileManagerClient() | 89 ->GetBluetoothProfileManagerClient() |
91 ->UnregisterProfile( | 90 ->UnregisterProfile( |
92 object_path_, unregistered_callback, | 91 object_path_, unregistered_callback, |
93 base::Bind(&BluetoothAdapterProfileChromeOS::OnUnregisterProfileError, | 92 base::Bind(&BluetoothAdapterProfileChromeOS::OnUnregisterProfileError, |
94 weak_ptr_factory_.GetWeakPtr(), unregistered_callback)); | 93 weak_ptr_factory_.GetWeakPtr(), unregistered_callback)); |
95 } | 94 } |
96 | 95 |
97 void BluetoothAdapterProfileChromeOS::OnUnregisterProfileError( | 96 void BluetoothAdapterProfileChromeOS::OnUnregisterProfileError( |
98 const base::Closure& unregistered_callback, | 97 const base::Closure& unregistered_callback, |
99 const std::string& error_name, | 98 const std::string& error_name, |
100 const std::string& error_message) { | 99 const std::string& error_message) { |
101 LOG(WARNING) << this->object_path().value() | 100 LOG(WARNING) << this->object_path().value() |
102 << ": Failed to unregister profile: " << error_name << ": " | 101 << ": Failed to unregister profile: " << error_name << ": " |
103 << error_message; | 102 << error_message; |
104 | 103 |
105 unregistered_callback.Run(); | 104 unregistered_callback.Run(); |
106 } | 105 } |
107 | 106 |
108 // BluetoothProfileServiceProvider::Delegate: | 107 // bluez::BluetoothProfileServiceProvider::Delegate: |
109 void BluetoothAdapterProfileChromeOS::Released() { | 108 void BluetoothAdapterProfileChromeOS::Released() { |
110 VLOG(1) << object_path_.value() << ": Release"; | 109 VLOG(1) << object_path_.value() << ": Release"; |
111 } | 110 } |
112 | 111 |
113 void BluetoothAdapterProfileChromeOS::NewConnection( | 112 void BluetoothAdapterProfileChromeOS::NewConnection( |
114 const dbus::ObjectPath& device_path, | 113 const dbus::ObjectPath& device_path, |
115 scoped_ptr<dbus::FileDescriptor> fd, | 114 scoped_ptr<dbus::FileDescriptor> fd, |
116 const BluetoothProfileServiceProvider::Delegate::Options& options, | 115 const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, |
117 const ConfirmationCallback& callback) { | 116 const ConfirmationCallback& callback) { |
118 dbus::ObjectPath delegate_path = device_path; | 117 dbus::ObjectPath delegate_path = device_path; |
119 | 118 |
120 if (delegates_.find(device_path.value()) == delegates_.end()) | 119 if (delegates_.find(device_path.value()) == delegates_.end()) |
121 delegate_path = dbus::ObjectPath(""); | 120 delegate_path = dbus::ObjectPath(""); |
122 | 121 |
123 if (delegates_.find(delegate_path.value()) == delegates_.end()) { | 122 if (delegates_.find(delegate_path.value()) == delegates_.end()) { |
124 VLOG(1) << object_path_.value() << ": New connection for device " | 123 VLOG(1) << object_path_.value() << ": New connection for device " |
125 << device_path.value() << " which has no delegates!"; | 124 << device_path.value() << " which has no delegates!"; |
126 callback.Run(REJECTED); | 125 callback.Run(REJECTED); |
(...skipping 26 matching lines...) Expand all Loading... |
153 // Cancel() should only go to a delegate accepting connections. | 152 // Cancel() should only go to a delegate accepting connections. |
154 if (delegates_.find("") == delegates_.end()) { | 153 if (delegates_.find("") == delegates_.end()) { |
155 VLOG(1) << object_path_.value() << ": Cancel with no delegate!"; | 154 VLOG(1) << object_path_.value() << ": Cancel with no delegate!"; |
156 return; | 155 return; |
157 } | 156 } |
158 | 157 |
159 delegates_[""]->Cancel(); | 158 delegates_[""]->Cancel(); |
160 } | 159 } |
161 | 160 |
162 } // namespace chromeos | 161 } // namespace chromeos |
OLD | NEW |