1 // Copyright 2014 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_PRIVATE_API_H_
6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_
8 #include "base/callback_forward.h"
9 #include "extensions/browser/api/bluetooth/bluetooth_extension_function.h"
10 #include "extensions/browser/browser_context_keyed_api_factory.h"
11 #include "extensions/browser/event_router.h"
14 class BluetoothAdapter
;
17 namespace extensions
{
19 class BluetoothApiPairingDelegate
;
21 // The profile-keyed service that manages the bluetoothPrivate extension API.
22 class BluetoothPrivateAPI
: public BrowserContextKeyedAPI
,
23 public EventRouter::Observer
{
25 static BrowserContextKeyedAPIFactory
<BluetoothPrivateAPI
>*
28 explicit BluetoothPrivateAPI(content::BrowserContext
* context
);
29 ~BluetoothPrivateAPI() override
;
31 // KeyedService implementation.
32 void Shutdown() override
;
34 // EventRouter::Observer implementation.
35 void OnListenerAdded(const EventListenerInfo
& details
) override
;
36 void OnListenerRemoved(const EventListenerInfo
& details
) override
;
38 // BrowserContextKeyedAPI implementation.
39 static const char* service_name() { return "BluetoothPrivateAPI"; }
40 static const bool kServiceRedirectedInIncognito
= true;
41 static const bool kServiceIsNULLWhileTesting
= true;
44 friend class BrowserContextKeyedAPIFactory
<BluetoothPrivateAPI
>;
46 content::BrowserContext
* browser_context_
;
51 class BluetoothPrivateSetAdapterStateFunction
52 : public BluetoothExtensionFunction
{
54 DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setAdapterState",
55 BLUETOOTHPRIVATE_SETADAPTERSTATE
)
56 BluetoothPrivateSetAdapterStateFunction();
59 ~BluetoothPrivateSetAdapterStateFunction() override
;
61 base::Closure
CreatePropertySetCallback(const std::string
& property_name
);
62 base::Closure
CreatePropertyErrorCallback(const std::string
& property_name
);
63 void OnAdapterPropertySet(const std::string
& property
);
64 void OnAdapterPropertyError(const std::string
& property
);
67 // BluetoothExtensionFunction overrides:
68 bool DoWork(scoped_refptr
<device::BluetoothAdapter
> adapter
) override
;
70 // Set of expected adapter properties to be changed.
71 std::set
<std::string
> pending_properties_
;
73 // Set of adapter properties that were not set successfully.
74 std::set
<std::string
> failed_properties_
;
76 DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetAdapterStateFunction
);
79 class BluetoothPrivateSetPairingResponseFunction
80 : public BluetoothExtensionFunction
{
82 DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setPairingResponse",
83 BLUETOOTHPRIVATE_SETPAIRINGRESPONSE
)
84 BluetoothPrivateSetPairingResponseFunction();
85 // BluetoothExtensionFunction overrides:
86 bool DoWork(scoped_refptr
<device::BluetoothAdapter
> adapter
) override
;
89 ~BluetoothPrivateSetPairingResponseFunction() override
;
90 DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetPairingResponseFunction
);
93 class BluetoothPrivateDisconnectAllFunction
94 : public BluetoothExtensionFunction
{
96 DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.disconnectAll",
97 BLUETOOTHPRIVATE_DISCONNECTALL
);
98 BluetoothPrivateDisconnectAllFunction();
100 // BluetoothExtensionFunction overrides:
101 bool DoWork(scoped_refptr
<device::BluetoothAdapter
> adapter
) override
;
104 ~BluetoothPrivateDisconnectAllFunction() override
;
106 void OnSuccessCallback();
107 void OnErrorCallback(scoped_refptr
<device::BluetoothAdapter
> adapter
,
108 const std::string
& device_address
);
110 DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateDisconnectAllFunction
);
113 class BluetoothPrivateSetDiscoveryFilterFunction
114 : public BluetoothExtensionFunction
{
116 DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setDiscoveryFilter",
117 BLUETOOTHPRIVATE_SETDISCOVERYFILTER
)
120 ~BluetoothPrivateSetDiscoveryFilterFunction() override
{}
122 // BluetoothExtensionFunction:
123 bool DoWork(scoped_refptr
<device::BluetoothAdapter
> adapter
) override
;
126 void OnSuccessCallback();
127 void OnErrorCallback();
130 } // namespace core_api
132 } // namespace extensions
134 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_