Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Unified Diff: chrome/browser/extensions/api/hotword_private/hotword_private_api.cc

Issue 686333002: Hotword Private API: Adds speech training functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/hotword_private/hotword_private_api.cc
diff --git a/chrome/browser/extensions/api/hotword_private/hotword_private_api.cc b/chrome/browser/extensions/api/hotword_private/hotword_private_api.cc
index 0413178365eb4c7812b3fabf6e7cd9b6d53b9c4b..4c3eb5bfd1a653d041def4fd5219a781e453d9c5 100644
--- a/chrome/browser/extensions/api/hotword_private/hotword_private_api.cc
+++ b/chrome/browser/extensions/api/hotword_private/hotword_private_api.cc
@@ -64,7 +64,9 @@ const char* HotwordPrivateEventService::service_name() {
void HotwordPrivateEventService::OnEnabledChanged(
const std::string& pref_name) {
DCHECK(pref_name == std::string(prefs::kHotwordSearchEnabled) ||
- pref_name == std::string(prefs::kHotwordAlwaysOnSearchEnabled));
+ pref_name == std::string(prefs::kHotwordAlwaysOnSearchEnabled) ||
+ pref_name == std::string(
+ hotword_internal::kHotwordTrainingEnabled));
SignalEvent(OnEnabledChanged::kEventName);
}
@@ -76,6 +78,14 @@ void HotwordPrivateEventService::OnHotwordSessionStopped() {
SignalEvent(api::hotword_private::OnHotwordSessionStopped::kEventName);
}
+void HotwordPrivateEventService::OnFinalizeSpeakerModel() {
+ SignalEvent(api::hotword_private::OnFinalizeSpeakerModel::kEventName);
+}
+
+void HotwordPrivateEventService::OnHotwordTriggered() {
+ SignalEvent(api::hotword_private::OnHotwordTriggered::kEventName);
+}
+
void HotwordPrivateEventService::SignalEvent(const std::string& event_name) {
EventRouter* router = EventRouter::Get(profile_);
if (!router || !router->HasEventListener(event_name))
@@ -123,10 +133,13 @@ bool HotwordPrivateGetStatusFunction::RunSync() {
HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(GetProfile());
- if (!hotword_service)
+ if (!hotword_service) {
result.available = false;
- else
+ } else {
result.available = hotword_service->IsServiceAvailable();
+ result.audio_logging_enabled = hotword_service->IsOptedIntoAudioLogging();
+ result.training_enabled = hotword_service->IsTraining();
+ }
PrefService* prefs = GetProfile()->GetPrefs();
result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled);
@@ -137,8 +150,6 @@ bool HotwordPrivateGetStatusFunction::RunSync() {
CommandLine* command_line = CommandLine::ForCurrentProcess();
result.experimental_hotword_enabled = command_line->HasSwitch(
switches::kEnableExperimentalHotwording);
- if (hotword_service)
- result.audio_logging_enabled = hotword_service->IsOptedIntoAudioLogging();
SetResult(result.ToValue().release());
return true;
@@ -151,7 +162,9 @@ bool HotwordPrivateSetHotwordSessionStateFunction::RunSync() {
HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(GetProfile());
- if (hotword_service && hotword_service->client())
+ if (hotword_service &&
+ hotword_service->client() &&
+ !hotword_service->IsTraining())
hotword_service->client()->OnHotwordStateChanged(params->started);
return true;
}
@@ -160,7 +173,9 @@ bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() {
HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(GetProfile());
if (hotword_service) {
- if (hotword_service->client()) {
+ if (hotword_service->IsTraining()) {
+ hotword_service->NotifyHotwordTriggered();
+ } else if (hotword_service->client()) {
hotword_service->client()->OnHotwordRecognized();
} else if (HotwordService::IsExperimentalHotwordingEnabled() &&
hotword_service->IsAlwaysOnEnabled()) {
@@ -177,19 +192,53 @@ bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() {
}
bool HotwordPrivateGetLaunchStateFunction::RunSync() {
+ HotwordService* hotword_service =
+ HotwordServiceFactory::GetForProfile(GetProfile());
+ if (!hotword_service) {
+ error_ = hotword_private_constants::kHotwordServiceUnavailable;
+ return false;
+ }
+
api::hotword_private::LaunchState result;
+ result.launch_mode =
+ hotword_service->GetHotwordAudioVerificationLaunchMode();
+ SetResult(result.ToValue().release());
+ return true;
+}
+bool HotwordPrivateStartTrainingFunction::RunSync() {
HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(GetProfile());
if (!hotword_service) {
error_ = hotword_private_constants::kHotwordServiceUnavailable;
return false;
- } else {
- result.launch_mode =
- hotword_service->GetHotwordAudioVerificationLaunchMode();
}
- SetResult(result.ToValue().release());
+ hotword_service->StartTraining();
+ return true;
+}
+
+bool HotwordPrivateFinalizeSpeakerModelFunction::RunSync() {
+ HotwordService* hotword_service =
+ HotwordServiceFactory::GetForProfile(GetProfile());
+ if (!hotword_service) {
+ error_ = hotword_private_constants::kHotwordServiceUnavailable;
+ return false;
+ }
+
+ hotword_service->FinalizeSpeakerModel();
+ return true;
+}
+
+bool HotwordPrivateStopTrainingFunction::RunSync() {
+ HotwordService* hotword_service =
+ HotwordServiceFactory::GetForProfile(GetProfile());
+ if (!hotword_service) {
+ error_ = hotword_private_constants::kHotwordServiceUnavailable;
+ return false;
+ }
+
+ hotword_service->StopTraining();
return true;
}

Powered by Google App Engine
This is Rietveld 408576698