#include "base/lazy_instance.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search/hotword_client.h"
#include "chrome/browser/search/hotword_service.h"
#include "chrome/browser/search/hotword_service_factory.h"
#include "chrome/common/pref_names.h"
#include "extensions/browser/event_router.h"
-#include "extensions/browser/extension_system.h"
namespace extensions {
void HotwordPrivateEventService::OnEnabledChanged(
const std::string& pref_name) {
DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
- SignalEvent();
+ SignalEvent(OnEnabledChanged::kEventName);
}
-void HotwordPrivateEventService::SignalEvent() {
- using OnEnabledChanged::kEventName;
+void HotwordPrivateEventService::OnHotwordSessionRequested() {
+ SignalEvent(api::hotword_private::OnHotwordSessionRequested::kEventName);
+}
+
+void HotwordPrivateEventService::OnHotwordSessionStopped() {
+ SignalEvent(api::hotword_private::OnHotwordSessionStopped::kEventName);
+}
- EventRouter* router = ExtensionSystem::Get(profile_)->event_router();
- if (!router || !router->HasEventListener(kEventName))
+void HotwordPrivateEventService::SignalEvent(const std::string& event_name) {
+ EventRouter* router = EventRouter::Get(profile_);
+ if (!router || !router->HasEventListener(event_name))
return;
scoped_ptr<base::ListValue> args(new base::ListValue());
- scoped_ptr<Event> event(new Event(kEventName, args.Pass()));
+ scoped_ptr<Event> event(new Event(event_name, args.Pass()));
router->BroadcastEvent(event.Pass());
}
-bool HotwordPrivateSetEnabledFunction::RunImpl() {
+bool HotwordPrivateSetEnabledFunction::RunSync() {
scoped_ptr<api::hotword_private::SetEnabled::Params> params(
api::hotword_private::SetEnabled::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
return true;
}
-bool HotwordPrivateSetAudioLoggingEnabledFunction::RunImpl() {
+bool HotwordPrivateSetAudioLoggingEnabledFunction::RunSync() {
scoped_ptr<api::hotword_private::SetEnabled::Params> params(
api::hotword_private::SetEnabled::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
return true;
}
-bool HotwordPrivateGetStatusFunction::RunImpl() {
+bool HotwordPrivateGetStatusFunction::RunSync() {
api::hotword_private::StatusDetails result;
HotwordService* hotword_service =
return true;
}
+bool HotwordPrivateSetHotwordSessionStateFunction::RunSync() {
+ scoped_ptr<api::hotword_private::SetHotwordSessionState::Params> params(
+ api::hotword_private::SetHotwordSessionState::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ HotwordService* hotword_service =
+ HotwordServiceFactory::GetForProfile(GetProfile());
+ if (hotword_service && hotword_service->client())
+ hotword_service->client()->OnHotwordStateChanged(params->started);
+ return true;
+}
+
+bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() {
+ HotwordService* hotword_service =
+ HotwordServiceFactory::GetForProfile(GetProfile());
+ if (hotword_service && hotword_service->client())
+ hotword_service->client()->OnHotwordRecognized();
+ return true;
+}
+
} // namespace extensions