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 CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EXTENSION_FUNCTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EXTENSION_FUNCTION_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EXTENSION_FUNCTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EXTENSION_FUNCTION_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" |
9 #include "chrome/browser/extensions/extension_function.h" | 10 #include "chrome/browser/extensions/extension_function.h" |
10 | 11 |
11 namespace device { | 12 namespace device { |
12 | 13 |
13 class BluetoothAdapter; | 14 class BluetoothAdapter; |
14 | 15 |
15 } // namespace device | 16 } // namespace device |
16 | 17 |
17 namespace extensions { | 18 namespace extensions { |
18 | 19 |
19 namespace api { | 20 namespace api { |
20 | 21 |
21 // Base class for bluetooth extension functions. This class initializes | 22 // Base class for bluetooth extension functions. This class initializes |
22 // bluetooth adapter and calls DoWork() implemented by individual bluetooth | 23 // bluetooth adapter and calls DoWork() implemented by individual bluetooth |
23 // extension functions. | 24 // extension functions. |
24 class BluetoothExtensionFunction : public AsyncExtensionFunction { | 25 class BluetoothExtensionFunction : public AsyncExtensionFunction { |
25 public: | 26 public: |
26 BluetoothExtensionFunction(); | 27 BluetoothExtensionFunction(); |
27 | 28 |
28 protected: | 29 protected: |
29 virtual ~BluetoothExtensionFunction(); | 30 virtual ~BluetoothExtensionFunction(); |
30 | 31 |
31 // ExtensionFunction: | 32 // ExtensionFunction: |
32 virtual bool RunImpl() OVERRIDE; | 33 virtual bool RunImpl() OVERRIDE; |
33 | 34 |
34 private: | 35 private: |
| 36 void RunOnAdapterReady(scoped_refptr<device::BluetoothAdapter> adapter); |
| 37 |
35 // Implemented by individual bluetooth extension functions, called | 38 // Implemented by individual bluetooth extension functions, called |
36 // automatically once |adapter| has been initialized. | 39 // automatically once |adapter| has been initialized. |
37 virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) = 0; | 40 virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) = 0; |
| 41 |
| 42 base::WeakPtrFactory<BluetoothExtensionFunction> weak_ptr_factory_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(BluetoothExtensionFunction); |
38 }; | 45 }; |
39 | 46 |
40 } // namespace api | 47 } // namespace api |
41 | 48 |
42 } // namespace extensions | 49 } // namespace extensions |
43 | 50 |
44 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EXTENSION_FUNCTION_
H_ | 51 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EXTENSION_FUNCTION_
H_ |
OLD | NEW |