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

Side by Side Diff: device/bluetooth/bluetooth_adapter.h

Issue 812673002: bluetooth: BluetoothAdapterDeleter used to control BluetoothAdapter destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Created 6 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "device/bluetooth/bluetooth_device.h" 17 #include "device/bluetooth/bluetooth_device.h"
18 #include "device/bluetooth/bluetooth_export.h" 18 #include "device/bluetooth/bluetooth_export.h"
19 19
20 namespace device { 20 namespace device {
21 21
22 class BluetoothDiscoverySession; 22 class BluetoothDiscoverySession;
23 class BluetoothGattCharacteristic; 23 class BluetoothGattCharacteristic;
24 class BluetoothGattDescriptor; 24 class BluetoothGattDescriptor;
25 class BluetoothGattService; 25 class BluetoothGattService;
26 class BluetoothSocket; 26 class BluetoothSocket;
27 class BluetoothUUID; 27 class BluetoothUUID;
28 struct BluetoothAdapterDeleter;
28 29
29 // BluetoothAdapter represents a local Bluetooth adapter which may be used to 30 // BluetoothAdapter represents a local Bluetooth adapter which may be used to
30 // interact with remote Bluetooth devices. As well as providing support for 31 // interact with remote Bluetooth devices. As well as providing support for
31 // determining whether an adapter is present and whether the radio is powered, 32 // determining whether an adapter is present and whether the radio is powered,
32 // this class also provides support for obtaining the list of remote devices 33 // this class also provides support for obtaining the list of remote devices
33 // known to the adapter, discovering new devices, and providing notification of 34 // known to the adapter, discovering new devices, and providing notification of
34 // updates to device information. 35 // updates to device information.
35 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter 36 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
36 : public base::RefCounted<BluetoothAdapter> { 37 : public base::RefCountedThreadSafe<BluetoothAdapter,
38 BluetoothAdapterDeleter> {
37 public: 39 public:
38 // Interface for observing changes from bluetooth adapters. 40 // Interface for observing changes from bluetooth adapters.
39 class Observer { 41 class Observer {
40 public: 42 public:
41 virtual ~Observer() {} 43 virtual ~Observer() {}
42 44
43 // Called when the presence of the adapter |adapter| changes. When |present| 45 // Called when the presence of the adapter |adapter| changes. When |present|
44 // is true the adapter is now present, false means the adapter has been 46 // is true the adapter is now present, false means the adapter has been
45 // removed from the system. 47 // removed from the system.
46 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, 48 virtual void AdapterPresentChanged(BluetoothAdapter* adapter,
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // BluetoothSocket instance that is to be owned by the received. 329 // BluetoothSocket instance that is to be owned by the received.
328 // |error_callback| will be called on failure with a message indicating the 330 // |error_callback| will be called on failure with a message indicating the
329 // cause. 331 // cause.
330 virtual void CreateL2capService( 332 virtual void CreateL2capService(
331 const BluetoothUUID& uuid, 333 const BluetoothUUID& uuid,
332 const ServiceOptions& options, 334 const ServiceOptions& options,
333 const CreateServiceCallback& callback, 335 const CreateServiceCallback& callback,
334 const CreateServiceErrorCallback& error_callback) = 0; 336 const CreateServiceErrorCallback& error_callback) = 0;
335 337
336 protected: 338 protected:
337 friend class base::RefCounted<BluetoothAdapter>; 339 friend class base::RefCountedThreadSafe<BluetoothAdapter,
340 BluetoothAdapterDeleter>;
341 friend struct BluetoothAdapterDeleter;
338 friend class BluetoothDiscoverySession; 342 friend class BluetoothDiscoverySession;
339 BluetoothAdapter(); 343 BluetoothAdapter();
340 virtual ~BluetoothAdapter(); 344 virtual ~BluetoothAdapter();
armansito 2014/12/16 22:01:47 nit: Empty line after destructor.
scheib 2014/12/16 22:15:26 Done.
345 // Called by RefCountedThreadSafeDeleteOnCorrectThread to destroy this.
346 virtual void DeleteOnCorrectThread() const = 0;
341 347
342 // Internal methods for initiating and terminating device discovery sessions. 348 // Internal methods for initiating and terminating device discovery sessions.
343 // An implementation of BluetoothAdapter keeps an internal reference count to 349 // An implementation of BluetoothAdapter keeps an internal reference count to
344 // make sure that the underlying controller is constantly searching for nearby 350 // make sure that the underlying controller is constantly searching for nearby
345 // devices and retrieving information from them as long as there are clients 351 // devices and retrieving information from them as long as there are clients
346 // who have requested discovery. These methods behave in the following way: 352 // who have requested discovery. These methods behave in the following way:
347 // 353 //
348 // On a call to AddDiscoverySession: 354 // On a call to AddDiscoverySession:
349 // - If there is a pending request to the subsystem, queue this request to 355 // - If there is a pending request to the subsystem, queue this request to
350 // execute once the pending requests are done. 356 // execute once the pending requests are done.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // will remove itself from this list when it gets destroyed or becomes 419 // will remove itself from this list when it gets destroyed or becomes
414 // inactive by calling DiscoverySessionBecameInactive(), hence no pointers to 420 // inactive by calling DiscoverySessionBecameInactive(), hence no pointers to
415 // deallocated sessions are kept. 421 // deallocated sessions are kept.
416 std::set<BluetoothDiscoverySession*> discovery_sessions_; 422 std::set<BluetoothDiscoverySession*> discovery_sessions_;
417 423
418 // Note: This should remain the last member so it'll be destroyed and 424 // Note: This should remain the last member so it'll be destroyed and
419 // invalidate its weak pointers before any other members are destroyed. 425 // invalidate its weak pointers before any other members are destroyed.
420 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; 426 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_;
421 }; 427 };
422 428
429 // Trait for RefCountedThreadSafe that deletes BluetoothAdapter.
430 struct BluetoothAdapterDeleter {
431 static void Destruct(const BluetoothAdapter* adapter) {
432 adapter->DeleteOnCorrectThread();
433 }
434 };
435
423 } // namespace device 436 } // namespace device
424 437
425 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 438 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_chromeos.h » ('j') | device/bluetooth/bluetooth_adapter_chromeos.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698