OLD | NEW |
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_FACTORY_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 | 12 |
12 namespace device { | 13 namespace device { |
13 | 14 |
14 class BluetoothAdapter; | 15 class BluetoothAdapter; |
15 | 16 |
16 // BluetoothAdapterFactory is a class that contains static methods, which | 17 // BluetoothAdapterFactory is a class that contains static methods, which |
17 // instantiate either a specific bluetooth adapter, or the generic "default | 18 // instantiate either a specific Bluetooth adapter, or the generic "default |
18 // adapter" which may change depending on availability. | 19 // adapter" which may change depending on availability. |
19 class BluetoothAdapterFactory { | 20 class BluetoothAdapterFactory { |
20 public: | 21 public: |
21 // Returns the shared instance for the default adapter, whichever that may | 22 typedef base::Callback<void(scoped_refptr<device::BluetoothAdapter> adapter)> |
22 // be at the time. Check the returned scoped_refptr does not point to NULL and | 23 AdapterCallback; |
23 // use IsPresent() and the AdapterPresentChanged() observer method to | 24 |
24 // determine whether an adapter is actually available or not. | 25 // Returns true if the Bluetooth adapter is available for the current |
25 static scoped_refptr<BluetoothAdapter> DefaultAdapter(); | 26 // platform. |
| 27 static bool IsBluetoothAdapterAvailable(); |
| 28 |
| 29 // Runs the callback with the shared instance for the default adapter when the |
| 30 // adapter is available to be used. |
| 31 static void RunCallbackOnAdapterReady(const AdapterCallback& callback); |
| 32 |
| 33 // Returns the shared instance of the adapter that has already been created. |
| 34 // It returns NULL if no adapter has been created at the time. |
| 35 static scoped_refptr<BluetoothAdapter> GetAdapter(); |
26 | 36 |
27 // Creates an instance for a specific adapter at address |address|. | 37 // Creates an instance for a specific adapter at address |address|. |
28 static BluetoothAdapter* Create(const std::string& address); | 38 static BluetoothAdapter* Create(const std::string& address); |
29 }; | 39 }; |
30 | 40 |
31 } // namespace device | 41 } // namespace device |
32 | 42 |
33 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ | 43 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ |
OLD | NEW |