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

Side by Side Diff: chrome/browser/extensions/api/hotword_private/hotword_private_api.cc

Issue 809603003: Plumb preamble log data from the hotword extension into the speech recognizer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 6 years 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/hotword_private/hotword_private_apitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/api/hotword_private/hotword_private_api.h" 5 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search/hotword_audio_history_handler.h" 13 #include "chrome/browser/search/hotword_audio_history_handler.h"
14 #include "chrome/browser/search/hotword_client.h" 14 #include "chrome/browser/search/hotword_client.h"
15 #include "chrome/browser/search/hotword_service.h" 15 #include "chrome/browser/search/hotword_service.h"
16 #include "chrome/browser/search/hotword_service_factory.h" 16 #include "chrome/browser/search/hotword_service_factory.h"
17 #include "chrome/browser/ui/app_list/app_list_service.h" 17 #include "chrome/browser/ui/app_list/app_list_service.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
21 #include "content/public/browser/speech_recognition_session_preamble.h"
21 #include "extensions/browser/event_router.h" 22 #include "extensions/browser/event_router.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 namespace extensions { 25 namespace extensions {
25 26
26 namespace hotword_private_constants { 27 namespace hotword_private_constants {
27 const char kHotwordServiceUnavailable[] = "Hotword Service is unavailable."; 28 const char kHotwordServiceUnavailable[] = "Hotword Service is unavailable.";
28 const char kHotwordEventServiceUnavailable[] = 29 const char kHotwordEventServiceUnavailable[] =
29 "Hotword Private Event Service is unavailable."; 30 "Hotword Private Event Service is unavailable.";
30 } // hotword_private_constants 31 } // hotword_private_constants
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 HotwordService* hotword_service = 176 HotwordService* hotword_service =
176 HotwordServiceFactory::GetForProfile(GetProfile()); 177 HotwordServiceFactory::GetForProfile(GetProfile());
177 if (hotword_service && 178 if (hotword_service &&
178 hotword_service->client() && 179 hotword_service->client() &&
179 !hotword_service->IsTraining()) 180 !hotword_service->IsTraining())
180 hotword_service->client()->OnHotwordStateChanged(params->started); 181 hotword_service->client()->OnHotwordStateChanged(params->started);
181 return true; 182 return true;
182 } 183 }
183 184
184 bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { 185 bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() {
186 scoped_ptr<api::hotword_private::NotifyHotwordRecognition::Params> params(
187 api::hotword_private::NotifyHotwordRecognition::Params::Create(*args_));
188 EXTENSION_FUNCTION_VALIDATE(params.get());
189
190 scoped_refptr<content::SpeechRecognitionSessionPreamble> preamble;
191 if (params->log.get() &&
192 !params->log->buffer.empty() &&
193 params->log->channels == 1) {
194 // TODO(amistry): Convert multi-channel preamble log into mono.
195 preamble = new content::SpeechRecognitionSessionPreamble();
196 preamble->sample_rate = params->log->sample_rate;
197 preamble->sample_depth = params->log->bytes_per_sample;
198 preamble->sample_data.swap(params->log->buffer);
199 }
200
185 HotwordService* hotword_service = 201 HotwordService* hotword_service =
186 HotwordServiceFactory::GetForProfile(GetProfile()); 202 HotwordServiceFactory::GetForProfile(GetProfile());
187 if (hotword_service) { 203 if (hotword_service) {
188 if (hotword_service->IsTraining()) { 204 if (hotword_service->IsTraining()) {
189 hotword_service->NotifyHotwordTriggered(); 205 hotword_service->NotifyHotwordTriggered();
190 } else if (hotword_service->client()) { 206 } else if (hotword_service->client()) {
191 hotword_service->client()->OnHotwordRecognized(); 207 hotword_service->client()->OnHotwordRecognized(preamble);
192 } else if (HotwordService::IsExperimentalHotwordingEnabled() && 208 } else if (HotwordService::IsExperimentalHotwordingEnabled() &&
193 hotword_service->IsAlwaysOnEnabled()) { 209 hotword_service->IsAlwaysOnEnabled()) {
194 Browser* browser = GetCurrentBrowser(); 210 Browser* browser = GetCurrentBrowser();
195 // If a Browser does not exist, fall back to the universally available, 211 // If a Browser does not exist, fall back to the universally available,
196 // but not recommended, way. 212 // but not recommended, way.
197 AppListService* app_list_service = AppListService::Get( 213 AppListService* app_list_service = AppListService::Get(
198 browser ? browser->host_desktop_type() : chrome::GetActiveDesktop()); 214 browser ? browser->host_desktop_type() : chrome::GetActiveDesktop());
199 CHECK(app_list_service); 215 CHECK(app_list_service);
200 app_list_service->ShowForVoiceSearch(GetProfile()); 216 app_list_service->ShowForVoiceSearch(GetProfile(), preamble);
201 } 217 }
202 } 218 }
203 return true; 219 return true;
204 } 220 }
205 221
206 bool HotwordPrivateGetLaunchStateFunction::RunSync() { 222 bool HotwordPrivateGetLaunchStateFunction::RunSync() {
207 HotwordService* hotword_service = 223 HotwordService* hotword_service =
208 HotwordServiceFactory::GetForProfile(GetProfile()); 224 HotwordServiceFactory::GetForProfile(GetProfile());
209 if (!hotword_service) { 225 if (!hotword_service) {
210 error_ = hotword_private_constants::kHotwordServiceUnavailable; 226 error_ = hotword_private_constants::kHotwordServiceUnavailable;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 void HotwordPrivateGetAudioHistoryEnabledFunction::SetResultAndSendResponse( 436 void HotwordPrivateGetAudioHistoryEnabledFunction::SetResultAndSendResponse(
421 bool success, bool new_enabled_value) { 437 bool success, bool new_enabled_value) {
422 api::hotword_private::AudioHistoryState result; 438 api::hotword_private::AudioHistoryState result;
423 result.success = success; 439 result.success = success;
424 result.enabled = new_enabled_value; 440 result.enabled = new_enabled_value;
425 SetResult(result.ToValue().release()); 441 SetResult(result.ToValue().release());
426 SendResponse(true); 442 SendResponse(true);
427 } 443 }
428 444
429 } // namespace extensions 445 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/hotword_private/hotword_private_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698