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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 int SpeechInputDispatcherHost::SpeechInputCallers::request_id(int id) { | 98 int SpeechInputDispatcherHost::SpeechInputCallers::request_id(int id) { |
99 return callers_[id].request_id; | 99 return callers_[id].request_id; |
100 } | 100 } |
101 | 101 |
102 //-------------------------- SpeechInputDispatcherHost ------------------------- | 102 //-------------------------- SpeechInputDispatcherHost ------------------------- |
103 | 103 |
104 SpeechInputManager::AccessorMethod* | 104 SpeechInputManager::AccessorMethod* |
105 SpeechInputDispatcherHost::manager_accessor_ = &SpeechInputManager::Get; | 105 SpeechInputDispatcherHost::manager_accessor_ = &SpeechInputManager::Get; |
106 | 106 |
107 SpeechInputDispatcherHost::SpeechInputDispatcherHost(int render_process_id) | 107 SpeechInputDispatcherHost::SpeechInputDispatcherHost(int render_process_id) |
108 : render_process_id_(render_process_id) { | 108 : render_process_id_(render_process_id), |
109 received_speech_request_(false) { | |
109 // This is initialized by Browser. Do not add any non-trivial | 110 // This is initialized by Browser. Do not add any non-trivial |
110 // initialization here, instead do it lazily when required (e.g. see the | 111 // initialization here, instead do it lazily when required (e.g. see the |
111 // method |manager()|) or add an Init() method. | 112 // method |manager()|) or add an Init() method. |
112 } | 113 } |
113 | 114 |
114 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { | 115 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { |
116 // If the renderer crashed for some reason or if we didn't receive a proper | |
117 // Cancel/Stop call for an existing session, cancel such active sessions now. | |
118 // We first check if this dispatcher received any speech IPC requst so that | |
119 // we don't end up creating the speech input manager for web pages which don't | |
120 // use speech input. | |
121 if (received_speech_request_) | |
bulach
2011/01/20 14:47:20
suggest: may_have_pending_requests_ ?
it seems sli
Satish
2011/01/20 15:09:03
Done.
| |
122 manager()->CancelAllRequestsWithDelegate(this); | |
115 } | 123 } |
116 | 124 |
117 SpeechInputManager* SpeechInputDispatcherHost::manager() { | 125 SpeechInputManager* SpeechInputDispatcherHost::manager() { |
118 return (*manager_accessor_)(); | 126 return (*manager_accessor_)(); |
119 } | 127 } |
120 | 128 |
121 bool SpeechInputDispatcherHost::OnMessageReceived( | 129 bool SpeechInputDispatcherHost::OnMessageReceived( |
122 const IPC::Message& message, bool* message_was_ok) { | 130 const IPC::Message& message, bool* message_was_ok) { |
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
124 | 132 |
125 uint32 message_type = message.type(); | 133 uint32 message_type = message.type(); |
126 if (message_type == ViewHostMsg_SpeechInput_StartRecognition::ID || | 134 if (message_type == ViewHostMsg_SpeechInput_StartRecognition::ID || |
127 message_type == ViewHostMsg_SpeechInput_CancelRecognition::ID || | 135 message_type == ViewHostMsg_SpeechInput_CancelRecognition::ID || |
128 message_type == ViewHostMsg_SpeechInput_StopRecording::ID) { | 136 message_type == ViewHostMsg_SpeechInput_StopRecording::ID) { |
129 if (!SpeechInputManager::IsFeatureEnabled()) { | 137 if (!SpeechInputManager::IsFeatureEnabled()) { |
130 *message_was_ok = false; | 138 *message_was_ok = false; |
131 return true; | 139 return true; |
132 } | 140 } |
133 | 141 |
142 received_speech_request_ = true; | |
134 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, | 143 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, |
135 *message_was_ok) | 144 *message_was_ok) |
136 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, | 145 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, |
137 OnStartRecognition) | 146 OnStartRecognition) |
138 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, | 147 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, |
139 OnCancelRecognition) | 148 OnCancelRecognition) |
140 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, | 149 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, |
141 OnStopRecording) | 150 OnStopRecording) |
142 IPC_END_MESSAGE_MAP() | 151 IPC_END_MESSAGE_MAP() |
143 return true; | 152 return true; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 g_speech_input_callers.Get().render_view_id(caller_id); | 219 g_speech_input_callers.Get().render_view_id(caller_id); |
211 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); | 220 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); |
212 Send(new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id, | 221 Send(new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id, |
213 caller_request_id)); | 222 caller_request_id)); |
214 // Request sequence ended, so remove mapping. | 223 // Request sequence ended, so remove mapping. |
215 g_speech_input_callers.Get().RemoveId(caller_id); | 224 g_speech_input_callers.Get().RemoveId(caller_id); |
216 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; | 225 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; |
217 } | 226 } |
218 | 227 |
219 } // namespace speech_input | 228 } // namespace speech_input |
OLD | NEW |