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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_HOTWORD_PRIVATE_HOTWORD_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_HOTWORD_PRIVATE_HOTWORD_PRIVATE_API_H_
8 #include "base/prefs/pref_change_registrar.h"
9 #include "base/values.h"
10 #include "chrome/browser/extensions/chrome_extension_function.h"
11 #include "chrome/common/extensions/api/hotword_private.h"
12 #include "extensions/browser/browser_context_keyed_api_factory.h"
13 #include "extensions/browser/extension_event_histogram_value.h"
17 namespace extensions
{
19 // Listens for changes in disable/enabled state and forwards as an extension
21 class HotwordPrivateEventService
: public BrowserContextKeyedAPI
{
23 explicit HotwordPrivateEventService(content::BrowserContext
* context
);
24 ~HotwordPrivateEventService() override
;
26 // BrowserContextKeyedAPI implementation.
27 void Shutdown() override
;
28 static BrowserContextKeyedAPIFactory
<HotwordPrivateEventService
>*
30 static const char* service_name();
32 void OnEnabledChanged(const std::string
& pref_name
);
34 void OnHotwordSessionRequested();
36 void OnHotwordSessionStopped();
38 void OnHotwordTriggered();
40 void OnFinalizeSpeakerModel();
42 void OnSpeakerModelSaved();
44 void OnDeleteSpeakerModel();
46 void OnSpeakerModelExists();
48 void OnMicrophoneStateChanged(bool enabled
);
51 friend class BrowserContextKeyedAPIFactory
<HotwordPrivateEventService
>;
53 void SignalEvent(events::HistogramValue histogram_value
,
54 const std::string
& event_name
);
55 void SignalEvent(events::HistogramValue histogram_value
,
56 const std::string
& event_name
,
57 scoped_ptr
<base::ListValue
> args
);
60 PrefChangeRegistrar pref_change_registrar_
;
64 class HotwordPrivateSetEnabledFunction
: public ChromeSyncExtensionFunction
{
66 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setEnabled",
67 HOTWORDPRIVATE_SETENABLED
)
70 ~HotwordPrivateSetEnabledFunction() override
{}
73 bool RunSync() override
;
76 class HotwordPrivateSetAudioLoggingEnabledFunction
77 : public ChromeSyncExtensionFunction
{
79 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setAudioLoggingEnabled",
80 HOTWORDPRIVATE_SETAUDIOLOGGINGENABLED
)
83 ~HotwordPrivateSetAudioLoggingEnabledFunction() override
{}
86 bool RunSync() override
;
89 class HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction
90 : public ChromeSyncExtensionFunction
{
92 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setHotwordAlwaysOnSearchEnabled",
93 HOTWORDPRIVATE_SETHOTWORDALWAYSONSEARCHENABLED
)
96 ~HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction() override
{}
99 bool RunSync() override
;
102 class HotwordPrivateGetStatusFunction
: public ChromeSyncExtensionFunction
{
104 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getStatus",
105 HOTWORDPRIVATE_GETSTATUS
)
108 ~HotwordPrivateGetStatusFunction() override
{}
110 // ExtensionFunction:
111 bool RunSync() override
;
114 class HotwordPrivateSetHotwordSessionStateFunction
115 : public ChromeSyncExtensionFunction
{
117 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setHotwordSessionState",
118 HOTWORDPRIVATE_SETHOTWORDSESSIONSTATE
);
121 ~HotwordPrivateSetHotwordSessionStateFunction() override
{}
123 // ExtensionFunction:
124 bool RunSync() override
;
127 class HotwordPrivateNotifyHotwordRecognitionFunction
128 : public ChromeSyncExtensionFunction
{
130 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.notifyHotwordRecognition",
131 HOTWORDPRIVATE_NOTIFYHOTWORDRECOGNITION
);
134 ~HotwordPrivateNotifyHotwordRecognitionFunction() override
{}
136 // ExtensionFunction:
137 bool RunSync() override
;
140 class HotwordPrivateGetLaunchStateFunction
:
141 public ChromeSyncExtensionFunction
{
143 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getLaunchState",
144 HOTWORDPRIVATE_GETLAUNCHSTATE
)
147 ~HotwordPrivateGetLaunchStateFunction() override
{}
149 // ExtensionFunction:
150 bool RunSync() override
;
153 class HotwordPrivateStartTrainingFunction
:
154 public ChromeSyncExtensionFunction
{
156 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.startTraining",
157 HOTWORDPRIVATE_STARTTRAINING
)
160 ~HotwordPrivateStartTrainingFunction() override
{}
162 // ExtensionFunction:
163 bool RunSync() override
;
166 class HotwordPrivateFinalizeSpeakerModelFunction
:
167 public ChromeSyncExtensionFunction
{
169 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.finalizeSpeakerModel",
170 HOTWORDPRIVATE_FINALIZESPEAKERMODEL
)
173 ~HotwordPrivateFinalizeSpeakerModelFunction() override
{}
175 // ExtensionFunction:
176 bool RunSync() override
;
179 class HotwordPrivateNotifySpeakerModelSavedFunction
:
180 public ChromeSyncExtensionFunction
{
182 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.notifySpeakerModelSaved",
183 HOTWORDPRIVATE_NOTIFYSPEAKERMODELSAVED
)
186 ~HotwordPrivateNotifySpeakerModelSavedFunction() override
{}
188 // ExtensionFunction:
189 bool RunSync() override
;
192 class HotwordPrivateStopTrainingFunction
:
193 public ChromeSyncExtensionFunction
{
195 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.stopTraining",
196 HOTWORDPRIVATE_STOPTRAINING
)
199 ~HotwordPrivateStopTrainingFunction() override
{}
201 // ExtensionFunction:
202 bool RunSync() override
;
205 class HotwordPrivateGetLocalizedStringsFunction
206 : public ChromeSyncExtensionFunction
{
208 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getLocalizedStrings",
209 HOTWORDPRIVATE_GETLOCALIZEDSTRINGS
)
212 ~HotwordPrivateGetLocalizedStringsFunction() override
{}
214 // ExtensionFunction:
215 bool RunSync() override
;
218 class HotwordPrivateSetAudioHistoryEnabledFunction
219 : public ChromeAsyncExtensionFunction
{
221 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setAudioHistoryEnabled",
222 HOTWORDPRIVATE_SETAUDIOHISTORYENABLED
)
225 ~HotwordPrivateSetAudioHistoryEnabledFunction() override
{}
227 // ExtensionFunction:
228 bool RunAsync() override
;
230 void SetResultAndSendResponse(bool success
, bool new_enabled_value
);
233 class HotwordPrivateGetAudioHistoryEnabledFunction
234 : public ChromeAsyncExtensionFunction
{
236 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getAudioHistoryEnabled",
237 HOTWORDPRIVATE_GETAUDIOHISTORYENABLED
)
240 ~HotwordPrivateGetAudioHistoryEnabledFunction() override
{}
242 // ExtensionFunction:
243 bool RunAsync() override
;
245 void SetResultAndSendResponse(bool success
, bool new_enabled_value
);
248 class HotwordPrivateSpeakerModelExistsResultFunction
:
249 public ChromeSyncExtensionFunction
{
251 DECLARE_EXTENSION_FUNCTION("hotwordPrivate.speakerModelExistsResult",
252 HOTWORDPRIVATE_SPEAKERMODELEXISTSRESULT
)
255 ~HotwordPrivateSpeakerModelExistsResultFunction() override
{}
257 // ExtensionFunction:
258 bool RunSync() override
;
261 } // namespace extensions
263 #endif // CHROME_BROWSER_EXTENSIONS_API_HOTWORD_PRIVATE_HOTWORD_PRIVATE_API_H_