| 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/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 9 | 9 |
| 10 namespace speech_input { | 10 namespace speech_input { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { | 114 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { |
| 115 } | 115 } |
| 116 | 116 |
| 117 SpeechInputManager* SpeechInputDispatcherHost::manager() { | 117 SpeechInputManager* SpeechInputDispatcherHost::manager() { |
| 118 return (*manager_accessor_)(); | 118 return (*manager_accessor_)(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool SpeechInputDispatcherHost::OnMessageReceived( | 121 bool SpeechInputDispatcherHost::OnMessageReceived( |
| 122 const IPC::Message& message, bool* message_was_ok) { | 122 const IPC::Message& message, bool* message_was_ok) { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 124 | 124 bool handled = true; |
| 125 uint32 message_type = message.type(); | 125 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, |
| 126 if (message_type == ViewHostMsg_SpeechInput_StartRecognition::ID || | 126 *message_was_ok) |
| 127 message_type == ViewHostMsg_SpeechInput_CancelRecognition::ID || | 127 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, |
| 128 message_type == ViewHostMsg_SpeechInput_StopRecording::ID) { | 128 OnStartRecognition) |
| 129 if (!SpeechInputManager::IsFeatureEnabled()) { | 129 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, |
| 130 *message_was_ok = false; | 130 OnCancelRecognition) |
| 131 return true; | 131 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, |
| 132 } | 132 OnStopRecording) |
| 133 | 133 IPC_MESSAGE_UNHANDLED(handled = false) |
| 134 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, | 134 IPC_END_MESSAGE_MAP() |
| 135 *message_was_ok) | 135 return handled; |
| 136 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, | |
| 137 OnStartRecognition) | |
| 138 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, | |
| 139 OnCancelRecognition) | |
| 140 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, | |
| 141 OnStopRecording) | |
| 142 IPC_END_MESSAGE_MAP() | |
| 143 return true; | |
| 144 } | |
| 145 | |
| 146 return false; | |
| 147 } | 136 } |
| 148 | 137 |
| 149 void SpeechInputDispatcherHost::OnStartRecognition( | 138 void SpeechInputDispatcherHost::OnStartRecognition( |
| 150 int render_view_id, | 139 int render_view_id, |
| 151 int request_id, | 140 int request_id, |
| 152 const gfx::Rect& element_rect, | 141 const gfx::Rect& element_rect, |
| 153 const std::string& language, | 142 const std::string& language, |
| 154 const std::string& grammar) { | 143 const std::string& grammar) { |
| 155 int caller_id = g_speech_input_callers.Get().CreateId( | 144 int caller_id = g_speech_input_callers.Get().CreateId( |
| 156 render_process_id_, render_view_id, request_id); | 145 render_process_id_, render_view_id, request_id); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 g_speech_input_callers.Get().render_view_id(caller_id); | 199 g_speech_input_callers.Get().render_view_id(caller_id); |
| 211 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); | 200 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); |
| 212 Send(new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id, | 201 Send(new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id, |
| 213 caller_request_id)); | 202 caller_request_id)); |
| 214 // Request sequence ended, so remove mapping. | 203 // Request sequence ended, so remove mapping. |
| 215 g_speech_input_callers.Get().RemoveId(caller_id); | 204 g_speech_input_callers.Get().RemoveId(caller_id); |
| 216 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; | 205 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; |
| 217 } | 206 } |
| 218 | 207 |
| 219 } // namespace speech_input | 208 } // namespace speech_input |
| OLD | NEW |