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/speech_input_messages.h" | 8 #include "chrome/common/speech_input_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 may_have_pending_requests_(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 (may_have_pending_requests_) |
| 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 == SpeechInputHostMsg_StartRecognition::ID || | 134 if (message_type == SpeechInputHostMsg_StartRecognition::ID || |
127 message_type == SpeechInputHostMsg_CancelRecognition::ID || | 135 message_type == SpeechInputHostMsg_CancelRecognition::ID || |
128 message_type == SpeechInputHostMsg_StopRecording::ID) { | 136 message_type == SpeechInputHostMsg_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 may_have_pending_requests_ = 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(SpeechInputHostMsg_StartRecognition, | 145 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StartRecognition, |
137 OnStartRecognition) | 146 OnStartRecognition) |
138 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_CancelRecognition, | 147 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_CancelRecognition, |
139 OnCancelRecognition) | 148 OnCancelRecognition) |
140 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StopRecording, | 149 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StopRecording, |
141 OnStopRecording) | 150 OnStopRecording) |
142 IPC_END_MESSAGE_MAP() | 151 IPC_END_MESSAGE_MAP() |
143 return true; | 152 return true; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 g_speech_input_callers.Get().render_view_id(caller_id); | 216 g_speech_input_callers.Get().render_view_id(caller_id); |
208 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); | 217 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); |
209 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, | 218 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, |
210 caller_request_id)); | 219 caller_request_id)); |
211 // Request sequence ended, so remove mapping. | 220 // Request sequence ended, so remove mapping. |
212 g_speech_input_callers.Get().RemoveId(caller_id); | 221 g_speech_input_callers.Get().RemoveId(caller_id); |
213 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; | 222 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; |
214 } | 223 } |
215 | 224 |
216 } // namespace speech_input | 225 } // namespace speech_input |
OLD | NEW |