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

Side by Side Diff: content/browser/speech/speech_recognition_manager_impl.cc

Issue 25550003: Web Speech API: Fix a race condition causing renderer crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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
« no previous file with comments | « content/browser/speech/speech_recognition_manager_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "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/renderer_host/media/media_stream_manager.h"
10 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 10 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 177 }
178 } 178 }
179 179
180 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id, 180 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id,
181 bool ask_user, 181 bool ask_user,
182 bool is_allowed) { 182 bool is_allowed) {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
184 if (!SessionExists(session_id)) 184 if (!SessionExists(session_id))
185 return; 185 return;
186 186
187 SessionsTable::iterator iter = sessions_.find(session_id);
188 DCHECK(iter != sessions_.end());
tommi (sloooow) - chröme 2013/10/02 08:01:14 DCHECK_NE?
Primiano Tucci (use gerrit) 2013/10/02 14:09:01 Hmm I tried (see patchset 2 trybots) but DCHECK_NE
189 Session *session = iter->second;
tommi (sloooow) - chröme 2013/10/02 08:01:14 Session* session = iter->second;
Primiano Tucci (use gerrit) 2013/10/02 14:09:01 Oh, right.
190
187 if (ask_user) { 191 if (ask_user) {
188 SessionsTable::iterator iter = sessions_.find(session_id); 192 SpeechRecognitionSessionContext& context = session->context;
189 DCHECK(iter != sessions_.end());
190 SpeechRecognitionSessionContext& context = iter->second->context;
191 context.label = media_stream_manager_->MakeMediaAccessRequest( 193 context.label = media_stream_manager_->MakeMediaAccessRequest(
192 context.render_process_id, 194 context.render_process_id,
193 context.render_view_id, 195 context.render_view_id,
194 context.request_id, 196 context.request_id,
195 StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE), 197 StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE),
196 GURL(context.context_name), 198 GURL(context.context_name),
197 base::Bind( 199 base::Bind(
198 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, 200 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback,
199 weak_factory_.GetWeakPtr(), session_id)); 201 weak_factory_.GetWeakPtr(), session_id));
200 return; 202 return;
201 } 203 }
202 204
203 if (is_allowed) { 205 if (is_allowed) {
no longer working on chromium 2013/10/02 09:05:06 question, should't you do nothing if session->abor
Primiano Tucci (use gerrit) 2013/10/02 14:09:01 Oh right, good catch. If the permission gets cache
204 base::MessageLoop::current()->PostTask( 206 base::MessageLoop::current()->PostTask(
205 FROM_HERE, 207 FROM_HERE,
206 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 208 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
207 weak_factory_.GetWeakPtr(), 209 weak_factory_.GetWeakPtr(),
208 session_id, 210 session_id,
209 EVENT_START)); 211 EVENT_START));
210 } else { 212 } else if (!session->abort_requested) {
211 OnRecognitionError(session_id, SpeechRecognitionError( 213 OnRecognitionError(session_id, SpeechRecognitionError(
212 SPEECH_RECOGNITION_ERROR_NOT_ALLOWED)); 214 SPEECH_RECOGNITION_ERROR_NOT_ALLOWED));
213 base::MessageLoop::current()->PostTask( 215 base::MessageLoop::current()->PostTask(
214 FROM_HERE, 216 FROM_HERE,
215 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 217 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
216 weak_factory_.GetWeakPtr(), 218 weak_factory_.GetWeakPtr(),
217 session_id, 219 session_id,
218 EVENT_ABORT)); 220 EVENT_ABORT));
219 } 221 }
220 } 222 }
(...skipping 25 matching lines...) Expand all
246 } 248 }
247 249
248 void SpeechRecognitionManagerImpl::AbortSession(int session_id) { 250 void SpeechRecognitionManagerImpl::AbortSession(int session_id) {
249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
250 if (!SessionExists(session_id)) 252 if (!SessionExists(session_id))
251 return; 253 return;
252 254
253 SessionsTable::iterator iter = sessions_.find(session_id); 255 SessionsTable::iterator iter = sessions_.find(session_id);
254 iter->second->ui.reset(); 256 iter->second->ui.reset();
255 257
258 if (iter->second->abort_requested)
259 return;
260
261 iter->second->abort_requested = true;
262
256 base::MessageLoop::current()->PostTask( 263 base::MessageLoop::current()->PostTask(
257 FROM_HERE, 264 FROM_HERE,
258 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 265 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
259 weak_factory_.GetWeakPtr(), 266 weak_factory_.GetWeakPtr(),
260 session_id, 267 session_id,
261 EVENT_ABORT)); 268 EVENT_ABORT));
262 } 269 }
263 270
264 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { 271 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) {
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { 674 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() {
668 // Since AudioManager::ShowAudioInputSettings can potentially launch external 675 // Since AudioManager::ShowAudioInputSettings can potentially launch external
669 // processes, do that in the FILE thread to not block the calling threads. 676 // processes, do that in the FILE thread to not block the calling threads.
670 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 677 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
671 base::Bind(&ShowAudioInputSettingsOnFileThread, 678 base::Bind(&ShowAudioInputSettingsOnFileThread,
672 audio_manager_)); 679 audio_manager_));
673 } 680 }
674 681
675 SpeechRecognitionManagerImpl::Session::Session() 682 SpeechRecognitionManagerImpl::Session::Session()
676 : id(kSessionIDInvalid), 683 : id(kSessionIDInvalid),
684 abort_requested(false),
677 listener_is_active(true) { 685 listener_is_active(true) {
678 } 686 }
679 687
680 SpeechRecognitionManagerImpl::Session::~Session() { 688 SpeechRecognitionManagerImpl::Session::~Session() {
681 } 689 }
682 690
683 } // namespace content 691 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognition_manager_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698