Commit b9f0bed7 authored by kcarattini's avatar kcarattini Committed by Commit bot

Hotword: Check for a speaker model before launching the opt-in flow

This is the first part of a multi-cl feature. I'll add the api functions in a followup cl to avoid having huge cls.

BUG=438525

Review URL: https://codereview.chromium.org/1020473003

Cr-Commit-Position: refs/heads/master@{#321924}
parent 77f844eb
......@@ -725,6 +725,34 @@ void HotwordService::DisableHotwordExtension(
}
}
void HotwordService::SpeakerModelExistsComplete(bool exists) {
if (exists) {
profile_->GetPrefs()->
SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, true);
} else {
LaunchHotwordAudioVerificationApp(HotwordService::HOTWORD_ONLY);
}
}
void HotwordService::OptIntoHotwording(
const LaunchMode& launch_mode) {
// First determine if we actually need to launch the app, or can just enable
// the pref. If Audio History has already been enabled, and we already have
// a speaker model, then we don't need to launch the app at all.
if (launch_mode == HotwordService::HOTWORD_ONLY) {
HotwordPrivateEventService* event_service =
BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(
profile_);
if (event_service) {
// TODO(kcarattini): add this call once it's implemented in the API.
// event_service->SpeakerModelExists();
return;
}
}
LaunchHotwordAudioVerificationApp(launch_mode);
}
void HotwordService::LaunchHotwordAudioVerificationApp(
const LaunchMode& launch_mode) {
hotword_audio_verification_launch_mode_ = launch_mode;
......
......@@ -140,18 +140,26 @@ class HotwordService : public extensions::ExtensionRegistryObserver,
// These methods are for launching, and getting and setting the launch mode of
// the Hotword Audio Verification App.
//
// TODO(kcarattini): Remove this when
// https://code.google.com/p/chromium/issues/detail?id=165573 is fixed,
// at which time we can simply launch the app in the given mode instead of
// having to check for it here.
// OptIntoHotwording first determines if the app needs to be launched, and if
// so, launches the app (if Audio History is on and a speaker model exists,
// then we don't need to launch the app).
//
// LaunchHotwordAudioVerificationApp launches the app without the above
// check in the specified |launch_mode|.
enum LaunchMode {
HOTWORD_ONLY,
HOTWORD_AND_AUDIO_HISTORY,
RETRAIN
};
void OptIntoHotwording(const LaunchMode& launch_mode);
void LaunchHotwordAudioVerificationApp(const LaunchMode& launch_mode);
virtual LaunchMode GetHotwordAudioVerificationLaunchMode();
// Called when the SpeakerModelExists request is complete. Either
// sets the always-on hotword pref to true, or launches the Hotword
// Audio Verification App, depending on the value of |exists|.
void SpeakerModelExistsComplete(bool exists);
// These methods control the speaker training communication between
// the Hotword Audio Verification App and the Hotword Extension that
// contains the NaCl module.
......
......@@ -1871,7 +1871,7 @@ void BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp(
if (!hotword_service)
return;
hotword_service->LaunchHotwordAudioVerificationApp(launch_mode);
hotword_service->OptIntoHotwording(launch_mode);
}
void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment