| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/speech/speech_input_dispatcher_host.h" | 5 #include "chrome/browser/speech/speech_input_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/renderer_host/render_process_host.h" |
| 8 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 9 | 10 |
| 10 namespace speech_input { | 11 namespace speech_input { |
| 11 | 12 |
| 12 //----------------------------- SpeechInputCallers ----------------------------- | 13 //----------------------------- SpeechInputCallers ----------------------------- |
| 13 | 14 |
| 14 // A singleton class to map the tuple | 15 // A singleton class to map the tuple |
| 15 // (render-process-id, render-view-id, requestid) to a single ID which is passed | 16 // (render-process-id, render-view-id, requestid) to a single ID which is passed |
| 16 // through rest of the speech code. | 17 // through rest of the speech code. |
| 17 class SpeechInputDispatcherHost::SpeechInputCallers { | 18 class SpeechInputDispatcherHost::SpeechInputCallers { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { | 115 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { |
| 115 } | 116 } |
| 116 | 117 |
| 117 SpeechInputManager* SpeechInputDispatcherHost::manager() { | 118 SpeechInputManager* SpeechInputDispatcherHost::manager() { |
| 118 return (*manager_accessor_)(); | 119 return (*manager_accessor_)(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 bool SpeechInputDispatcherHost::OnMessageReceived( | 122 bool SpeechInputDispatcherHost::OnMessageReceived( |
| 122 const IPC::Message& message, bool* message_was_ok) { | 123 const IPC::Message& message, bool* message_was_ok) { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 124 bool handled = true; | 125 |
| 125 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, *message_was_ok) | 126 uint32 message_type = message.type(); |
| 126 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, | 127 if (message_type == ViewHostMsg_SpeechInput_StartRecognition::ID || |
| 127 OnStartRecognition) | 128 message_type == ViewHostMsg_SpeechInput_CancelRecognition::ID || |
| 128 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, | 129 message_type == ViewHostMsg_SpeechInput_StopRecording::ID) { |
| 129 OnCancelRecognition) | 130 if (!SpeechInputManager::IsFeatureEnabled()) { |
| 130 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, | 131 RenderProcessHost::FromID(render_process_id_)->ReceivedBadMessage(); |
| 131 OnStopRecording) | 132 return false; |
| 132 IPC_MESSAGE_UNHANDLED(handled = false) | 133 } |
| 133 IPC_END_MESSAGE_MAP() | 134 |
| 134 return handled; | 135 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, |
| 136 *message_was_ok) |
| 137 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, |
| 138 OnStartRecognition) |
| 139 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, |
| 140 OnCancelRecognition) |
| 141 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, |
| 142 OnStopRecording) |
| 143 IPC_END_MESSAGE_MAP() |
| 144 return true; |
| 145 } |
| 146 |
| 147 return false; |
| 135 } | 148 } |
| 136 | 149 |
| 137 void SpeechInputDispatcherHost::OnStartRecognition( | 150 void SpeechInputDispatcherHost::OnStartRecognition( |
| 138 int render_view_id, | 151 int render_view_id, |
| 139 int request_id, | 152 int request_id, |
| 140 const gfx::Rect& element_rect, | 153 const gfx::Rect& element_rect, |
| 141 const std::string& language, | 154 const std::string& language, |
| 142 const std::string& grammar) { | 155 const std::string& grammar) { |
| 143 int caller_id = g_speech_input_callers.Get().CreateId( | 156 int caller_id = g_speech_input_callers.Get().CreateId( |
| 144 render_process_id_, render_view_id, request_id); | 157 render_process_id_, render_view_id, request_id); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 g_speech_input_callers.Get().render_view_id(caller_id); | 211 g_speech_input_callers.Get().render_view_id(caller_id); |
| 199 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); | 212 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); |
| 200 Send(new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id, | 213 Send(new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id, |
| 201 caller_request_id)); | 214 caller_request_id)); |
| 202 // Request sequence ended, so remove mapping. | 215 // Request sequence ended, so remove mapping. |
| 203 g_speech_input_callers.Get().RemoveId(caller_id); | 216 g_speech_input_callers.Get().RemoveId(caller_id); |
| 204 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; | 217 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; |
| 205 } | 218 } |
| 206 | 219 |
| 207 } // namespace speech_input | 220 } // namespace speech_input |
| OLD | NEW |