Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / braille_display_private / braille_display_private_api.h
blobc1b23e77e722f46b246a430ed0cfdfc55d242ee9
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRAILLE_DISPLAY_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRAILLE_DISPLAY_PRIVATE_API_H_
8 #include "base/scoped_observer.h"
9 #include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
10 #include "chrome/common/extensions/api/braille_display_private.h"
11 #include "extensions/browser/api/async_api_function.h"
12 #include "extensions/browser/browser_context_keyed_api_factory.h"
13 #include "extensions/browser/event_router.h"
15 class Profile;
17 namespace extensions {
18 namespace api {
19 namespace braille_display_private {
20 class BrailleDisplayPrivateAPIUserTest;
21 } // namespace braille_display_private
22 } // namespace api
24 // Implementation of the chrome.brailleDisplayPrivate API.
25 class BrailleDisplayPrivateAPI : public BrowserContextKeyedAPI,
26 api::braille_display_private::BrailleObserver,
27 EventRouter::Observer {
28 public:
29 explicit BrailleDisplayPrivateAPI(content::BrowserContext* context);
30 ~BrailleDisplayPrivateAPI() override;
32 // ProfileKeyedService implementation.
33 void Shutdown() override;
35 // BrowserContextKeyedAPI implementation.
36 static BrowserContextKeyedAPIFactory<BrailleDisplayPrivateAPI>*
37 GetFactoryInstance();
39 // BrailleObserver implementation.
40 void OnBrailleDisplayStateChanged(
41 const api::braille_display_private::DisplayState& display_state) override;
42 void OnBrailleKeyEvent(
43 const api::braille_display_private::KeyEvent& keyEvent) override;
45 // EventRouter::Observer implementation.
46 void OnListenerAdded(const EventListenerInfo& details) override;
47 void OnListenerRemoved(const EventListenerInfo& details) override;
49 private:
50 friend class BrowserContextKeyedAPIFactory<BrailleDisplayPrivateAPI>;
51 friend class api::braille_display_private::BrailleDisplayPrivateAPIUserTest;
53 class EventDelegate {
54 public:
55 virtual ~EventDelegate() {}
56 virtual void BroadcastEvent(scoped_ptr<Event> event) = 0;
57 virtual bool HasListener() = 0;
60 class DefaultEventDelegate;
62 // Returns whether the profile that this API was created for is currently
63 // the active profile.
64 bool IsProfileActive();
66 void SetEventDelegateForTest(scoped_ptr<EventDelegate> delegate);
68 Profile* profile_;
69 ScopedObserver<api::braille_display_private::BrailleController,
70 BrailleObserver> scoped_observer_;
71 scoped_ptr<EventDelegate> event_delegate_;
73 // BrowserContextKeyedAPI implementation.
74 static const char* service_name() {
75 return "BrailleDisplayPrivateAPI";
77 // Override the default so the service is not created in tests.
78 static const bool kServiceIsNULLWhileTesting = true;
81 namespace api {
83 class BrailleDisplayPrivateGetDisplayStateFunction : public AsyncApiFunction {
84 DECLARE_EXTENSION_FUNCTION("brailleDisplayPrivate.getDisplayState",
85 BRAILLEDISPLAYPRIVATE_GETDISPLAYSTATE)
86 protected:
87 ~BrailleDisplayPrivateGetDisplayStateFunction() override {}
88 bool Prepare() override;
89 void Work() override;
90 bool Respond() override;
93 class BrailleDisplayPrivateWriteDotsFunction : public AsyncApiFunction {
94 DECLARE_EXTENSION_FUNCTION("brailleDisplayPrivate.writeDots",
95 BRAILLEDISPLAYPRIVATE_WRITEDOTS);
96 public:
97 BrailleDisplayPrivateWriteDotsFunction();
99 protected:
100 ~BrailleDisplayPrivateWriteDotsFunction() override;
101 bool Prepare() override;
102 void Work() override;
103 bool Respond() override;
105 private:
106 scoped_ptr<braille_display_private::WriteDots::Params> params_;
109 } // namespace api
110 } // namespace extensions
112 #endif // CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRAILLE_DISPLAY_PRIVATE_API_H_