/extensions/browser/api/bluetooth/bluetooth_private_api.h

https://gitlab.com/jonnialva90/iridium-browser · C Header · 152 lines · 99 code · 39 blank · 14 comment · 0 complexity · dcacb1887e9e81871dd40b4c269d5448 MD5 · raw file

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