| OLD | NEW |
| 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 "content/browser/speech/speech_recognizer_impl_android.h" | 5 #include "content/browser/speech/speech_recognizer_impl_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/context_utils.h" | |
| 10 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 11 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 12 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 13 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 14 #include "base/bind.h" | 13 #include "base/bind.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/speech_recognition_event_listener.h" | 16 #include "content/public/browser/speech_recognition_event_listener.h" |
| 18 #include "content/public/browser/speech_recognition_manager.h" | 17 #include "content/public/browser/speech_recognition_manager.h" |
| 19 #include "content/public/browser/speech_recognition_session_config.h" | 18 #include "content/public/browser/speech_recognition_session_config.h" |
| 20 #include "content/public/common/speech_recognition_grammar.h" | 19 #include "content/public/common/speech_recognition_grammar.h" |
| 21 #include "content/public/common/speech_recognition_result.h" | 20 #include "content/public/common/speech_recognition_result.h" |
| 22 #include "jni/SpeechRecognition_jni.h" | 21 #include "jni/SpeechRecognition_jni.h" |
| 23 | 22 |
| 24 using base::android::AppendJavaStringArrayToStringVector; | 23 using base::android::AppendJavaStringArrayToStringVector; |
| 25 using base::android::AttachCurrentThread; | 24 using base::android::AttachCurrentThread; |
| 26 using base::android::ConvertUTF8ToJavaString; | 25 using base::android::ConvertUTF8ToJavaString; |
| 27 using base::android::GetApplicationContext; | |
| 28 using base::android::JavaFloatArrayToFloatVector; | 26 using base::android::JavaFloatArrayToFloatVector; |
| 29 using base::android::JavaParamRef; | 27 using base::android::JavaParamRef; |
| 30 | 28 |
| 31 namespace content { | 29 namespace content { |
| 32 | 30 |
| 33 SpeechRecognizerImplAndroid::SpeechRecognizerImplAndroid( | 31 SpeechRecognizerImplAndroid::SpeechRecognizerImplAndroid( |
| 34 SpeechRecognitionEventListener* listener, | 32 SpeechRecognitionEventListener* listener, |
| 35 int session_id) | 33 int session_id) |
| 36 : SpeechRecognizer(listener, session_id), | 34 : SpeechRecognizer(listener, session_id), |
| 37 state_(STATE_IDLE) { | 35 state_(STATE_IDLE) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 53 &content::SpeechRecognizerImplAndroid::StartRecognitionOnUIThread, this, | 51 &content::SpeechRecognizerImplAndroid::StartRecognitionOnUIThread, this, |
| 54 config.language, config.continuous, config.interim_results)); | 52 config.language, config.continuous, config.interim_results)); |
| 55 } | 53 } |
| 56 | 54 |
| 57 void SpeechRecognizerImplAndroid::StartRecognitionOnUIThread( | 55 void SpeechRecognizerImplAndroid::StartRecognitionOnUIThread( |
| 58 const std::string& language, | 56 const std::string& language, |
| 59 bool continuous, | 57 bool continuous, |
| 60 bool interim_results) { | 58 bool interim_results) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 62 JNIEnv* env = AttachCurrentThread(); | 60 JNIEnv* env = AttachCurrentThread(); |
| 63 j_recognition_.Reset(Java_SpeechRecognition_createSpeechRecognition(env, | 61 j_recognition_.Reset(Java_SpeechRecognition_createSpeechRecognition( |
| 64 GetApplicationContext(), reinterpret_cast<intptr_t>(this))); | 62 env, reinterpret_cast<intptr_t>(this))); |
| 65 Java_SpeechRecognition_startRecognition( | 63 Java_SpeechRecognition_startRecognition( |
| 66 env, j_recognition_, ConvertUTF8ToJavaString(env, language), continuous, | 64 env, j_recognition_, ConvertUTF8ToJavaString(env, language), continuous, |
| 67 interim_results); | 65 interim_results); |
| 68 } | 66 } |
| 69 | 67 |
| 70 void SpeechRecognizerImplAndroid::AbortRecognition() { | 68 void SpeechRecognizerImplAndroid::AbortRecognition() { |
| 71 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 69 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 72 state_ = STATE_IDLE; | 70 state_ = STATE_IDLE; |
| 73 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 71 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 74 &content::SpeechRecognizerImplAndroid::AbortRecognition, this)); | 72 &content::SpeechRecognizerImplAndroid::AbortRecognition, this)); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 state_ = STATE_IDLE; | 218 state_ = STATE_IDLE; |
| 221 listener()->OnRecognitionEnd(session_id()); | 219 listener()->OnRecognitionEnd(session_id()); |
| 222 } | 220 } |
| 223 | 221 |
| 224 // static | 222 // static |
| 225 bool SpeechRecognizerImplAndroid::RegisterSpeechRecognizer(JNIEnv* env) { | 223 bool SpeechRecognizerImplAndroid::RegisterSpeechRecognizer(JNIEnv* env) { |
| 226 return RegisterNativesImpl(env); | 224 return RegisterNativesImpl(env); |
| 227 } | 225 } |
| 228 | 226 |
| 229 } // namespace content | 227 } // namespace content |
| OLD | NEW |