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: content/browser/speech/speech_recognition_manager_impl.cc

Issue 10933018: Speech JavaScript API: Use the MediaStreamManager to ask for user permission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing Satish's comments Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/speech/speech_recognition_manager_impl.h" 5 #include "content/browser/speech/speech_recognition_manager_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/browser_main_loop.h" 8 #include "content/browser/browser_main_loop.h"
9 #include "content/browser/renderer_host/media/media_stream_manager.h"
9 #include "content/browser/speech/google_one_shot_remote_engine.h" 10 #include "content/browser/speech/google_one_shot_remote_engine.h"
10 #include "content/browser/speech/google_streaming_remote_engine.h" 11 #include "content/browser/speech/google_streaming_remote_engine.h"
11 #include "content/browser/speech/speech_recognition_engine.h" 12 #include "content/browser/speech/speech_recognition_engine.h"
12 #include "content/browser/speech/speech_recognizer.h" 13 #include "content/browser/speech/speech_recognizer.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/resource_context.h" 16 #include "content/public/browser/resource_context.h"
16 #include "content/public/browser/speech_recognition_event_listener.h" 17 #include "content/public/browser/speech_recognition_event_listener.h"
17 #include "content/public/browser/speech_recognition_manager_delegate.h" 18 #include "content/public/browser/speech_recognition_manager_delegate.h"
18 #include "content/public/browser/speech_recognition_session_config.h" 19 #include "content/public/browser/speech_recognition_session_config.h"
19 #include "content/public/browser/speech_recognition_session_context.h" 20 #include "content/public/browser/speech_recognition_session_context.h"
21 #include "content/public/common/speech_recognition_error.h"
20 #include "content/public/common/speech_recognition_result.h" 22 #include "content/public/common/speech_recognition_result.h"
21 #include "media/audio/audio_manager.h" 23 #include "media/audio/audio_manager.h"
22 24
23 using base::Callback; 25 using base::Callback;
24 using content::BrowserMainLoop; 26 using content::BrowserMainLoop;
25 using content::BrowserThread; 27 using content::BrowserThread;
26 using content::SpeechRecognitionError;
27 using content::SpeechRecognitionEventListener; 28 using content::SpeechRecognitionEventListener;
28 using content::SpeechRecognitionManager; 29 using content::SpeechRecognitionManager;
29 using content::SpeechRecognitionResult; 30 using content::SpeechRecognitionResult;
30 using content::SpeechRecognitionSessionContext; 31 using content::SpeechRecognitionSessionContext;
31 using content::SpeechRecognitionSessionConfig; 32 using content::SpeechRecognitionSessionConfig;
32 33
33 namespace content { 34 namespace content {
34 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { 35 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() {
35 return speech::SpeechRecognitionManagerImpl::GetInstance(); 36 return speech::SpeechRecognitionManagerImpl::GetInstance();
36 } 37 }
37 } // namespace content 38 } // namespace content
38 39
39 namespace { 40 namespace {
40 speech::SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl; 41 speech::SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl;
41 42
42 void ShowAudioInputSettingsOnFileThread() { 43 void ShowAudioInputSettingsOnFileThread() {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
44 media::AudioManager* audio_manager = BrowserMainLoop::GetAudioManager(); 45 media::AudioManager* audio_manager = BrowserMainLoop::GetAudioManager();
45 DCHECK(audio_manager->CanShowAudioInputSettings()); 46 DCHECK(audio_manager->CanShowAudioInputSettings());
46 if (audio_manager->CanShowAudioInputSettings()) 47 if (audio_manager->CanShowAudioInputSettings())
47 audio_manager->ShowAudioInputSettings(); 48 audio_manager->ShowAudioInputSettings();
48 } 49 }
49 } // namespace 50 } // namespace
50 51
51 namespace speech { 52 namespace speech {
52 53
54 class SpeechRecognitionManagerImpl::PermissionRequest :
no longer working on chromium 2012/09/12 11:29:49 mvoe this ":" one line below with 4 space as inden
hans 2012/09/12 12:32:21 Done.
55 public media_stream::MediaStreamRequester {
56 public:
57 PermissionRequest(media_stream::MediaStreamManager* media_stream_manager,
58 int session_id,
59 const base::Callback<void(bool is_allowed)>& callback)
60 : media_stream_manager_(media_stream_manager),
61 session_id_(session_id),
62 callback_(callback) {
63 }
64
65 virtual ~PermissionRequest() {}
no longer working on chromium 2012/09/12 11:29:49 When a request is being handled by the media_strea
hans 2012/09/12 12:32:21 Done.
66
67 void Start(int render_process_id, int render_view_id, const GURL& origin) {
68 media_stream_manager_->GenerateStream(
69 this,
70 render_process_id,
71 render_view_id,
72 media_stream::StreamOptions(/*audio=*/true, /*video=*/false),
73 origin,
74 &label_);
75 }
76
77 void Abort() {
78 media_stream_manager_->CancelGenerateStream(label_);
79 }
80
81 int Session() { return session_id_; }
no longer working on chromium 2012/09/12 11:29:49 nit, int Session() const { ... }
hans 2012/09/12 12:32:21 Done.
82
83 // MediaStreamRequester methods.
84 virtual void StreamGenerated(
85 const std::string& label,
86 const media_stream::StreamDeviceInfoArray& audio_devices,
87 const media_stream::StreamDeviceInfoArray& video_devices) OVERRIDE {
88 // TODO(hans): One day it would be nice to actually use the generated stream
89 // but right now we only use it to request permission, and then we dump it.
90 BrowserThread::PostTask(
91 BrowserThread::IO,
92 FROM_HERE,
93 base::Bind(&media_stream::MediaStreamManager::StopGeneratedStream,
94 base::Unretained(media_stream_manager_),
95 label));
96 callback_.Run(true);
97 }
98
99 virtual void StreamGenerationFailed(const std::string& label) OVERRIDE {
100 callback_.Run(false);
101 }
102
103 // The callbacks below are ignored.
104 virtual void AudioDeviceFailed(const std::string& label,
105 int index) OVERRIDE {}
106 virtual void VideoDeviceFailed(const std::string& label,
107 int index) OVERRIDE {}
108 virtual void DevicesEnumerated(
109 const std::string& label,
110 const media_stream::StreamDeviceInfoArray& devices) OVERRIDE {}
111 virtual void DeviceOpened(
112 const std::string& label,
113 const media_stream::StreamDeviceInfo& device_info) OVERRIDE {}
114
115 private:
116 media_stream::MediaStreamManager* media_stream_manager_;
117 int session_id_;
118 base::Callback<void(bool is_allowed)> callback_;
119 std::string label_;
120 };
121
53 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { 122 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() {
54 return g_speech_recognition_manager_impl; 123 return g_speech_recognition_manager_impl;
55 } 124 }
56 125
57 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() 126 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl()
58 : session_id_capturing_audio_(kSessionIDInvalid), 127 : primary_session_id_(kSessionIDInvalid),
59 last_session_id_(kSessionIDInvalid), 128 last_session_id_(kSessionIDInvalid),
60 is_dispatching_event_(false), 129 is_dispatching_event_(false),
61 delegate_(content::GetContentClient()->browser()-> 130 delegate_(content::GetContentClient()->browser()->
62 GetSpeechRecognitionManagerDelegate()), 131 GetSpeechRecognitionManagerDelegate()),
63 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 132 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
64 DCHECK(!g_speech_recognition_manager_impl); 133 DCHECK(!g_speech_recognition_manager_impl);
65 g_speech_recognition_manager_impl = this; 134 g_speech_recognition_manager_impl = this;
66 } 135 }
67 136
68 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { 137 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() {
no longer working on chromium 2012/09/12 11:29:49 who owns the SpeechRecognitionManagerImpl? please
hans 2012/09/12 12:32:21 SpeechRecognitionManagerImpl is a singleton, and i
69 DCHECK(g_speech_recognition_manager_impl); 138 DCHECK(g_speech_recognition_manager_impl);
70 g_speech_recognition_manager_impl = NULL; 139 g_speech_recognition_manager_impl = NULL;
71 // Recognition sessions will be aborted by the corresponding destructors. 140 // Recognition sessions will be aborted by the corresponding destructors.
72 sessions_.clear(); 141 sessions_.clear();
73 } 142 }
74 143
75 int SpeechRecognitionManagerImpl::CreateSession( 144 int SpeechRecognitionManagerImpl::CreateSession(
76 const SpeechRecognitionSessionConfig& config) { 145 const SpeechRecognitionSessionConfig& config) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
78 147
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 google_remote_engine); 186 google_remote_engine);
118 return session_id; 187 return session_id;
119 } 188 }
120 189
121 void SpeechRecognitionManagerImpl::StartSession(int session_id) { 190 void SpeechRecognitionManagerImpl::StartSession(int session_id) {
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
123 if (!SessionExists(session_id)) 192 if (!SessionExists(session_id))
124 return; 193 return;
125 194
126 // If there is another active session, abort that. 195 // If there is another active session, abort that.
127 if (session_id_capturing_audio_ != kSessionIDInvalid && 196 if (primary_session_id_ != kSessionIDInvalid &&
128 session_id_capturing_audio_ != session_id) { 197 primary_session_id_ != session_id) {
129 AbortSession(session_id_capturing_audio_); 198 AbortSession(primary_session_id_);
130 } 199 }
131 200
132 if (delegate_.get()) 201 primary_session_id_ = session_id;
202
203 if (delegate_.get()) {
133 delegate_->CheckRecognitionIsAllowed( 204 delegate_->CheckRecognitionIsAllowed(
134 session_id, 205 session_id,
135 base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback, 206 base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback,
136 weak_factory_.GetWeakPtr())); 207 weak_factory_.GetWeakPtr(),
208 session_id));
209 }
137 } 210 }
138 211
139 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id, 212 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id,
213 bool ask_user,
140 bool is_allowed) { 214 bool is_allowed) {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
142 DCHECK(SessionExists(session_id)); 216 if (!SessionExists(session_id))
217 return;
218
219 if (ask_user) {
220 media_stream::MediaStreamManager* media_stream_manager =
221 BrowserMainLoop::GetMediaStreamManager();
222
223 const SpeechRecognitionSessionContext& context =
224 GetSessionContext(session_id);
225
226 permission_request_.reset(new PermissionRequest(
227 media_stream_manager,
228 session_id,
229 base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback,
230 weak_factory_.GetWeakPtr(),
231 session_id,
232 false)));
233
234 permission_request_->Start(context.render_process_id,
235 context.render_view_id,
236 GURL(context.context_name));
237
238 return;
239 }
240
241 permission_request_.reset();
242
143 if (is_allowed) { 243 if (is_allowed) {
144 MessageLoop::current()->PostTask(FROM_HERE, 244 MessageLoop::current()->PostTask(FROM_HERE,
145 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 245 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
146 weak_factory_.GetWeakPtr(), session_id, EVENT_START)); 246 weak_factory_.GetWeakPtr(), session_id, EVENT_START));
147 } else { 247 } else {
148 sessions_.erase(session_id); 248 OnRecognitionError(session_id, content::SpeechRecognitionError(
249 content::SPEECH_RECOGNITION_ERROR_NOT_ALLOWED));
250 MessageLoop::current()->PostTask(FROM_HERE,
251 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
252 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT));
149 } 253 }
150 } 254 }
151 255
152 void SpeechRecognitionManagerImpl::AbortSession(int session_id) { 256 void SpeechRecognitionManagerImpl::AbortSession(int session_id) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
154 if (!SessionExists(session_id)) 258 if (!SessionExists(session_id))
155 return; 259 return;
156 260
261 if (permission_request_.get() &&
262 permission_request_->Session() == session_id) {
263 DCHECK(permission_request_.get());
264 permission_request_->Abort();
265 }
266
157 MessageLoop::current()->PostTask(FROM_HERE, 267 MessageLoop::current()->PostTask(FROM_HERE,
158 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 268 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
159 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT)); 269 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT));
160 } 270 }
161 271
162 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { 272 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
164 if (!SessionExists(session_id)) 274 if (!SessionExists(session_id))
165 return; 275 return;
166 276
277 if (permission_request_.get() &&
278 permission_request_->Session() == session_id) {
279 DCHECK(permission_request_.get());
280 permission_request_->Abort();
281 }
282
167 MessageLoop::current()->PostTask(FROM_HERE, 283 MessageLoop::current()->PostTask(FROM_HERE,
168 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 284 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
169 weak_factory_.GetWeakPtr(), session_id, EVENT_STOP_CAPTURE)); 285 weak_factory_.GetWeakPtr(), session_id, EVENT_STOP_CAPTURE));
170 } 286 }
171 287
172 // Here begins the SpeechRecognitionEventListener interface implementation, 288 // Here begins the SpeechRecognitionEventListener interface implementation,
173 // which will simply relay the events to the proper listener registered for the 289 // which will simply relay the events to the proper listener registered for the
174 // particular session (most likely InputTagSpeechDispatcherHost) and to the 290 // particular session (most likely InputTagSpeechDispatcherHost) and to the
175 // catch-all listener provided by the delegate (if any). 291 // catch-all listener provided by the delegate (if any).
176 292
177 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { 293 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) {
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
179 if (!SessionExists(session_id)) 295 if (!SessionExists(session_id))
180 return; 296 return;
181 297
182 DCHECK_EQ(session_id_capturing_audio_, session_id); 298 DCHECK_EQ(primary_session_id_, session_id);
183 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 299 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
184 delegate_listener->OnRecognitionStart(session_id); 300 delegate_listener->OnRecognitionStart(session_id);
185 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 301 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
186 listener->OnRecognitionStart(session_id); 302 listener->OnRecognitionStart(session_id);
187 } 303 }
188 304
189 void SpeechRecognitionManagerImpl::OnAudioStart(int session_id) { 305 void SpeechRecognitionManagerImpl::OnAudioStart(int session_id) {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
191 if (!SessionExists(session_id)) 307 if (!SessionExists(session_id))
192 return; 308 return;
193 309
194 DCHECK_EQ(session_id_capturing_audio_, session_id); 310 DCHECK_EQ(primary_session_id_, session_id);
195 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 311 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
196 delegate_listener->OnAudioStart(session_id); 312 delegate_listener->OnAudioStart(session_id);
197 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 313 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
198 listener->OnAudioStart(session_id); 314 listener->OnAudioStart(session_id);
199 } 315 }
200 316
201 void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete( 317 void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete(
202 int session_id) { 318 int session_id) {
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
204 if (!SessionExists(session_id)) 320 if (!SessionExists(session_id))
205 return; 321 return;
206 322
207 DCHECK_EQ(session_id_capturing_audio_, session_id); 323 DCHECK_EQ(primary_session_id_, session_id);
208 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 324 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
209 delegate_listener->OnEnvironmentEstimationComplete(session_id); 325 delegate_listener->OnEnvironmentEstimationComplete(session_id);
210 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 326 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
211 listener->OnEnvironmentEstimationComplete(session_id); 327 listener->OnEnvironmentEstimationComplete(session_id);
212 } 328 }
213 329
214 void SpeechRecognitionManagerImpl::OnSoundStart(int session_id) { 330 void SpeechRecognitionManagerImpl::OnSoundStart(int session_id) {
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
216 if (!SessionExists(session_id)) 332 if (!SessionExists(session_id))
217 return; 333 return;
218 334
219 DCHECK_EQ(session_id_capturing_audio_, session_id); 335 DCHECK_EQ(primary_session_id_, session_id);
220 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 336 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
221 delegate_listener->OnSoundStart(session_id); 337 delegate_listener->OnSoundStart(session_id);
222 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 338 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
223 listener->OnSoundStart(session_id); 339 listener->OnSoundStart(session_id);
224 } 340 }
225 341
226 void SpeechRecognitionManagerImpl::OnSoundEnd(int session_id) { 342 void SpeechRecognitionManagerImpl::OnSoundEnd(int session_id) {
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
228 if (!SessionExists(session_id)) 344 if (!SessionExists(session_id))
229 return; 345 return;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // completed the transition from CAPTURING_AUDIO to WAITING_FOR_RESULT, thus 505 // completed the transition from CAPTURING_AUDIO to WAITING_FOR_RESULT, thus
390 // we perceive the AUDIO_ENDED event in WAITING_FOR_RESULT). 506 // we perceive the AUDIO_ENDED event in WAITING_FOR_RESULT).
391 // This makes the code below a bit tricky but avoids a lot of code for 507 // This makes the code below a bit tricky but avoids a lot of code for
392 // tracking and reconstructing asynchronously the state of the recognizer. 508 // tracking and reconstructing asynchronously the state of the recognizer.
393 switch (session_state) { 509 switch (session_state) {
394 case SESSION_STATE_IDLE: 510 case SESSION_STATE_IDLE:
395 switch (event) { 511 switch (event) {
396 case EVENT_START: 512 case EVENT_START:
397 return SessionStart(session); 513 return SessionStart(session);
398 case EVENT_ABORT: 514 case EVENT_ABORT:
515 return SessionAbort(session);
399 case EVENT_RECOGNITION_ENDED: 516 case EVENT_RECOGNITION_ENDED:
400 return SessionDelete(session); 517 return SessionDelete(session);
401 case EVENT_STOP_CAPTURE: 518 case EVENT_STOP_CAPTURE:
519 return SessionStopAudioCapture(session);
402 case EVENT_AUDIO_ENDED: 520 case EVENT_AUDIO_ENDED:
403 return; 521 return;
404 } 522 }
405 break; 523 break;
406 case SESSION_STATE_CAPTURING_AUDIO: 524 case SESSION_STATE_CAPTURING_AUDIO:
407 switch (event) { 525 switch (event) {
408 case EVENT_STOP_CAPTURE: 526 case EVENT_STOP_CAPTURE:
409 return SessionStopAudioCapture(session); 527 return SessionStopAudioCapture(session);
410 case EVENT_ABORT: 528 case EVENT_ABORT:
411 return SessionAbort(session); 529 return SessionAbort(session);
(...skipping 29 matching lines...) Expand all
441 if (session.recognizer->IsCapturingAudio()) 559 if (session.recognizer->IsCapturingAudio())
442 return SESSION_STATE_CAPTURING_AUDIO; 560 return SESSION_STATE_CAPTURING_AUDIO;
443 return SESSION_STATE_WAITING_FOR_RESULT; 561 return SESSION_STATE_WAITING_FOR_RESULT;
444 } 562 }
445 563
446 // ----------- Contract for all the FSM evolution functions below ------------- 564 // ----------- Contract for all the FSM evolution functions below -------------
447 // - Are guaranteed to be executed in the IO thread; 565 // - Are guaranteed to be executed in the IO thread;
448 // - Are guaranteed to be not reentrant (themselves and each other); 566 // - Are guaranteed to be not reentrant (themselves and each other);
449 567
450 void SpeechRecognitionManagerImpl::SessionStart(const Session& session) { 568 void SpeechRecognitionManagerImpl::SessionStart(const Session& session) {
451 session_id_capturing_audio_ = session.id; 569 DCHECK_EQ(primary_session_id_, session.id);
452 session.recognizer->StartRecognition(); 570 session.recognizer->StartRecognition();
453 } 571 }
454 572
455 void SpeechRecognitionManagerImpl::SessionAbort(const Session& session) { 573 void SpeechRecognitionManagerImpl::SessionAbort(const Session& session) {
456 if (session_id_capturing_audio_ == session.id) 574 if (primary_session_id_ == session.id)
457 session_id_capturing_audio_ = kSessionIDInvalid; 575 primary_session_id_ = kSessionIDInvalid;
458 DCHECK(session.recognizer.get() && session.recognizer->IsActive()); 576 DCHECK(session.recognizer.get());
459 session.recognizer->AbortRecognition(); 577 session.recognizer->AbortRecognition();
460 } 578 }
461 579
462 void SpeechRecognitionManagerImpl::SessionStopAudioCapture( 580 void SpeechRecognitionManagerImpl::SessionStopAudioCapture(
463 const Session& session) { 581 const Session& session) {
464 DCHECK(session.recognizer.get() && session.recognizer->IsCapturingAudio()); 582 DCHECK(session.recognizer.get());
465 session.recognizer->StopAudioCapture(); 583 session.recognizer->StopAudioCapture();
466 } 584 }
467 585
468 void SpeechRecognitionManagerImpl::ResetCapturingSessionId( 586 void SpeechRecognitionManagerImpl::ResetCapturingSessionId(
469 const Session& session) { 587 const Session& session) {
470 DCHECK_EQ(session_id_capturing_audio_, session.id); 588 DCHECK_EQ(primary_session_id_, session.id);
471 session_id_capturing_audio_ = kSessionIDInvalid; 589 primary_session_id_ = kSessionIDInvalid;
472 } 590 }
473 591
474 void SpeechRecognitionManagerImpl::SessionDelete(const Session& session) { 592 void SpeechRecognitionManagerImpl::SessionDelete(const Session& session) {
475 DCHECK(session.recognizer == NULL || !session.recognizer->IsActive()); 593 DCHECK(session.recognizer == NULL || !session.recognizer->IsActive());
476 if (session_id_capturing_audio_ == session.id) 594 if (primary_session_id_ == session.id)
477 session_id_capturing_audio_ = kSessionIDInvalid; 595 primary_session_id_ = kSessionIDInvalid;
478 sessions_.erase(session.id); 596 sessions_.erase(session.id);
479 } 597 }
480 598
481 void SpeechRecognitionManagerImpl::NotFeasible(const Session& session, 599 void SpeechRecognitionManagerImpl::NotFeasible(const Session& session,
482 FSMEvent event) { 600 FSMEvent event) {
483 NOTREACHED() << "Unfeasible event " << event 601 NOTREACHED() << "Unfeasible event " << event
484 << " in state " << GetSessionState(session.id) 602 << " in state " << GetSessionState(session.id)
485 << " for session " << session.id; 603 << " for session " << session.id;
486 } 604 }
487 605
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 660
543 SpeechRecognitionManagerImpl::Session::Session() 661 SpeechRecognitionManagerImpl::Session::Session()
544 : id(kSessionIDInvalid), 662 : id(kSessionIDInvalid),
545 listener_is_active(true) { 663 listener_is_active(true) {
546 } 664 }
547 665
548 SpeechRecognitionManagerImpl::Session::~Session() { 666 SpeechRecognitionManagerImpl::Session::~Session() {
549 } 667 }
550 668
551 } // namespace speech 669 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698