/chrome/browser/extensions/api/braille_display_private/braille_display_private_api.h

https://gitlab.com/0072016/Facebook-SDK- · C Header · 112 lines · 77 code · 23 blank · 12 comment · 0 complexity · d12b11cd0f5fa9f8811304267e1b9b1d MD5 · raw file

  1. // Copyright 2013 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 CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRAILLE_DISPLAY_PRIVATE_API_H_
  5. #define CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRAILLE_DISPLAY_PRIVATE_API_H_
  6. #include "base/scoped_observer.h"
  7. #include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
  8. #include "chrome/common/extensions/api/braille_display_private.h"
  9. #include "extensions/browser/api/async_api_function.h"
  10. #include "extensions/browser/browser_context_keyed_api_factory.h"
  11. #include "extensions/browser/event_router.h"
  12. class Profile;
  13. namespace extensions {
  14. namespace api {
  15. namespace braille_display_private {
  16. class BrailleDisplayPrivateAPIUserTest;
  17. } // namespace braille_display_private
  18. } // namespace api
  19. // Implementation of the chrome.brailleDisplayPrivate API.
  20. class BrailleDisplayPrivateAPI : public BrowserContextKeyedAPI,
  21. api::braille_display_private::BrailleObserver,
  22. EventRouter::Observer {
  23. public:
  24. explicit BrailleDisplayPrivateAPI(content::BrowserContext* context);
  25. ~BrailleDisplayPrivateAPI() override;
  26. // ProfileKeyedService implementation.
  27. void Shutdown() override;
  28. // BrowserContextKeyedAPI implementation.
  29. static BrowserContextKeyedAPIFactory<BrailleDisplayPrivateAPI>*
  30. GetFactoryInstance();
  31. // BrailleObserver implementation.
  32. void OnBrailleDisplayStateChanged(
  33. const api::braille_display_private::DisplayState& display_state) override;
  34. void OnBrailleKeyEvent(
  35. const api::braille_display_private::KeyEvent& keyEvent) override;
  36. // EventRouter::Observer implementation.
  37. void OnListenerAdded(const EventListenerInfo& details) override;
  38. void OnListenerRemoved(const EventListenerInfo& details) override;
  39. private:
  40. friend class BrowserContextKeyedAPIFactory<BrailleDisplayPrivateAPI>;
  41. friend class api::braille_display_private::BrailleDisplayPrivateAPIUserTest;
  42. class EventDelegate {
  43. public:
  44. virtual ~EventDelegate() {}
  45. virtual void BroadcastEvent(std::unique_ptr<Event> event) = 0;
  46. virtual bool HasListener() = 0;
  47. };
  48. class DefaultEventDelegate;
  49. // Returns whether the profile that this API was created for is currently
  50. // the active profile.
  51. bool IsProfileActive();
  52. void SetEventDelegateForTest(std::unique_ptr<EventDelegate> delegate);
  53. Profile* profile_;
  54. ScopedObserver<api::braille_display_private::BrailleController,
  55. BrailleObserver> scoped_observer_;
  56. std::unique_ptr<EventDelegate> event_delegate_;
  57. // BrowserContextKeyedAPI implementation.
  58. static const char* service_name() {
  59. return "BrailleDisplayPrivateAPI";
  60. }
  61. // Override the default so the service is not created in tests.
  62. static const bool kServiceIsNULLWhileTesting = true;
  63. };
  64. namespace api {
  65. class BrailleDisplayPrivateGetDisplayStateFunction : public AsyncApiFunction {
  66. DECLARE_EXTENSION_FUNCTION("brailleDisplayPrivate.getDisplayState",
  67. BRAILLEDISPLAYPRIVATE_GETDISPLAYSTATE)
  68. protected:
  69. ~BrailleDisplayPrivateGetDisplayStateFunction() override {}
  70. bool Prepare() override;
  71. void Work() override;
  72. bool Respond() override;
  73. };
  74. class BrailleDisplayPrivateWriteDotsFunction : public AsyncApiFunction {
  75. DECLARE_EXTENSION_FUNCTION("brailleDisplayPrivate.writeDots",
  76. BRAILLEDISPLAYPRIVATE_WRITEDOTS);
  77. public:
  78. BrailleDisplayPrivateWriteDotsFunction();
  79. protected:
  80. ~BrailleDisplayPrivateWriteDotsFunction() override;
  81. bool Prepare() override;
  82. void Work() override;
  83. bool Respond() override;
  84. private:
  85. std::unique_ptr<braille_display_private::WriteDots::Params> params_;
  86. };
  87. } // namespace api
  88. } // namespace extensions
  89. #endif // CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRAILLE_DISPLAY_PRIVATE_API_H_