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"
17 namespace extensions
{
19 namespace braille_display_private
{
20 class BrailleDisplayPrivateAPIUserTest
;
21 } // namespace braille_display_private
24 // Implementation of the chrome.brailleDisplayPrivate API.
25 class BrailleDisplayPrivateAPI
: public BrowserContextKeyedAPI
,
26 api::braille_display_private::BrailleObserver
,
27 EventRouter::Observer
{
29 explicit BrailleDisplayPrivateAPI(content::BrowserContext
* context
);
30 ~BrailleDisplayPrivateAPI() override
;
32 // ProfileKeyedService implementation.
33 void Shutdown() override
;
35 // BrowserContextKeyedAPI implementation.
36 static BrowserContextKeyedAPIFactory
<BrailleDisplayPrivateAPI
>*
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
;
50 friend class BrowserContextKeyedAPIFactory
<BrailleDisplayPrivateAPI
>;
51 friend class api::braille_display_private::BrailleDisplayPrivateAPIUserTest
;
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
);
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;
83 class BrailleDisplayPrivateGetDisplayStateFunction
: public AsyncApiFunction
{
84 DECLARE_EXTENSION_FUNCTION("brailleDisplayPrivate.getDisplayState",
85 BRAILLEDISPLAYPRIVATE_GETDISPLAYSTATE
)
87 ~BrailleDisplayPrivateGetDisplayStateFunction() override
{}
88 bool Prepare() override
;
90 bool Respond() override
;
93 class BrailleDisplayPrivateWriteDotsFunction
: public AsyncApiFunction
{
94 DECLARE_EXTENSION_FUNCTION("brailleDisplayPrivate.writeDots",
95 BRAILLEDISPLAYPRIVATE_WRITEDOTS
);
97 BrailleDisplayPrivateWriteDotsFunction();
100 ~BrailleDisplayPrivateWriteDotsFunction() override
;
101 bool Prepare() override
;
102 void Work() override
;
103 bool Respond() override
;
106 scoped_ptr
<braille_display_private::WriteDots::Params
> params_
;
110 } // namespace extensions
112 #endif // CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRAILLE_DISPLAY_PRIVATE_API_H_