| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_speech_recognition_manager_delegate.h" | 5 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 ChromeSpeechRecognitionManagerDelegate::ChromeSpeechRecognitionManagerDelegate() | 98 ChromeSpeechRecognitionManagerDelegate::ChromeSpeechRecognitionManagerDelegate() |
| 99 : bubble_controller_(new SpeechRecognitionBubbleController( | 99 : bubble_controller_(new SpeechRecognitionBubbleController( |
| 100 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { | 100 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { |
| 101 } | 101 } |
| 102 | 102 |
| 103 ChromeSpeechRecognitionManagerDelegate:: | 103 ChromeSpeechRecognitionManagerDelegate:: |
| 104 ~ChromeSpeechRecognitionManagerDelegate() { | 104 ~ChromeSpeechRecognitionManagerDelegate() { |
| 105 } | 105 } |
| 106 | 106 |
| 107 void ChromeSpeechRecognitionManagerDelegate::ShowRecognitionRequested( | 107 void ChromeSpeechRecognitionManagerDelegate::ShowRecognitionRequested( |
| 108 int caller_id, | 108 int session_id, |
| 109 int render_process_id, | 109 int render_process_id, |
| 110 int render_view_id, | 110 int render_view_id, |
| 111 const gfx::Rect& element_rect) { | 111 const gfx::Rect& element_rect) { |
| 112 bubble_controller_->CreateBubble(caller_id, render_process_id, | 112 bubble_controller_->CreateBubble(session_id, render_process_id, |
| 113 render_view_id, element_rect); | 113 render_view_id, element_rect); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void ChromeSpeechRecognitionManagerDelegate::GetRequestInfo( | 116 void ChromeSpeechRecognitionManagerDelegate::GetRequestInfo( |
| 117 bool* can_report_metrics, | 117 bool* can_report_metrics, |
| 118 std::string* request_info) { | 118 std::string* request_info) { |
| 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 120 if (!optional_request_info_.get()) { | 120 if (!optional_request_info_.get()) { |
| 121 optional_request_info_ = new OptionalRequestInfo(); | 121 optional_request_info_ = new OptionalRequestInfo(); |
| 122 // Since hardware info is optional with speech input requests, we start an | 122 // Since hardware info is optional with speech input requests, we start an |
| 123 // asynchronous fetch here and move on with recording audio. This first | 123 // asynchronous fetch here and move on with recording audio. This first |
| 124 // speech input request would send an empty string for hardware info and | 124 // speech input request would send an empty string for hardware info and |
| 125 // subsequent requests may have the hardware info available if the fetch | 125 // subsequent requests may have the hardware info available if the fetch |
| 126 // completed before them. This way we don't end up stalling the user with | 126 // completed before them. This way we don't end up stalling the user with |
| 127 // a long wait and disk seeks when they click on a UI element and start | 127 // a long wait and disk seeks when they click on a UI element and start |
| 128 // speaking. | 128 // speaking. |
| 129 optional_request_info_->Refresh(); | 129 optional_request_info_->Refresh(); |
| 130 } | 130 } |
| 131 *can_report_metrics = optional_request_info_->can_report_metrics(); | 131 *can_report_metrics = optional_request_info_->can_report_metrics(); |
| 132 *request_info = optional_request_info_->value(); | 132 *request_info = optional_request_info_->value(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void ChromeSpeechRecognitionManagerDelegate::ShowWarmUp(int caller_id) { | 135 void ChromeSpeechRecognitionManagerDelegate::ShowWarmUp(int session_id) { |
| 136 bubble_controller_->SetBubbleWarmUpMode(caller_id); | 136 bubble_controller_->SetBubbleWarmUpMode(session_id); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ChromeSpeechRecognitionManagerDelegate::ShowRecognizing(int caller_id) { | 139 void ChromeSpeechRecognitionManagerDelegate::ShowRecognizing(int session_id) { |
| 140 bubble_controller_->SetBubbleRecognizingMode(caller_id); | 140 bubble_controller_->SetBubbleRecognizingMode(session_id); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ChromeSpeechRecognitionManagerDelegate::ShowRecording(int caller_id) { | 143 void ChromeSpeechRecognitionManagerDelegate::ShowRecording(int session_id) { |
| 144 bubble_controller_->SetBubbleRecordingMode(caller_id); | 144 bubble_controller_->SetBubbleRecordingMode(session_id); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void ChromeSpeechRecognitionManagerDelegate::ShowInputVolume( | 147 void ChromeSpeechRecognitionManagerDelegate::ShowInputVolume( |
| 148 int caller_id, float volume, float noise_volume) { | 148 int session_id, float volume, float noise_volume) { |
| 149 bubble_controller_->SetBubbleInputVolume(caller_id, volume, noise_volume); | 149 bubble_controller_->SetBubbleInputVolume(session_id, volume, noise_volume); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void ChromeSpeechRecognitionManagerDelegate::ShowMicError(int caller_id, | 152 void ChromeSpeechRecognitionManagerDelegate::ShowMicError(int session_id, |
| 153 MicError error) { | 153 MicError error) { |
| 154 switch (error) { | 154 switch (error) { |
| 155 case MIC_ERROR_NO_DEVICE_AVAILABLE: | 155 case MIC_ERROR_NO_DEVICE_AVAILABLE: |
| 156 bubble_controller_->SetBubbleMessage( | 156 bubble_controller_->SetBubbleMessage( |
| 157 caller_id, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_NO_MIC)); | 157 session_id, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_NO_MIC)); |
| 158 break; | 158 break; |
| 159 | 159 |
| 160 case MIC_ERROR_DEVICE_IN_USE: | 160 case MIC_ERROR_DEVICE_IN_USE: |
| 161 bubble_controller_->SetBubbleMessage( | 161 bubble_controller_->SetBubbleMessage( |
| 162 caller_id, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_IN_USE)); | 162 session_id, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_IN_USE)); |
| 163 break; | 163 break; |
| 164 | 164 |
| 165 default: | 165 default: |
| 166 NOTREACHED(); | 166 NOTREACHED(); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 void ChromeSpeechRecognitionManagerDelegate::ShowRecognizerError( | 170 void ChromeSpeechRecognitionManagerDelegate::ShowRecognizerError( |
| 171 int caller_id, content::SpeechRecognitionErrorCode error) { | 171 int session_id, content::SpeechRecognitionErrorCode error) { |
| 172 struct ErrorMessageMapEntry { | 172 struct ErrorMessageMapEntry { |
| 173 content::SpeechRecognitionErrorCode error; | 173 content::SpeechRecognitionErrorCode error; |
| 174 int message_id; | 174 int message_id; |
| 175 }; | 175 }; |
| 176 ErrorMessageMapEntry error_message_map[] = { | 176 ErrorMessageMapEntry error_message_map[] = { |
| 177 { | 177 { |
| 178 content::SPEECH_RECOGNITION_ERROR_AUDIO, IDS_SPEECH_INPUT_MIC_ERROR | 178 content::SPEECH_RECOGNITION_ERROR_AUDIO, IDS_SPEECH_INPUT_MIC_ERROR |
| 179 }, { | 179 }, { |
| 180 content::SPEECH_RECOGNITION_ERROR_NO_SPEECH, IDS_SPEECH_INPUT_NO_SPEECH | 180 content::SPEECH_RECOGNITION_ERROR_NO_SPEECH, IDS_SPEECH_INPUT_NO_SPEECH |
| 181 }, { | 181 }, { |
| 182 content::SPEECH_RECOGNITION_ERROR_NO_MATCH, IDS_SPEECH_INPUT_NO_RESULTS | 182 content::SPEECH_RECOGNITION_ERROR_NO_MATCH, IDS_SPEECH_INPUT_NO_RESULTS |
| 183 }, { | 183 }, { |
| 184 content::SPEECH_RECOGNITION_ERROR_NETWORK, IDS_SPEECH_INPUT_NET_ERROR | 184 content::SPEECH_RECOGNITION_ERROR_NETWORK, IDS_SPEECH_INPUT_NET_ERROR |
| 185 } | 185 } |
| 186 }; | 186 }; |
| 187 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(error_message_map); ++i) { | 187 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(error_message_map); ++i) { |
| 188 if (error_message_map[i].error == error) { | 188 if (error_message_map[i].error == error) { |
| 189 bubble_controller_->SetBubbleMessage( | 189 bubble_controller_->SetBubbleMessage( |
| 190 caller_id, | 190 session_id, |
| 191 l10n_util::GetStringUTF16(error_message_map[i].message_id)); | 191 l10n_util::GetStringUTF16(error_message_map[i].message_id)); |
| 192 return; | 192 return; |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 NOTREACHED() << "unknown error " << error; | 196 NOTREACHED() << "unknown error " << error; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void ChromeSpeechRecognitionManagerDelegate::DoClose(int caller_id) { | 199 void ChromeSpeechRecognitionManagerDelegate::DoClose(int session_id) { |
| 200 bubble_controller_->CloseBubble(caller_id); | 200 bubble_controller_->CloseBubble(session_id); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void ChromeSpeechRecognitionManagerDelegate::InfoBubbleButtonClicked( | 203 void ChromeSpeechRecognitionManagerDelegate::InfoBubbleButtonClicked( |
| 204 int caller_id, SpeechRecognitionBubble::Button button) { | 204 int session_id, SpeechRecognitionBubble::Button button) { |
| 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 206 | 206 |
| 207 if (button == SpeechRecognitionBubble::BUTTON_CANCEL) { | 207 if (button == SpeechRecognitionBubble::BUTTON_CANCEL) { |
| 208 SpeechRecognitionManager::GetInstance()->CancelRecognitionForRequest( | 208 SpeechRecognitionManager::GetInstance()->CancelRecognitionForRequest( |
| 209 caller_id); | 209 session_id); |
| 210 } else if (button == SpeechRecognitionBubble::BUTTON_TRY_AGAIN) { | 210 } else if (button == SpeechRecognitionBubble::BUTTON_TRY_AGAIN) { |
| 211 SpeechRecognitionManager::GetInstance()->StartRecognitionForRequest( | 211 SpeechRecognitionManager::GetInstance()->StartRecognitionForRequest( |
| 212 caller_id); | 212 session_id); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 void ChromeSpeechRecognitionManagerDelegate::InfoBubbleFocusChanged( | 216 void ChromeSpeechRecognitionManagerDelegate::InfoBubbleFocusChanged( |
| 217 int caller_id) { | 217 int session_id) { |
| 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 219 SpeechRecognitionManager::GetInstance()->FocusLostForRequest(caller_id); | 219 SpeechRecognitionManager::GetInstance()->FocusLostForRequest(session_id); |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace speech | 222 } // namespace speech |
| OLD | NEW |