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

Side by Side Diff: content/renderer/speech_recognition_dispatcher.cc

Issue 10831110: SpeechRecognitionDispatcher: break out translation of error codes to separate function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make android happy Created 8 years, 4 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/public/common/speech_recognition_error.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) 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/renderer/speech_recognition_dispatcher.h" 5 #include "content/renderer/speech_recognition_dispatcher.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "content/common/speech_recognition_messages.h" 9 #include "content/common/speech_recognition_messages.h"
10 #include "content/renderer/render_view_impl.h" 10 #include "content/renderer/render_view_impl.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 115
116 void SpeechRecognitionDispatcher::OnSoundEnded(int request_id) { 116 void SpeechRecognitionDispatcher::OnSoundEnded(int request_id) {
117 recognizer_client_->didEndSound(GetHandleFromID(request_id)); 117 recognizer_client_->didEndSound(GetHandleFromID(request_id));
118 } 118 }
119 119
120 void SpeechRecognitionDispatcher::OnAudioEnded(int request_id) { 120 void SpeechRecognitionDispatcher::OnAudioEnded(int request_id) {
121 recognizer_client_->didEndAudio(GetHandleFromID(request_id)); 121 recognizer_client_->didEndAudio(GetHandleFromID(request_id));
122 } 122 }
123 123
124 static WebSpeechRecognizerClient::ErrorCode WebKitErrorCode(
125 content::SpeechRecognitionErrorCode e) {
126 switch (e) {
127 case content::SPEECH_RECOGNITION_ERROR_NONE:
128 NOTREACHED();
129 return WebSpeechRecognizerClient::OtherError;
130 case content::SPEECH_RECOGNITION_ERROR_ABORTED:
131 return WebSpeechRecognizerClient::AbortedError;
132 case content::SPEECH_RECOGNITION_ERROR_AUDIO:
133 return WebSpeechRecognizerClient::AudioCaptureError;
134 case content::SPEECH_RECOGNITION_ERROR_NETWORK:
135 return WebSpeechRecognizerClient::NetworkError;
136 case content::SPEECH_RECOGNITION_ERROR_NO_SPEECH:
137 return WebSpeechRecognizerClient::NoSpeechError;
138 case content::SPEECH_RECOGNITION_ERROR_NO_MATCH:
139 NOTREACHED();
140 return WebSpeechRecognizerClient::OtherError;
141 case content::SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR:
142 return WebSpeechRecognizerClient::BadGrammarError;
143 }
144 NOTREACHED();
145 return WebSpeechRecognizerClient::OtherError;
146 }
147
124 void SpeechRecognitionDispatcher::OnErrorOccurred( 148 void SpeechRecognitionDispatcher::OnErrorOccurred(
125 int request_id, const SpeechRecognitionError& error) { 149 int request_id, const SpeechRecognitionError& error) {
126 if (error.code == content::SPEECH_RECOGNITION_ERROR_NO_MATCH) { 150 if (error.code == content::SPEECH_RECOGNITION_ERROR_NO_MATCH) {
127 recognizer_client_->didReceiveNoMatch(GetHandleFromID(request_id), 151 recognizer_client_->didReceiveNoMatch(GetHandleFromID(request_id),
128 WebSpeechRecognitionResult()); 152 WebSpeechRecognitionResult());
129 } else { 153 } else {
130 // TODO(primiano): speech_recognition_error.h must be updated to match the
131 // new enums defined in the the API specs (thus removing the code below).
132 WebSpeechRecognizerClient::ErrorCode wk_error_code;
133 switch (error.code) {
134 case content::SPEECH_RECOGNITION_ERROR_ABORTED:
135 wk_error_code = WebSpeechRecognizerClient::AbortedError;
136 break;
137 case content::SPEECH_RECOGNITION_ERROR_AUDIO:
138 wk_error_code = WebSpeechRecognizerClient::AudioCaptureError;
139 break;
140 case content::SPEECH_RECOGNITION_ERROR_NETWORK:
141 wk_error_code = WebSpeechRecognizerClient::NetworkError;
142 break;
143 case content::SPEECH_RECOGNITION_ERROR_NO_SPEECH:
144 wk_error_code = WebSpeechRecognizerClient::NoSpeechError;
145 break;
146 case content::SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR:
147 wk_error_code = WebSpeechRecognizerClient::BadGrammarError;
148 break;
149 default:
150 NOTREACHED();
151 wk_error_code = WebSpeechRecognizerClient::OtherError;
152 }
153 recognizer_client_->didReceiveError(GetHandleFromID(request_id), 154 recognizer_client_->didReceiveError(GetHandleFromID(request_id),
154 WebString(), // TODO(primiano): message? 155 WebString(), // TODO(primiano): message?
155 wk_error_code); 156 WebKitErrorCode(error.code));
156 } 157 }
157 } 158 }
158 159
159 void SpeechRecognitionDispatcher::OnRecognitionEnded(int request_id) { 160 void SpeechRecognitionDispatcher::OnRecognitionEnded(int request_id) {
160 recognizer_client_->didEnd(GetHandleFromID(request_id)); 161 recognizer_client_->didEnd(GetHandleFromID(request_id));
161 handle_map_.erase(request_id); 162 handle_map_.erase(request_id);
162 } 163 }
163 164
164 void SpeechRecognitionDispatcher::OnResultRetrieved( 165 void SpeechRecognitionDispatcher::OnResultRetrieved(
165 int request_id, const SpeechRecognitionResult& result) { 166 int request_id, const SpeechRecognitionResult& result) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 208 }
208 return false; 209 return false;
209 } 210 }
210 211
211 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID( 212 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID(
212 int request_id) { 213 int request_id) {
213 HandleMap::iterator iter = handle_map_.find(request_id); 214 HandleMap::iterator iter = handle_map_.find(request_id);
214 DCHECK(iter != handle_map_.end()); 215 DCHECK(iter != handle_map_.end());
215 return iter->second; 216 return iter->second;
216 } 217 }
OLDNEW
« no previous file with comments | « content/public/common/speech_recognition_error.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698