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

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: Rebase 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 156 }
157 157
158 } // namespace 158 } // namespace
159 159
160 namespace hotword_internal { 160 namespace hotword_internal {
161 // Constants for the hotword field trial. 161 // Constants for the hotword field trial.
162 const char kHotwordFieldTrialName[] = "VoiceTrigger"; 162 const char kHotwordFieldTrialName[] = "VoiceTrigger";
163 const char kHotwordFieldTrialDisabledGroupName[] = "Disabled"; 163 const char kHotwordFieldTrialDisabledGroupName[] = "Disabled";
164 // Old preference constant. 164 // Old preference constant.
165 const char kHotwordUnusablePrefName[] = "hotword.search_enabled"; 165 const char kHotwordUnusablePrefName[] = "hotword.search_enabled";
166 // String passed to indicate the training state has changed.
167 const char kHotwordTrainingEnabled[] = "hotword_training_enabled";
166 } // namespace hotword_internal 168 } // namespace hotword_internal
167 169
168 // static 170 // static
169 bool HotwordService::DoesHotwordSupportLanguage(Profile* profile) { 171 bool HotwordService::DoesHotwordSupportLanguage(Profile* profile) {
170 std::string normalized_locale = 172 std::string normalized_locale =
171 l10n_util::NormalizeLocale(GetCurrentLocale(profile)); 173 l10n_util::NormalizeLocale(GetCurrentLocale(profile));
172 base::StringToLowerASCII(&normalized_locale); 174 base::StringToLowerASCII(&normalized_locale);
173 175
174 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) { 176 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) {
175 if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0) 177 if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0)
176 return true; 178 return true;
177 } 179 }
178 return false; 180 return false;
179 } 181 }
180 182
181 // static 183 // static
182 bool HotwordService::IsExperimentalHotwordingEnabled() { 184 bool HotwordService::IsExperimentalHotwordingEnabled() {
183 CommandLine* command_line = CommandLine::ForCurrentProcess(); 185 CommandLine* command_line = CommandLine::ForCurrentProcess();
184 return command_line->HasSwitch(switches::kEnableExperimentalHotwording); 186 return command_line->HasSwitch(switches::kEnableExperimentalHotwording);
185 } 187 }
186 188
187 HotwordService::HotwordService(Profile* profile) 189 HotwordService::HotwordService(Profile* profile)
188 : profile_(profile), 190 : profile_(profile),
189 extension_registry_observer_(this), 191 extension_registry_observer_(this),
190 client_(NULL), 192 client_(NULL),
191 error_message_(0), 193 error_message_(0),
192 reinstall_pending_(false), 194 reinstall_pending_(false),
195 training_(false),
193 weak_factory_(this) { 196 weak_factory_(this) {
194 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); 197 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
195 // This will be called during profile initialization which is a good time 198 // This will be called during profile initialization which is a good time
196 // to check the user's hotword state. 199 // to check the user's hotword state.
197 HotwordEnabled enabled_state = UNSET; 200 HotwordEnabled enabled_state = UNSET;
198 if (IsExperimentalHotwordingEnabled()) { 201 if (IsExperimentalHotwordingEnabled()) {
199 // Disable the old extension so it doesn't interfere with the new stuff. 202 // Disable the old extension so it doesn't interfere with the new stuff.
200 DisableHotwordExtension(GetExtensionService(profile_)); 203 DisableHotwordExtension(GetExtensionService(profile_));
201 } else { 204 } else {
202 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) { 205 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 473
471 OpenApplication(AppLaunchParams( 474 OpenApplication(AppLaunchParams(
472 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); 475 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
473 } 476 }
474 477
475 HotwordService::LaunchMode 478 HotwordService::LaunchMode
476 HotwordService::GetHotwordAudioVerificationLaunchMode() { 479 HotwordService::GetHotwordAudioVerificationLaunchMode() {
477 return hotword_audio_verification_launch_mode_; 480 return hotword_audio_verification_launch_mode_;
478 } 481 }
479 482
483 void HotwordService::StartTraining() {
484 training_ = true;
485
486 if (!IsServiceAvailable())
487 return;
488
489 HotwordPrivateEventService* event_service =
490 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
491 if (event_service)
492 event_service->OnEnabledChanged(hotword_internal::kHotwordTrainingEnabled);
493 }
494
495 void HotwordService::FinalizeSpeakerModel() {
496 if (!IsServiceAvailable())
497 return;
498
499 HotwordPrivateEventService* event_service =
500 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
501 if (event_service)
502 event_service->OnFinalizeSpeakerModel();
503 }
504
505 void HotwordService::StopTraining() {
506 training_ = false;
507
508 if (!IsServiceAvailable())
509 return;
510
511 HotwordPrivateEventService* event_service =
512 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
513 if (event_service)
514 event_service->OnEnabledChanged(hotword_internal::kHotwordTrainingEnabled);
515 }
516
517 void HotwordService::NotifyHotwordTriggered() {
518 if (!IsServiceAvailable())
519 return;
520
521 HotwordPrivateEventService* event_service =
522 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
523 if (event_service)
524 event_service->OnHotwordTriggered();
525 }
526
527 bool HotwordService::IsTraining() {
528 return training_;
529 }
530
480 void HotwordService::OnHotwordSearchEnabledChanged( 531 void HotwordService::OnHotwordSearchEnabledChanged(
481 const std::string& pref_name) { 532 const std::string& pref_name) {
482 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); 533 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
483 534
484 ExtensionService* extension_service = GetExtensionService(profile_); 535 ExtensionService* extension_service = GetExtensionService(profile_);
485 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 536 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
486 EnableHotwordExtension(extension_service); 537 EnableHotwordExtension(extension_service);
487 else 538 else
488 DisableHotwordExtension(extension_service); 539 DisableHotwordExtension(extension_service);
489 } 540 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 return false; 579 return false;
529 580
530 std::string previous_locale = 581 std::string previous_locale =
531 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); 582 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage);
532 std::string locale = GetCurrentLocale(profile_); 583 std::string locale = GetCurrentLocale(profile_);
533 584
534 // If it's a new locale, then the old extension should be uninstalled. 585 // If it's a new locale, then the old extension should be uninstalled.
535 return locale != previous_locale && 586 return locale != previous_locale &&
536 HotwordService::DoesHotwordSupportLanguage(profile_); 587 HotwordService::DoesHotwordSupportLanguage(profile_);
537 } 588 }
OLDNEW
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698