Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: device/bluetooth/dbus/bluetooth_media_endpoint_service_provider.cc

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_media_endpoint_service_provider.h" 5 #include "device/bluetooth/dbus/bluetooth_media_endpoint_service_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "chromeos/dbus/bluetooth_media_transport_client.h"
13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h"
15 #include "dbus/exported_object.h" 12 #include "dbus/exported_object.h"
13 #include "device/bluetooth/dbus/bluetooth_media_transport_client.h"
14 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
15 #include "device/bluetooth/dbus/fake_bluetooth_media_endpoint_service_provider.h "
16 16
17 namespace { 17 namespace {
18 18
19 // TODO(mcchou): Move these constants to dbus/service_constants.h. 19 // TODO(mcchou): Move these constants to dbus/service_constants.h.
20 // Bluetooth Media Endpoint service identifier. 20 // Bluetooth Media Endpoint service identifier.
21 const char kBluetoothMediaEndpointInterface[] = "org.bluez.MediaEndpoint1"; 21 const char kBluetoothMediaEndpointInterface[] = "org.bluez.MediaEndpoint1";
22 22
23 // Method names in Bluetooth Media Endpoint interface. 23 // Method names in Bluetooth Media Endpoint interface.
24 const char kSetConfiguration[] = "SetConfiguration"; 24 const char kSetConfiguration[] = "SetConfiguration";
25 const char kSelectConfiguration[] = "SelectConfiguration"; 25 const char kSelectConfiguration[] = "SelectConfiguration";
26 const char kClearConfiguration[] = "ClearConfiguration"; 26 const char kClearConfiguration[] = "ClearConfiguration";
27 const char kRelease[] = "Release"; 27 const char kRelease[] = "Release";
28 28
29 const uint8_t kInvalidCodec = 0xff; 29 const uint8_t kInvalidCodec = 0xff;
30 const char kInvalidState[] = "unknown"; 30 const char kInvalidState[] = "unknown";
31 31
32 } // namespace 32 } // namespace
33 33
34 namespace chromeos { 34 namespace bluez {
35 35
36 // The BluetoothMediaEndopintServiceProvider implementation used in production. 36 // The BluetoothMediaEndopintServiceProvider implementation used in production.
37 class CHROMEOS_EXPORT BluetoothMediaEndpointServiceProviderImpl 37 class DEVICE_BLUETOOTH_EXPORT BluetoothMediaEndpointServiceProviderImpl
38 : public BluetoothMediaEndpointServiceProvider { 38 : public BluetoothMediaEndpointServiceProvider {
39 public: 39 public:
40 BluetoothMediaEndpointServiceProviderImpl(dbus::Bus* bus, 40 BluetoothMediaEndpointServiceProviderImpl(dbus::Bus* bus,
41 const dbus::ObjectPath& object_path, 41 const dbus::ObjectPath& object_path,
42 Delegate* delegate) 42 Delegate* delegate)
43 : origin_thread_id_(base::PlatformThread::CurrentId()), 43 : origin_thread_id_(base::PlatformThread::CurrentId()),
44 bus_(bus), 44 bus_(bus),
45 delegate_(delegate), 45 delegate_(delegate),
46 object_path_(object_path), 46 object_path_(object_path),
47 weak_ptr_factory_(this) { 47 weak_ptr_factory_(this) {
48 VLOG(1) << "Creating Bluetooth Media Endpoint: " << object_path_.value(); 48 VLOG(1) << "Creating Bluetooth Media Endpoint: " << object_path_.value();
49 DCHECK(bus_); 49 DCHECK(bus_);
50 DCHECK(delegate_); 50 DCHECK(delegate_);
51 DCHECK(object_path_.IsValid()); 51 DCHECK(object_path_.IsValid());
52 52
53 exported_object_ = bus_->GetExportedObject(object_path_); 53 exported_object_ = bus_->GetExportedObject(object_path_);
54 54
55 exported_object_->ExportMethod( 55 exported_object_->ExportMethod(
56 kBluetoothMediaEndpointInterface, 56 kBluetoothMediaEndpointInterface, kSetConfiguration,
57 kSetConfiguration, 57 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::SetConfiguration,
58 base::Bind( 58 weak_ptr_factory_.GetWeakPtr()),
59 &BluetoothMediaEndpointServiceProviderImpl::SetConfiguration,
60 weak_ptr_factory_.GetWeakPtr()),
61 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::OnExported, 59 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::OnExported,
62 weak_ptr_factory_.GetWeakPtr())); 60 weak_ptr_factory_.GetWeakPtr()));
63 61
64 exported_object_->ExportMethod( 62 exported_object_->ExportMethod(
65 kBluetoothMediaEndpointInterface, 63 kBluetoothMediaEndpointInterface, kSelectConfiguration,
66 kSelectConfiguration,
67 base::Bind( 64 base::Bind(
68 &BluetoothMediaEndpointServiceProviderImpl::SelectConfiguration, 65 &BluetoothMediaEndpointServiceProviderImpl::SelectConfiguration,
69 weak_ptr_factory_.GetWeakPtr()), 66 weak_ptr_factory_.GetWeakPtr()),
70 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::OnExported, 67 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::OnExported,
71 weak_ptr_factory_.GetWeakPtr())); 68 weak_ptr_factory_.GetWeakPtr()));
72 69
73 exported_object_->ExportMethod( 70 exported_object_->ExportMethod(
74 kBluetoothMediaEndpointInterface, 71 kBluetoothMediaEndpointInterface, kClearConfiguration,
75 kClearConfiguration,
76 base::Bind( 72 base::Bind(
77 &BluetoothMediaEndpointServiceProviderImpl::ClearConfiguration, 73 &BluetoothMediaEndpointServiceProviderImpl::ClearConfiguration,
78 weak_ptr_factory_.GetWeakPtr()), 74 weak_ptr_factory_.GetWeakPtr()),
79 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::OnExported, 75 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::OnExported,
80 weak_ptr_factory_.GetWeakPtr())); 76 weak_ptr_factory_.GetWeakPtr()));
81 77
82 exported_object_->ExportMethod( 78 exported_object_->ExportMethod(
83 kBluetoothMediaEndpointInterface, 79 kBluetoothMediaEndpointInterface, kRelease,
84 kRelease,
85 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::Release, 80 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::Release,
86 weak_ptr_factory_.GetWeakPtr()), 81 weak_ptr_factory_.GetWeakPtr()),
87 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::OnExported, 82 base::Bind(&BluetoothMediaEndpointServiceProviderImpl::OnExported,
88 weak_ptr_factory_.GetWeakPtr())); 83 weak_ptr_factory_.GetWeakPtr()));
89 } 84 }
90 85
91 ~BluetoothMediaEndpointServiceProviderImpl() override { 86 ~BluetoothMediaEndpointServiceProviderImpl() override {
92 VLOG(1) << "Cleaning up Bluetooth Media Endpoint: " 87 VLOG(1) << "Cleaning up Bluetooth Media Endpoint: " << object_path_.value();
93 << object_path_.value();
94 88
95 bus_->UnregisterExportedObject(object_path_); 89 bus_->UnregisterExportedObject(object_path_);
96 } 90 }
97 91
98 private: 92 private:
99 // Returns true if the current thread is on the origin thread, false 93 // Returns true if the current thread is on the origin thread, false
100 // otherwise. 94 // otherwise.
101 bool OnOriginThread() const { 95 bool OnOriginThread() const {
102 return base::PlatformThread::CurrentId() == origin_thread_id_; 96 return base::PlatformThread::CurrentId() == origin_thread_id_;
103 } 97 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 << method_call->ToString(); 185 << method_call->ToString();
192 return; 186 return;
193 } 187 }
194 188
195 std::vector<uint8_t> configuration(capabilities, capabilities + length); 189 std::vector<uint8_t> configuration(capabilities, capabilities + length);
196 190
197 // |delegate_| generates the response to |SelectConfiguration| and sends it 191 // |delegate_| generates the response to |SelectConfiguration| and sends it
198 // back via |callback|. 192 // back via |callback|.
199 Delegate::SelectConfigurationCallback callback = base::Bind( 193 Delegate::SelectConfigurationCallback callback = base::Bind(
200 &BluetoothMediaEndpointServiceProviderImpl::OnConfiguration, 194 &BluetoothMediaEndpointServiceProviderImpl::OnConfiguration,
201 weak_ptr_factory_.GetWeakPtr(), 195 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender);
202 method_call,
203 response_sender);
204 196
205 delegate_->SelectConfiguration(configuration, callback); 197 delegate_->SelectConfiguration(configuration, callback);
206 } 198 }
207 199
208 // Called by dbus:: when the remote device is about to close the connection. 200 // Called by dbus:: when the remote device is about to close the connection.
209 void ClearConfiguration( 201 void ClearConfiguration(
210 dbus::MethodCall* method_call, 202 dbus::MethodCall* method_call,
211 dbus::ExportedObject::ResponseSender response_sender) { 203 dbus::ExportedObject::ResponseSender response_sender) {
212 VLOG(1) << "ClearConfiguration"; 204 VLOG(1) << "ClearConfiguration";
213 205
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // Note This should remain the last member so it'll be destroyed and 278 // Note This should remain the last member so it'll be destroyed and
287 // invalidate it's weak pointers before any other members are destroyed. 279 // invalidate it's weak pointers before any other members are destroyed.
288 base::WeakPtrFactory<BluetoothMediaEndpointServiceProviderImpl> 280 base::WeakPtrFactory<BluetoothMediaEndpointServiceProviderImpl>
289 weak_ptr_factory_; 281 weak_ptr_factory_;
290 282
291 DISALLOW_COPY_AND_ASSIGN(BluetoothMediaEndpointServiceProviderImpl); 283 DISALLOW_COPY_AND_ASSIGN(BluetoothMediaEndpointServiceProviderImpl);
292 }; 284 };
293 285
294 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties:: 286 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties::
295 TransportProperties() 287 TransportProperties()
296 : codec(kInvalidCodec), 288 : codec(kInvalidCodec), state(kInvalidState) {}
297 state(kInvalidState) {
298 }
299 289
300 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties:: 290 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties::
301 ~TransportProperties() { 291 ~TransportProperties() {}
302 }
303 292
304 BluetoothMediaEndpointServiceProvider::BluetoothMediaEndpointServiceProvider() { 293 BluetoothMediaEndpointServiceProvider::BluetoothMediaEndpointServiceProvider() {
305 } 294 }
306 295
307 BluetoothMediaEndpointServiceProvider:: 296 BluetoothMediaEndpointServiceProvider::
308 ~BluetoothMediaEndpointServiceProvider() { 297 ~BluetoothMediaEndpointServiceProvider() {}
309 }
310 298
311 BluetoothMediaEndpointServiceProvider* 299 BluetoothMediaEndpointServiceProvider*
312 BluetoothMediaEndpointServiceProvider::Create( 300 BluetoothMediaEndpointServiceProvider::Create(
313 dbus::Bus* bus, 301 dbus::Bus* bus,
314 const dbus::ObjectPath& object_path, 302 const dbus::ObjectPath& object_path,
315 Delegate* delegate) { 303 Delegate* delegate) {
316 // Returns a real implementation. 304 // Returns a real implementation.
317 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { 305 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) {
318 return new BluetoothMediaEndpointServiceProviderImpl( 306 return new BluetoothMediaEndpointServiceProviderImpl(bus, object_path,
319 bus, object_path, delegate); 307 delegate);
320 } 308 }
321 // Returns a fake implementation. 309 // Returns a fake implementation.
322 return new FakeBluetoothMediaEndpointServiceProvider(object_path, delegate); 310 return new FakeBluetoothMediaEndpointServiceProvider(object_path, delegate);
323 } 311 }
324 312
325 } // namespace chromeos 313 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698