Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / extensions / browser / api / bluetooth / bluetooth_api.h
blobd4f4f1fbb5081b0b2e740a17ae793df40349c7eb
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_API_H_
6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_API_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "device/bluetooth/bluetooth_device.h"
13 #include "extensions/browser/api/bluetooth/bluetooth_extension_function.h"
14 #include "extensions/browser/browser_context_keyed_api_factory.h"
15 #include "extensions/browser/event_router.h"
16 #include "extensions/browser/extension_function.h"
17 #include "extensions/common/api/bluetooth.h"
19 namespace content {
20 class BrowserContext;
23 namespace device {
24 class BluetoothAdapter;
27 namespace extensions {
29 class BluetoothEventRouter;
31 // The profile-keyed service that manages the bluetooth extension API.
32 // All methods of this class must be called on the UI thread.
33 // TODO(rpaquay): Rename this and move to separate file.
34 class BluetoothAPI : public BrowserContextKeyedAPI,
35 public EventRouter::Observer {
36 public:
37 // Convenience method to get the BluetoothAPI for a browser context.
38 static BluetoothAPI* Get(content::BrowserContext* context);
40 static BrowserContextKeyedAPIFactory<BluetoothAPI>* GetFactoryInstance();
42 explicit BluetoothAPI(content::BrowserContext* context);
43 ~BluetoothAPI() override;
45 BluetoothEventRouter* event_router();
47 // KeyedService implementation.
48 void Shutdown() override;
50 // EventRouter::Observer implementation.
51 void OnListenerAdded(const EventListenerInfo& details) override;
52 void OnListenerRemoved(const EventListenerInfo& details) override;
54 private:
55 // BrowserContextKeyedAPI implementation.
56 friend class BrowserContextKeyedAPIFactory<BluetoothAPI>;
57 static const char* service_name() { return "BluetoothAPI"; }
58 static const bool kServiceRedirectedInIncognito = true;
59 static const bool kServiceIsNULLWhileTesting = true;
61 content::BrowserContext* browser_context_;
63 // Created lazily on first access.
64 scoped_ptr<BluetoothEventRouter> event_router_;
67 namespace api {
69 class BluetoothGetAdapterStateFunction : public BluetoothExtensionFunction {
70 public:
71 DECLARE_EXTENSION_FUNCTION("bluetooth.getAdapterState",
72 BLUETOOTH_GETADAPTERSTATE)
74 protected:
75 ~BluetoothGetAdapterStateFunction() override;
77 // BluetoothExtensionFunction:
78 bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
81 class BluetoothGetDevicesFunction : public BluetoothExtensionFunction {
82 public:
83 DECLARE_EXTENSION_FUNCTION("bluetooth.getDevices", BLUETOOTH_GETDEVICES)
85 protected:
86 ~BluetoothGetDevicesFunction() override;
88 // BluetoothExtensionFunction:
89 bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
92 class BluetoothGetDeviceFunction : public BluetoothExtensionFunction {
93 public:
94 DECLARE_EXTENSION_FUNCTION("bluetooth.getDevice", BLUETOOTH_GETDEVICE)
96 // BluetoothExtensionFunction:
97 bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
99 protected:
100 ~BluetoothGetDeviceFunction() override;
103 class BluetoothStartDiscoveryFunction : public BluetoothExtensionFunction {
104 public:
105 DECLARE_EXTENSION_FUNCTION("bluetooth.startDiscovery",
106 BLUETOOTH_STARTDISCOVERY)
108 protected:
109 ~BluetoothStartDiscoveryFunction() override {}
111 // BluetoothExtensionFunction:
112 bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
114 private:
115 void OnSuccessCallback();
116 void OnErrorCallback();
119 class BluetoothStopDiscoveryFunction : public BluetoothExtensionFunction {
120 public:
121 DECLARE_EXTENSION_FUNCTION("bluetooth.stopDiscovery", BLUETOOTH_STOPDISCOVERY)
123 protected:
124 ~BluetoothStopDiscoveryFunction() override {}
126 // BluetoothExtensionFunction:
127 bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
129 private:
130 void OnSuccessCallback();
131 void OnErrorCallback();
134 } // namespace api
135 } // namespace extensions
137 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_API_H_