OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/dbus/bluetooth_profile_service_provider.h" | 5 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" |
6 | |
7 | 6 |
8 #include "base/bind.h" | 7 #include "base/bind.h" |
9 #include "base/logging.h" | 8 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
11 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | |
13 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" | |
14 #include "dbus/exported_object.h" | 11 #include "dbus/exported_object.h" |
15 #include "dbus/message.h" | 12 #include "dbus/message.h" |
| 13 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 14 #include "device/bluetooth/dbus/fake_bluetooth_profile_service_provider.h" |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
17 | 16 |
18 namespace chromeos { | 17 namespace bluez { |
19 | 18 |
20 // The BluetoothProfileServiceProvider implementation used in production. | 19 // The BluetoothProfileServiceProvider implementation used in production. |
21 class BluetoothProfileServiceProviderImpl | 20 class BluetoothProfileServiceProviderImpl |
22 : public BluetoothProfileServiceProvider { | 21 : public BluetoothProfileServiceProvider { |
23 public: | 22 public: |
24 BluetoothProfileServiceProviderImpl(dbus::Bus* bus, | 23 BluetoothProfileServiceProviderImpl(dbus::Bus* bus, |
25 const dbus::ObjectPath& object_path, | 24 const dbus::ObjectPath& object_path, |
26 Delegate* delegate) | 25 Delegate* delegate) |
27 : origin_thread_id_(base::PlatformThread::CurrentId()), | 26 : origin_thread_id_(base::PlatformThread::CurrentId()), |
28 bus_(bus), | 27 bus_(bus), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } else { | 120 } else { |
122 if (key == bluetooth_profile::kVersionProperty) | 121 if (key == bluetooth_profile::kVersionProperty) |
123 dict_entry_reader.PopVariantOfUint16(&options.version); | 122 dict_entry_reader.PopVariantOfUint16(&options.version); |
124 else if (key == bluetooth_profile::kFeaturesProperty) | 123 else if (key == bluetooth_profile::kFeaturesProperty) |
125 dict_entry_reader.PopVariantOfUint16(&options.features); | 124 dict_entry_reader.PopVariantOfUint16(&options.features); |
126 } | 125 } |
127 } | 126 } |
128 | 127 |
129 Delegate::ConfirmationCallback callback = base::Bind( | 128 Delegate::ConfirmationCallback callback = base::Bind( |
130 &BluetoothProfileServiceProviderImpl::OnConfirmation, | 129 &BluetoothProfileServiceProviderImpl::OnConfirmation, |
131 weak_ptr_factory_.GetWeakPtr(), | 130 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender); |
132 method_call, | |
133 response_sender); | |
134 | 131 |
135 delegate_->NewConnection(device_path, fd.Pass(), options, callback); | 132 delegate_->NewConnection(device_path, fd.Pass(), options, callback); |
136 } | 133 } |
137 | 134 |
138 // Called by dbus:: when the Bluetooth daemon is about to disconnect the | 135 // Called by dbus:: when the Bluetooth daemon is about to disconnect the |
139 // profile. | 136 // profile. |
140 void RequestDisconnection( | 137 void RequestDisconnection( |
141 dbus::MethodCall* method_call, | 138 dbus::MethodCall* method_call, |
142 dbus::ExportedObject::ResponseSender response_sender) { | 139 dbus::ExportedObject::ResponseSender response_sender) { |
143 DCHECK(OnOriginThread()); | 140 DCHECK(OnOriginThread()); |
144 DCHECK(delegate_); | 141 DCHECK(delegate_); |
145 | 142 |
146 dbus::MessageReader reader(method_call); | 143 dbus::MessageReader reader(method_call); |
147 dbus::ObjectPath device_path; | 144 dbus::ObjectPath device_path; |
148 if (!reader.PopObjectPath(&device_path)) { | 145 if (!reader.PopObjectPath(&device_path)) { |
149 LOG(WARNING) << "RequestDisconnection called with incorrect paramters: " | 146 LOG(WARNING) << "RequestDisconnection called with incorrect paramters: " |
150 << method_call->ToString(); | 147 << method_call->ToString(); |
151 return; | 148 return; |
152 } | 149 } |
153 | 150 |
154 Delegate::ConfirmationCallback callback = base::Bind( | 151 Delegate::ConfirmationCallback callback = base::Bind( |
155 &BluetoothProfileServiceProviderImpl::OnConfirmation, | 152 &BluetoothProfileServiceProviderImpl::OnConfirmation, |
156 weak_ptr_factory_.GetWeakPtr(), | 153 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender); |
157 method_call, | |
158 response_sender); | |
159 | 154 |
160 delegate_->RequestDisconnection(device_path, callback); | 155 delegate_->RequestDisconnection(device_path, callback); |
161 } | 156 } |
162 | 157 |
163 // Called by dbus:: when the request failed before a reply was returned | 158 // Called by dbus:: when the request failed before a reply was returned |
164 // from the device. | 159 // from the device. |
165 void Cancel(dbus::MethodCall* method_call, | 160 void Cancel(dbus::MethodCall* method_call, |
166 dbus::ExportedObject::ResponseSender response_sender) { | 161 dbus::ExportedObject::ResponseSender response_sender) { |
167 DCHECK(OnOriginThread()); | 162 DCHECK(OnOriginThread()); |
168 DCHECK(delegate_); | 163 DCHECK(delegate_); |
169 | 164 |
170 delegate_->Cancel(); | 165 delegate_->Cancel(); |
171 | 166 |
172 response_sender.Run(dbus::Response::FromMethodCall(method_call)); | 167 response_sender.Run(dbus::Response::FromMethodCall(method_call)); |
173 } | 168 } |
174 | 169 |
175 // Called by dbus:: when a method is exported. | 170 // Called by dbus:: when a method is exported. |
176 void OnExported(const std::string& interface_name, | 171 void OnExported(const std::string& interface_name, |
177 const std::string& method_name, | 172 const std::string& method_name, |
178 bool success) { | 173 bool success) { |
179 LOG_IF(WARNING, !success) << "Failed to export " | 174 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." |
180 << interface_name << "." << method_name; | 175 << method_name; |
181 } | 176 } |
182 | 177 |
183 // Called by the Delegate in response to a method requiring confirmation. | 178 // Called by the Delegate in response to a method requiring confirmation. |
184 void OnConfirmation(dbus::MethodCall* method_call, | 179 void OnConfirmation(dbus::MethodCall* method_call, |
185 dbus::ExportedObject::ResponseSender response_sender, | 180 dbus::ExportedObject::ResponseSender response_sender, |
186 Delegate::Status status) { | 181 Delegate::Status status) { |
187 DCHECK(OnOriginThread()); | 182 DCHECK(OnOriginThread()); |
188 | 183 |
189 switch (status) { | 184 switch (status) { |
190 case Delegate::SUCCESS: { | 185 case Delegate::SUCCESS: { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 222 |
228 // Weak pointer factory for generating 'this' pointers that might live longer | 223 // Weak pointer factory for generating 'this' pointers that might live longer |
229 // than we do. | 224 // than we do. |
230 // Note: This should remain the last member so it'll be destroyed and | 225 // Note: This should remain the last member so it'll be destroyed and |
231 // invalidate its weak pointers before any other members are destroyed. | 226 // invalidate its weak pointers before any other members are destroyed. |
232 base::WeakPtrFactory<BluetoothProfileServiceProviderImpl> weak_ptr_factory_; | 227 base::WeakPtrFactory<BluetoothProfileServiceProviderImpl> weak_ptr_factory_; |
233 | 228 |
234 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileServiceProviderImpl); | 229 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileServiceProviderImpl); |
235 }; | 230 }; |
236 | 231 |
237 BluetoothProfileServiceProvider::BluetoothProfileServiceProvider() { | 232 BluetoothProfileServiceProvider::BluetoothProfileServiceProvider() {} |
238 } | |
239 | 233 |
240 BluetoothProfileServiceProvider::~BluetoothProfileServiceProvider() { | 234 BluetoothProfileServiceProvider::~BluetoothProfileServiceProvider() {} |
241 } | |
242 | 235 |
243 // static | 236 // static |
244 BluetoothProfileServiceProvider* BluetoothProfileServiceProvider::Create( | 237 BluetoothProfileServiceProvider* BluetoothProfileServiceProvider::Create( |
245 dbus::Bus* bus, | 238 dbus::Bus* bus, |
246 const dbus::ObjectPath& object_path, | 239 const dbus::ObjectPath& object_path, |
247 Delegate* delegate) { | 240 Delegate* delegate) { |
248 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { | 241 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) { |
249 return new BluetoothProfileServiceProviderImpl(bus, object_path, delegate); | 242 return new BluetoothProfileServiceProviderImpl(bus, object_path, delegate); |
250 } else { | 243 } else { |
251 return new FakeBluetoothProfileServiceProvider(object_path, delegate); | 244 return new FakeBluetoothProfileServiceProvider(object_path, delegate); |
252 } | 245 } |
253 } | 246 } |
254 | 247 |
255 } // namespace chromeos | 248 } // namespace bluez |
OLD | NEW |