Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / hotword_private / hotword_private_api.cc
index 1e1c7ef..42bbe18 100644 (file)
@@ -7,11 +7,11 @@
 #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 {
 
@@ -52,21 +52,27 @@ const char* HotwordPrivateEventService::service_name() {
 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());
@@ -76,7 +82,7 @@ bool HotwordPrivateSetEnabledFunction::RunImpl() {
   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());
@@ -86,7 +92,7 @@ bool HotwordPrivateSetAudioLoggingEnabledFunction::RunImpl() {
   return true;
 }
 
-bool HotwordPrivateGetStatusFunction::RunImpl() {
+bool HotwordPrivateGetStatusFunction::RunSync() {
   api::hotword_private::StatusDetails result;
 
   HotwordService* hotword_service =
@@ -107,4 +113,24 @@ bool HotwordPrivateGetStatusFunction::RunImpl() {
   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