Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: chrome/browser/speech/speech_input_dispatcher_host.cc

Issue 6308009: If user had consented for metrics reporting, send speech input request origin to the server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/speech_input_messages.h"
9 9
10 namespace speech_input { 10 namespace speech_input {
11 11
12 //----------------------------- SpeechInputCallers ----------------------------- 12 //----------------------------- SpeechInputCallers -----------------------------
13 13
14 // A singleton class to map the tuple 14 // A singleton class to map the tuple
15 // (render-process-id, render-view-id, requestid) to a single ID which is passed 15 // (render-process-id, render-view-id, requestid) to a single ID which is passed
16 // through rest of the speech code. 16 // through rest of the speech code.
17 class SpeechInputDispatcherHost::SpeechInputCallers { 17 class SpeechInputDispatcherHost::SpeechInputCallers {
18 public: 18 public:
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
125 uint32 message_type = message.type(); 125 uint32 message_type = message.type();
126 if (message_type == ViewHostMsg_SpeechInput_StartRecognition::ID || 126 if (message_type == SpeechInputHostMsg_StartRecognition::ID ||
127 message_type == ViewHostMsg_SpeechInput_CancelRecognition::ID || 127 message_type == SpeechInputHostMsg_CancelRecognition::ID ||
128 message_type == ViewHostMsg_SpeechInput_StopRecording::ID) { 128 message_type == SpeechInputHostMsg_StopRecording::ID) {
129 if (!SpeechInputManager::IsFeatureEnabled()) { 129 if (!SpeechInputManager::IsFeatureEnabled()) {
130 *message_was_ok = false; 130 *message_was_ok = false;
131 return true; 131 return true;
132 } 132 }
133 133
134 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, 134 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message,
135 *message_was_ok) 135 *message_was_ok)
136 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, 136 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StartRecognition,
137 OnStartRecognition) 137 OnStartRecognition)
138 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, 138 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_CancelRecognition,
139 OnCancelRecognition) 139 OnCancelRecognition)
140 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, 140 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StopRecording,
141 OnStopRecording) 141 OnStopRecording)
142 IPC_END_MESSAGE_MAP() 142 IPC_END_MESSAGE_MAP()
143 return true; 143 return true;
144 } 144 }
145 145
146 return false; 146 return false;
147 } 147 }
148 148
149 void SpeechInputDispatcherHost::OnStartRecognition( 149 void SpeechInputDispatcherHost::OnStartRecognition(
150 int render_view_id, 150 const SpeechInputHostMsg_StartRecognition_Params &params) {
151 int request_id,
152 const gfx::Rect& element_rect,
153 const std::string& language,
154 const std::string& grammar) {
155 int caller_id = g_speech_input_callers.Get().CreateId( 151 int caller_id = g_speech_input_callers.Get().CreateId(
156 render_process_id_, render_view_id, request_id); 152 render_process_id_, params.render_view_id, params.request_id);
157 manager()->StartRecognition(this, caller_id, 153 manager()->StartRecognition(this, caller_id,
158 render_process_id_, 154 render_process_id_,
159 render_view_id, element_rect, 155 params.render_view_id, params.element_rect,
160 language, grammar); 156 params.language, params.grammar,
157 params.origin_url);
161 } 158 }
162 159
163 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, 160 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id,
164 int request_id) { 161 int request_id) {
165 int caller_id = g_speech_input_callers.Get().GetId( 162 int caller_id = g_speech_input_callers.Get().GetId(
166 render_process_id_, render_view_id, request_id); 163 render_process_id_, render_view_id, request_id);
167 if (caller_id) { 164 if (caller_id) {
168 manager()->CancelRecognition(caller_id); 165 manager()->CancelRecognition(caller_id);
169 // Request sequence ended so remove mapping. 166 // Request sequence ended so remove mapping.
170 g_speech_input_callers.Get().RemoveId(caller_id); 167 g_speech_input_callers.Get().RemoveId(caller_id);
171 } 168 }
172 } 169 }
173 170
174 void SpeechInputDispatcherHost::OnStopRecording(int render_view_id, 171 void SpeechInputDispatcherHost::OnStopRecording(int render_view_id,
175 int request_id) { 172 int request_id) {
176 int caller_id = g_speech_input_callers.Get().GetId( 173 int caller_id = g_speech_input_callers.Get().GetId(
177 render_process_id_, render_view_id, request_id); 174 render_process_id_, render_view_id, request_id);
178 if (caller_id) 175 if (caller_id)
179 manager()->StopRecording(caller_id); 176 manager()->StopRecording(caller_id);
180 } 177 }
181 178
182 void SpeechInputDispatcherHost::SetRecognitionResult( 179 void SpeechInputDispatcherHost::SetRecognitionResult(
183 int caller_id, const SpeechInputResultArray& result) { 180 int caller_id, const SpeechInputResultArray& result) {
184 VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult enter"; 181 VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult enter";
185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
186 int caller_render_view_id = 183 int caller_render_view_id =
187 g_speech_input_callers.Get().render_view_id(caller_id); 184 g_speech_input_callers.Get().render_view_id(caller_id);
188 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); 185 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id);
189 Send(new ViewMsg_SpeechInput_SetRecognitionResult(caller_render_view_id, 186 Send(new SpeechInputMsg_SetRecognitionResult(caller_render_view_id,
190 caller_request_id, 187 caller_request_id,
191 result)); 188 result));
192 VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult exit"; 189 VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult exit";
193 } 190 }
194 191
195 void SpeechInputDispatcherHost::DidCompleteRecording(int caller_id) { 192 void SpeechInputDispatcherHost::DidCompleteRecording(int caller_id) {
196 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording enter"; 193 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording enter";
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
198 int caller_render_view_id = 195 int caller_render_view_id =
199 g_speech_input_callers.Get().render_view_id(caller_id); 196 g_speech_input_callers.Get().render_view_id(caller_id);
200 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); 197 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id);
201 Send(new ViewMsg_SpeechInput_RecordingComplete(caller_render_view_id, 198 Send(new SpeechInputMsg_RecordingComplete(caller_render_view_id,
202 caller_request_id)); 199 caller_request_id));
203 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording exit"; 200 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording exit";
204 } 201 }
205 202
206 void SpeechInputDispatcherHost::DidCompleteRecognition(int caller_id) { 203 void SpeechInputDispatcherHost::DidCompleteRecognition(int caller_id) {
207 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition enter"; 204 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition enter";
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
209 int caller_render_view_id = 206 int caller_render_view_id =
210 g_speech_input_callers.Get().render_view_id(caller_id); 207 g_speech_input_callers.Get().render_view_id(caller_id);
211 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); 208 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id);
212 Send(new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id, 209 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id,
213 caller_request_id)); 210 caller_request_id));
214 // Request sequence ended, so remove mapping. 211 // Request sequence ended, so remove mapping.
215 g_speech_input_callers.Get().RemoveId(caller_id); 212 g_speech_input_callers.Get().RemoveId(caller_id);
216 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; 213 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit";
217 } 214 }
218 215
219 } // namespace speech_input 216 } // namespace speech_input
OLDNEW
« no previous file with comments | « chrome/browser/speech/speech_input_dispatcher_host.h ('k') | chrome/browser/speech/speech_input_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698