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

Side by Side Diff: chrome/browser/search/hotword_service.cc

Issue 686333002: Hotword Private API: Adds speech training functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests for Finalize Speaker Model Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/search/hotword_service.h" 5 #include "chrome/browser/search/hotword_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 156
157 } // namespace 157 } // namespace
158 158
159 namespace hotword_internal { 159 namespace hotword_internal {
160 // Constants for the hotword field trial. 160 // Constants for the hotword field trial.
161 const char kHotwordFieldTrialName[] = "VoiceTrigger"; 161 const char kHotwordFieldTrialName[] = "VoiceTrigger";
162 const char kHotwordFieldTrialDisabledGroupName[] = "Disabled"; 162 const char kHotwordFieldTrialDisabledGroupName[] = "Disabled";
163 // Old preference constant. 163 // Old preference constant.
164 const char kHotwordUnusablePrefName[] = "hotword.search_enabled"; 164 const char kHotwordUnusablePrefName[] = "hotword.search_enabled";
165 // String passed to indicate the training state has changed.
166 const char kHotwordTrainingEnabled[] = "hotword_training_enabled";
165 } // namespace hotword_internal 167 } // namespace hotword_internal
166 168
167 // static 169 // static
168 bool HotwordService::DoesHotwordSupportLanguage(Profile* profile) { 170 bool HotwordService::DoesHotwordSupportLanguage(Profile* profile) {
169 std::string normalized_locale = 171 std::string normalized_locale =
170 l10n_util::NormalizeLocale(GetCurrentLocale(profile)); 172 l10n_util::NormalizeLocale(GetCurrentLocale(profile));
171 base::StringToLowerASCII(&normalized_locale); 173 base::StringToLowerASCII(&normalized_locale);
172 174
173 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) { 175 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) {
174 if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0) 176 if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0)
175 return true; 177 return true;
176 } 178 }
177 return false; 179 return false;
178 } 180 }
179 181
180 // static 182 // static
181 bool HotwordService::IsExperimentalHotwordingEnabled() { 183 bool HotwordService::IsExperimentalHotwordingEnabled() {
182 CommandLine* command_line = CommandLine::ForCurrentProcess(); 184 CommandLine* command_line = CommandLine::ForCurrentProcess();
183 return command_line->HasSwitch(switches::kEnableExperimentalHotwording); 185 return command_line->HasSwitch(switches::kEnableExperimentalHotwording);
184 } 186 }
185 187
186 HotwordService::HotwordService(Profile* profile) 188 HotwordService::HotwordService(Profile* profile)
187 : profile_(profile), 189 : profile_(profile),
188 extension_registry_observer_(this), 190 extension_registry_observer_(this),
189 client_(NULL), 191 client_(NULL),
190 error_message_(0), 192 error_message_(0),
191 reinstall_pending_(false), 193 reinstall_pending_(false),
194 training_(false),
192 weak_factory_(this) { 195 weak_factory_(this) {
193 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); 196 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
194 // This will be called during profile initialization which is a good time 197 // This will be called during profile initialization which is a good time
195 // to check the user's hotword state. 198 // to check the user's hotword state.
196 HotwordEnabled enabled_state = UNSET; 199 HotwordEnabled enabled_state = UNSET;
197 if (IsExperimentalHotwordingEnabled()) { 200 if (IsExperimentalHotwordingEnabled()) {
198 // Disable the old extension so it doesn't interfere with the new stuff. 201 // Disable the old extension so it doesn't interfere with the new stuff.
199 DisableHotwordExtension(GetExtensionService(profile_)); 202 DisableHotwordExtension(GetExtensionService(profile_));
200 } else { 203 } else {
201 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) { 204 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 470
468 OpenApplication(AppLaunchParams( 471 OpenApplication(AppLaunchParams(
469 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); 472 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
470 } 473 }
471 474
472 HotwordService::LaunchMode 475 HotwordService::LaunchMode
473 HotwordService::GetHotwordAudioVerificationLaunchMode() { 476 HotwordService::GetHotwordAudioVerificationLaunchMode() {
474 return hotword_audio_verification_launch_mode_; 477 return hotword_audio_verification_launch_mode_;
475 } 478 }
476 479
480 void HotwordService::StartTraining() {
481 training_ = true;
482
483 if (!IsServiceAvailable())
484 return;
485
486 HotwordPrivateEventService* event_service =
487 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
488 if (event_service)
489 event_service->OnEnabledChanged(hotword_internal::kHotwordTrainingEnabled);
490 }
491
492 void HotwordService::FinalizeSpeakerModel() {
493 if (!IsServiceAvailable())
494 return;
495
496 HotwordPrivateEventService* event_service =
497 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
498 if (event_service)
499 event_service->OnFinalizeSpeakerModel();
500 }
501
502 void HotwordService::StopTraining() {
503 training_ = false;
504
505 if (!IsServiceAvailable())
506 return;
507
508 HotwordPrivateEventService* event_service =
509 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
510 if (event_service)
511 event_service->OnEnabledChanged(hotword_internal::kHotwordTrainingEnabled);
512 }
513
514 void HotwordService::NotifyHotwordTriggered() {
515 if (!IsServiceAvailable())
516 return;
517
518 HotwordPrivateEventService* event_service =
519 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
520 if (event_service)
521 event_service->OnHotwordTriggered();
522 }
523
524 bool HotwordService::IsTraining() {
525 return training_;
526 }
527
477 void HotwordService::OnHotwordSearchEnabledChanged( 528 void HotwordService::OnHotwordSearchEnabledChanged(
478 const std::string& pref_name) { 529 const std::string& pref_name) {
479 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); 530 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
480 531
481 ExtensionService* extension_service = GetExtensionService(profile_); 532 ExtensionService* extension_service = GetExtensionService(profile_);
482 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 533 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
483 EnableHotwordExtension(extension_service); 534 EnableHotwordExtension(extension_service);
484 else 535 else
485 DisableHotwordExtension(extension_service); 536 DisableHotwordExtension(extension_service);
486 } 537 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 return false; 576 return false;
526 577
527 std::string previous_locale = 578 std::string previous_locale =
528 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); 579 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage);
529 std::string locale = GetCurrentLocale(profile_); 580 std::string locale = GetCurrentLocale(profile_);
530 581
531 // If it's a new locale, then the old extension should be uninstalled. 582 // If it's a new locale, then the old extension should be uninstalled.
532 return locale != previous_locale && 583 return locale != previous_locale &&
533 HotwordService::DoesHotwordSupportLanguage(profile_); 584 HotwordService::DoesHotwordSupportLanguage(profile_);
534 } 585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698