#include "extensions/common/extension.h"
#include "ui/base/l10n/l10n_util.h"
+// The whole file relies on the extension systems but this file is built on
+// some non-extension supported platforms and including an API header will cause
+// a compile error since it depends on header files generated by .idl.
+// TODO(mukai): clean up file dependencies and remove this clause.
+#if defined(ENABLE_EXTENSIONS)
+#include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
+#endif
+
+#if defined(ENABLE_EXTENSIONS)
+using extensions::BrowserContextKeyedAPIFactory;
+using extensions::HotwordPrivateEventService;
+#endif
+
namespace {
const int kMaxTimesToShowOptInPopup = 10;
// Allowed languages for hotwording.
static const char* kSupportedLocales[] = {
"en",
- "en_us"
+ "de",
+ "fr",
+ "ru"
};
// Enum describing the state of the hotword preference.
StringToLowerASCII(&normalized_locale);
for (size_t i = 0; i < arraysize(kSupportedLocales); i++) {
- if (kSupportedLocales[i] == normalized_locale)
+ if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0)
return true;
}
return false;
}
HotwordService::HotwordService(Profile* profile)
- : profile_(profile) {
+ : profile_(profile),
+ client_(NULL) {
// This will be called during profile initialization which is a good time
// to check the user's hotword state.
HotwordEnabled enabled_state = UNSET;
else
DisableHotwordExtension(extension_service);
}
+
+void HotwordService::RequestHotwordSession(HotwordClient* client) {
+#if defined(ENABLE_EXTENSIONS)
+ if (!IsServiceAvailable() || client_)
+ return;
+
+ client_ = client;
+
+ HotwordPrivateEventService* event_service =
+ BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
+ if (event_service)
+ event_service->OnHotwordSessionRequested();
+#endif
+}
+
+void HotwordService::StopHotwordSession(HotwordClient* client) {
+#if defined(ENABLE_EXTENSIONS)
+ if (!IsServiceAvailable())
+ return;
+
+ DCHECK(client_ == client);
+
+ client_ = NULL;
+ HotwordPrivateEventService* event_service =
+ BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
+ if (event_service)
+ event_service->OnHotwordSessionStopped();
+#endif
+}