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

Side by Side Diff: chromeos/dbus/bluetooth_le_advertisement_service_provider.cc

Issue 1054743003: Add CPP API for BLE advertisments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tentative win fix Created 5 years, 7 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 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
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),
41 type_(type), 40 type_(type),
42 service_uuids_(service_uuids.Pass()), 41 service_uuids_(service_uuids.Pass()),
43 manufacturer_data_(manufacturer_data.Pass()), 42 manufacturer_data_(manufacturer_data.Pass()),
44 solicit_uuids_(solicit_uuids.Pass()), 43 solicit_uuids_(solicit_uuids.Pass()),
45 service_data_(service_data.Pass()), 44 service_data_(service_data.Pass()),
46 weak_ptr_factory_(this) { 45 weak_ptr_factory_(this) {
47 DCHECK(bus); 46 DCHECK(bus);
48 DCHECK(delegate); 47 DCHECK(delegate);
49 48
50 VLOG(1) << "Creating Bluetooth Advertisement: " << object_path_.value(); 49 VLOG(1) << "Creating Bluetooth Advertisement: " << object_path_.value();
51 50
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
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
365 // Advertisement data that needs to be provided to BlueZ when requested. 361 // Advertisement data that needs to be provided to BlueZ when requested.
366 AdvertisementType type_; 362 AdvertisementType type_;
367 scoped_ptr<UUIDList> service_uuids_; 363 scoped_ptr<UUIDList> service_uuids_;
368 scoped_ptr<ManufacturerData> manufacturer_data_; 364 scoped_ptr<ManufacturerData> manufacturer_data_;
369 scoped_ptr<UUIDList> solicit_uuids_; 365 scoped_ptr<UUIDList> solicit_uuids_;
370 scoped_ptr<ServiceData> service_data_; 366 scoped_ptr<ServiceData> service_data_;
371 367
372 // D-Bus object we are exporting, owned by this object. 368 // D-Bus object we are exporting, owned by this object.
373 scoped_refptr<dbus::ExportedObject> exported_object_; 369 scoped_refptr<dbus::ExportedObject> exported_object_;
374 370
375 // Weak pointer factory for generating 'this' pointers that might live longer 371 // Weak pointer factory for generating 'this' pointers that might live longer
376 // than we do. 372 // than we do.
377 // Note: This should remain the last member so it'll be destroyed and 373 // Note: This should remain the last member so it'll be destroyed and
378 // invalidate its weak pointers before any other members are destroyed. 374 // invalidate its weak pointers before any other members are destroyed.
379 base::WeakPtrFactory<BluetoothAdvertisementServiceProviderImpl> 375 base::WeakPtrFactory<BluetoothAdvertisementServiceProviderImpl>
380 weak_ptr_factory_; 376 weak_ptr_factory_;
381 377
382 DISALLOW_COPY_AND_ASSIGN(BluetoothAdvertisementServiceProviderImpl); 378 DISALLOW_COPY_AND_ASSIGN(BluetoothAdvertisementServiceProviderImpl);
383 }; 379 };
384 380
385 BluetoothLEAdvertisementServiceProvider:: 381 BluetoothLEAdvertisementServiceProvider::
386 BluetoothLEAdvertisementServiceProvider() { 382 BluetoothLEAdvertisementServiceProvider() {
387 } 383 }
388 384
389 BluetoothLEAdvertisementServiceProvider:: 385 BluetoothLEAdvertisementServiceProvider::
390 ~BluetoothLEAdvertisementServiceProvider() { 386 ~BluetoothLEAdvertisementServiceProvider() {
391 } 387 }
392 388
393 // static 389 // static
394 BluetoothLEAdvertisementServiceProvider* 390 scoped_ptr<BluetoothLEAdvertisementServiceProvider>
395 BluetoothLEAdvertisementServiceProvider::Create( 391 BluetoothLEAdvertisementServiceProvider::Create(
396 dbus::Bus* bus, 392 dbus::Bus* bus,
397 const dbus::ObjectPath& object_path, 393 const dbus::ObjectPath& object_path,
398 Delegate* delegate, 394 Delegate* delegate,
399 AdvertisementType type, 395 AdvertisementType type,
400 scoped_ptr<UUIDList> service_uuids, 396 scoped_ptr<UUIDList> service_uuids,
401 scoped_ptr<ManufacturerData> manufacturer_data, 397 scoped_ptr<ManufacturerData> manufacturer_data,
402 scoped_ptr<UUIDList> solicit_uuids, 398 scoped_ptr<UUIDList> solicit_uuids,
403 scoped_ptr<ServiceData> service_data) { 399 scoped_ptr<ServiceData> service_data) {
404 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { 400 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) {
405 return new BluetoothAdvertisementServiceProviderImpl( 401 return make_scoped_ptr(new BluetoothAdvertisementServiceProviderImpl(
406 bus, object_path, delegate, type, service_uuids.Pass(), 402 bus, object_path, delegate, type, service_uuids.Pass(),
407 manufacturer_data.Pass(), solicit_uuids.Pass(), service_data.Pass()); 403 manufacturer_data.Pass(), solicit_uuids.Pass(), service_data.Pass()));
408 } else { 404 } else {
409 return new FakeBluetoothLEAdvertisementServiceProvider(object_path, 405 return make_scoped_ptr(
410 delegate); 406 new FakeBluetoothLEAdvertisementServiceProvider(object_path, delegate));
411 } 407 }
412 } 408 }
413 409
414 } // namespace chromeos 410 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698