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. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_ 7 8 #include "base/callback_forward.h" 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h" 10 #include "extensions/browser/browser_context_keyed_api_factory.h" 11 #include "extensions/browser/event_router.h" 12 13 namespace device { 14 class BluetoothAdapter; 15 } 16 17 namespace extensions { 18 19 class BluetoothApiPairingDelegate; 20 21 // The profile-keyed service that manages the bluetoothPrivate extension API. 22 class BluetoothPrivateAPI : public BrowserContextKeyedAPI, 23 public EventRouter::Observer { 24 public: 25 static BrowserContextKeyedAPIFactory<BluetoothPrivateAPI>* 26 GetFactoryInstance(); 27 28 explicit BluetoothPrivateAPI(content::BrowserContext* context); 29 virtual ~BluetoothPrivateAPI(); 30 31 // KeyedService implementation. 32 virtual void Shutdown() OVERRIDE; 33 34 // EventRouter::Observer implementation. 35 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; 36 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; 37 38 // BrowserContextKeyedAPI implementation. service_name()39 static const char* service_name() { return "BluetoothPrivateAPI"; } 40 static const bool kServiceRedirectedInIncognito = true; 41 static const bool kServiceIsNULLWhileTesting = true; 42 43 private: 44 friend class BrowserContextKeyedAPIFactory<BluetoothPrivateAPI>; 45 46 content::BrowserContext* browser_context_; 47 }; 48 49 namespace api { 50 51 class BluetoothPrivateSetAdapterStateFunction 52 : public BluetoothExtensionFunction { 53 public: 54 DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setAdapterState", 55 BLUETOOTHPRIVATE_SETADAPTERSTATE) 56 BluetoothPrivateSetAdapterStateFunction(); 57 58 private: 59 virtual ~BluetoothPrivateSetAdapterStateFunction(); 60 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); 65 void SendError(); 66 67 // BluetoothExtensionFunction overrides: 68 virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE; 69 70 // Set of expected adapter properties to be changed. 71 std::set<std::string> pending_properties_; 72 73 // Set of adapter properties that were not set successfully. 74 std::set<std::string> failed_properties_; 75 76 DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetAdapterStateFunction); 77 }; 78 79 class BluetoothPrivateEnablePairingFunction 80 : public BluetoothExtensionFunction { 81 public: 82 DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.enablePairing", 83 BLUETOOTHPRIVATE_ENABLEPAIRING) 84 BluetoothPrivateEnablePairingFunction(); 85 // BluetoothExtensionFunction overrides: 86 virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE; 87 88 private: 89 virtual ~BluetoothPrivateEnablePairingFunction(); 90 DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateEnablePairingFunction); 91 }; 92 93 class BluetoothPrivateDisablePairingFunction 94 : public BluetoothExtensionFunction { 95 public: 96 DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.disablePairing", 97 BLUETOOTHPRIVATE_DISABLEPAIRING) 98 BluetoothPrivateDisablePairingFunction(); 99 // BluetoothExtensionFunction overrides: 100 virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE; 101 102 private: 103 virtual ~BluetoothPrivateDisablePairingFunction(); 104 DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateDisablePairingFunction); 105 }; 106 107 class BluetoothPrivateSetPairingResponseFunction 108 : public BluetoothExtensionFunction { 109 public: 110 DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setPairingResponse", 111 BLUETOOTHPRIVATE_SETPAIRINGRESPONSE) 112 BluetoothPrivateSetPairingResponseFunction(); 113 // BluetoothExtensionFunction overrides: 114 virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE; 115 116 private: 117 virtual ~BluetoothPrivateSetPairingResponseFunction(); 118 DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetPairingResponseFunction); 119 }; 120 121 } // namespace api 122 123 } // namespace extensions 124 125 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_ 126