| 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 "chromeos/dbus/bluetooth_le_advertisement_service_provider.h" | 5 #include "chromeos/dbus/bluetooth_le_advertisement_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/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 const dbus::ObjectPath& object_path, | 30 const dbus::ObjectPath& object_path, |
| 31 Delegate* delegate, | 31 Delegate* delegate, |
| 32 AdvertisementType type, | 32 AdvertisementType type, |
| 33 scoped_ptr<UUIDList> service_uuids, | 33 scoped_ptr<UUIDList> service_uuids, |
| 34 scoped_ptr<ManufacturerData> manufacturer_data, | 34 scoped_ptr<ManufacturerData> manufacturer_data, |
| 35 scoped_ptr<UUIDList> solicit_uuids, | 35 scoped_ptr<UUIDList> solicit_uuids, |
| 36 scoped_ptr<ServiceData> service_data) | 36 scoped_ptr<ServiceData> service_data) |
| 37 : origin_thread_id_(base::PlatformThread::CurrentId()), | 37 : origin_thread_id_(base::PlatformThread::CurrentId()), |
| 38 bus_(bus), | 38 bus_(bus), |
| 39 delegate_(delegate), | 39 delegate_(delegate), |
| 40 object_path_(object_path), |
| 40 type_(type), | 41 type_(type), |
| 41 service_uuids_(service_uuids.Pass()), | 42 service_uuids_(service_uuids.Pass()), |
| 42 manufacturer_data_(manufacturer_data.Pass()), | 43 manufacturer_data_(manufacturer_data.Pass()), |
| 43 solicit_uuids_(solicit_uuids.Pass()), | 44 solicit_uuids_(solicit_uuids.Pass()), |
| 44 service_data_(service_data.Pass()), | 45 service_data_(service_data.Pass()), |
| 45 weak_ptr_factory_(this) { | 46 weak_ptr_factory_(this) { |
| 46 DCHECK(bus); | 47 DCHECK(bus); |
| 47 DCHECK(delegate); | 48 DCHECK(delegate); |
| 48 | 49 |
| 49 VLOG(1) << "Creating Bluetooth Advertisement: " << object_path_.value(); | 50 VLOG(1) << "Creating Bluetooth Advertisement: " << object_path_.value(); |
| 50 | 51 |
| 51 object_path_ = object_path; | |
| 52 exported_object_ = bus_->GetExportedObject(object_path_); | 52 exported_object_ = bus_->GetExportedObject(object_path_); |
| 53 | 53 |
| 54 // Export Bluetooth Advertisement interface methods. | 54 // Export Bluetooth Advertisement interface methods. |
| 55 exported_object_->ExportMethod( | 55 exported_object_->ExportMethod( |
| 56 bluetooth_advertisement::kBluetoothAdvertisementIntervace, | 56 bluetooth_advertisement::kBluetoothAdvertisementIntervace, |
| 57 bluetooth_advertisement::kRelease, | 57 bluetooth_advertisement::kRelease, |
| 58 base::Bind(&BluetoothAdvertisementServiceProviderImpl::Release, | 58 base::Bind(&BluetoothAdvertisementServiceProviderImpl::Release, |
| 59 weak_ptr_factory_.GetWeakPtr()), | 59 weak_ptr_factory_.GetWeakPtr()), |
| 60 base::Bind(&BluetoothAdvertisementServiceProviderImpl::OnExported, | 60 base::Bind(&BluetoothAdvertisementServiceProviderImpl::OnExported, |
| 61 weak_ptr_factory_.GetWeakPtr())); | 61 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 351 |
| 352 // D-Bus bus object is exported on, not owned by this object and must | 352 // D-Bus bus object is exported on, not owned by this object and must |
| 353 // outlive it. | 353 // outlive it. |
| 354 dbus::Bus* bus_; | 354 dbus::Bus* bus_; |
| 355 | 355 |
| 356 // All incoming method calls are passed on to the Delegate and a callback | 356 // All incoming method calls are passed on to the Delegate and a callback |
| 357 // passed to generate the reply. |delegate_| is generally the object that | 357 // passed to generate the reply. |delegate_| is generally the object that |
| 358 // owns this one, and must outlive it. | 358 // owns this one, and must outlive it. |
| 359 Delegate* delegate_; | 359 Delegate* delegate_; |
| 360 | 360 |
| 361 // D-Bus object path of object we are exporting, kept so we can unregister |
| 362 // again in our destructor. |
| 363 dbus::ObjectPath object_path_; |
| 364 |
| 361 // Advertisement data that needs to be provided to BlueZ when requested. | 365 // Advertisement data that needs to be provided to BlueZ when requested. |
| 362 AdvertisementType type_; | 366 AdvertisementType type_; |
| 363 scoped_ptr<UUIDList> service_uuids_; | 367 scoped_ptr<UUIDList> service_uuids_; |
| 364 scoped_ptr<ManufacturerData> manufacturer_data_; | 368 scoped_ptr<ManufacturerData> manufacturer_data_; |
| 365 scoped_ptr<UUIDList> solicit_uuids_; | 369 scoped_ptr<UUIDList> solicit_uuids_; |
| 366 scoped_ptr<ServiceData> service_data_; | 370 scoped_ptr<ServiceData> service_data_; |
| 367 | 371 |
| 368 // D-Bus object we are exporting, owned by this object. | 372 // D-Bus object we are exporting, owned by this object. |
| 369 scoped_refptr<dbus::ExportedObject> exported_object_; | 373 scoped_refptr<dbus::ExportedObject> exported_object_; |
| 370 | 374 |
| 371 // Weak pointer factory for generating 'this' pointers that might live longer | 375 // Weak pointer factory for generating 'this' pointers that might live longer |
| 372 // than we do. | 376 // than we do. |
| 373 // Note: This should remain the last member so it'll be destroyed and | 377 // Note: This should remain the last member so it'll be destroyed and |
| 374 // invalidate its weak pointers before any other members are destroyed. | 378 // invalidate its weak pointers before any other members are destroyed. |
| 375 base::WeakPtrFactory<BluetoothAdvertisementServiceProviderImpl> | 379 base::WeakPtrFactory<BluetoothAdvertisementServiceProviderImpl> |
| 376 weak_ptr_factory_; | 380 weak_ptr_factory_; |
| 377 | 381 |
| 378 DISALLOW_COPY_AND_ASSIGN(BluetoothAdvertisementServiceProviderImpl); | 382 DISALLOW_COPY_AND_ASSIGN(BluetoothAdvertisementServiceProviderImpl); |
| 379 }; | 383 }; |
| 380 | 384 |
| 381 BluetoothLEAdvertisementServiceProvider:: | 385 BluetoothLEAdvertisementServiceProvider:: |
| 382 BluetoothLEAdvertisementServiceProvider() { | 386 BluetoothLEAdvertisementServiceProvider() { |
| 383 } | 387 } |
| 384 | 388 |
| 385 BluetoothLEAdvertisementServiceProvider:: | 389 BluetoothLEAdvertisementServiceProvider:: |
| 386 ~BluetoothLEAdvertisementServiceProvider() { | 390 ~BluetoothLEAdvertisementServiceProvider() { |
| 387 } | 391 } |
| 388 | 392 |
| 389 // static | 393 // static |
| 390 scoped_ptr<BluetoothLEAdvertisementServiceProvider> | 394 BluetoothLEAdvertisementServiceProvider* |
| 391 BluetoothLEAdvertisementServiceProvider::Create( | 395 BluetoothLEAdvertisementServiceProvider::Create( |
| 392 dbus::Bus* bus, | 396 dbus::Bus* bus, |
| 393 const dbus::ObjectPath& object_path, | 397 const dbus::ObjectPath& object_path, |
| 394 Delegate* delegate, | 398 Delegate* delegate, |
| 395 AdvertisementType type, | 399 AdvertisementType type, |
| 396 scoped_ptr<UUIDList> service_uuids, | 400 scoped_ptr<UUIDList> service_uuids, |
| 397 scoped_ptr<ManufacturerData> manufacturer_data, | 401 scoped_ptr<ManufacturerData> manufacturer_data, |
| 398 scoped_ptr<UUIDList> solicit_uuids, | 402 scoped_ptr<UUIDList> solicit_uuids, |
| 399 scoped_ptr<ServiceData> service_data) { | 403 scoped_ptr<ServiceData> service_data) { |
| 400 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { | 404 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { |
| 401 return make_scoped_ptr(new BluetoothAdvertisementServiceProviderImpl( | 405 return new BluetoothAdvertisementServiceProviderImpl( |
| 402 bus, object_path, delegate, type, service_uuids.Pass(), | 406 bus, object_path, delegate, type, service_uuids.Pass(), |
| 403 manufacturer_data.Pass(), solicit_uuids.Pass(), service_data.Pass())); | 407 manufacturer_data.Pass(), solicit_uuids.Pass(), service_data.Pass()); |
| 404 } else { | 408 } else { |
| 405 return make_scoped_ptr( | 409 return new FakeBluetoothLEAdvertisementServiceProvider(object_path, |
| 406 new FakeBluetoothLEAdvertisementServiceProvider(object_path, delegate)); | 410 delegate); |
| 407 } | 411 } |
| 408 } | 412 } |
| 409 | 413 |
| 410 } // namespace chromeos | 414 } // namespace chromeos |
| OLD | NEW |