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

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

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/speech/speech_input_dispatcher_host.h" 5 #include "content/browser/speech/speech_input_dispatcher_host.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "content/browser/resource_context.h"
8 #include "content/browser/speech/speech_input_preferences.h" 9 #include "content/browser/speech/speech_input_preferences.h"
9 #include "content/common/speech_input_messages.h" 10 #include "content/common/speech_input_messages.h"
10 #include "content/public/browser/content_browser_client.h" 11 #include "content/public/browser/content_browser_client.h"
11 12
12 using content::BrowserThread; 13 using content::BrowserThread;
13 14
14 namespace speech_input { 15 namespace speech_input {
15 16
16 //----------------------------- SpeechInputCallers ----------------------------- 17 //----------------------------- SpeechInputCallers -----------------------------
17 18
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 108
108 SpeechInputManager* SpeechInputDispatcherHost::manager_; 109 SpeechInputManager* SpeechInputDispatcherHost::manager_;
109 110
110 void SpeechInputDispatcherHost::set_manager(SpeechInputManager* manager) { 111 void SpeechInputDispatcherHost::set_manager(SpeechInputManager* manager) {
111 manager_ = manager; 112 manager_ = manager;
112 } 113 }
113 114
114 SpeechInputDispatcherHost::SpeechInputDispatcherHost( 115 SpeechInputDispatcherHost::SpeechInputDispatcherHost(
115 int render_process_id, 116 int render_process_id,
116 net::URLRequestContextGetter* context_getter, 117 net::URLRequestContextGetter* context_getter,
117 SpeechInputPreferences* speech_input_preferences) 118 SpeechInputPreferences* speech_input_preferences,
119 const content::ResourceContext* resource_context)
118 : render_process_id_(render_process_id), 120 : render_process_id_(render_process_id),
119 may_have_pending_requests_(false), 121 may_have_pending_requests_(false),
120 context_getter_(context_getter), 122 context_getter_(context_getter),
121 speech_input_preferences_(speech_input_preferences) { 123 speech_input_preferences_(speech_input_preferences),
124 resource_context_(resource_context) {
122 // This is initialized by Browser. Do not add any non-trivial 125 // This is initialized by Browser. Do not add any non-trivial
123 // initialization here, instead do it lazily when required (e.g. see the 126 // initialization here, instead do it lazily when required (e.g. see the
124 // method |manager()|) or add an Init() method. 127 // method |manager()|) or add an Init() method.
125 } 128 }
126 129
127 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { 130 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() {
128 // If the renderer crashed for some reason or if we didn't receive a proper 131 // If the renderer crashed for some reason or if we didn't receive a proper
129 // Cancel/Stop call for an existing session, cancel such active sessions now. 132 // Cancel/Stop call for an existing session, cancel such active sessions now.
130 // We first check if this dispatcher received any speech IPC requst so that 133 // We first check if this dispatcher received any speech IPC requst so that
131 // we don't end up creating the speech input manager for web pages which don't 134 // we don't end up creating the speech input manager for web pages which don't
(...skipping 22 matching lines...) Expand all
154 OnStopRecording) 157 OnStopRecording)
155 IPC_MESSAGE_UNHANDLED(handled = false) 158 IPC_MESSAGE_UNHANDLED(handled = false)
156 IPC_END_MESSAGE_MAP() 159 IPC_END_MESSAGE_MAP()
157 if (handled) 160 if (handled)
158 may_have_pending_requests_ = true; 161 may_have_pending_requests_ = true;
159 return handled; 162 return handled;
160 } 163 }
161 164
162 void SpeechInputDispatcherHost::OnStartRecognition( 165 void SpeechInputDispatcherHost::OnStartRecognition(
163 const SpeechInputHostMsg_StartRecognition_Params &params) { 166 const SpeechInputHostMsg_StartRecognition_Params &params) {
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
164 int caller_id = g_speech_input_callers.Get().CreateId( 168 int caller_id = g_speech_input_callers.Get().CreateId(
165 render_process_id_, params.render_view_id, params.request_id); 169 render_process_id_, params.render_view_id, params.request_id);
166 manager()->StartRecognition(this, caller_id, 170 manager()->StartRecognition(this, caller_id,
167 render_process_id_, 171 render_process_id_,
168 params.render_view_id, params.element_rect, 172 params.render_view_id, params.element_rect,
169 params.language, params.grammar, 173 params.language, params.grammar,
170 params.origin_url, 174 params.origin_url,
171 context_getter_.get(), 175 context_getter_.get(),
172 speech_input_preferences_.get()); 176 speech_input_preferences_.get(),
177 resource_context_->audio_manager());
173 } 178 }
174 179
175 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, 180 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id,
176 int request_id) { 181 int request_id) {
177 int caller_id = g_speech_input_callers.Get().GetId( 182 int caller_id = g_speech_input_callers.Get().GetId(
178 render_process_id_, render_view_id, request_id); 183 render_process_id_, render_view_id, request_id);
179 if (caller_id) { 184 if (caller_id) {
180 manager()->CancelRecognition(caller_id); 185 manager()->CancelRecognition(caller_id);
181 // Request sequence ended so remove mapping. 186 // Request sequence ended so remove mapping.
182 g_speech_input_callers.Get().RemoveId(caller_id); 187 g_speech_input_callers.Get().RemoveId(caller_id);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 g_speech_input_callers.Get().render_view_id(caller_id); 227 g_speech_input_callers.Get().render_view_id(caller_id);
223 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); 228 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id);
224 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, 229 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id,
225 caller_request_id)); 230 caller_request_id));
226 // Request sequence ended, so remove mapping. 231 // Request sequence ended, so remove mapping.
227 g_speech_input_callers.Get().RemoveId(caller_id); 232 g_speech_input_callers.Get().RemoveId(caller_id);
228 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; 233 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit";
229 } 234 }
230 235
231 } // namespace speech_input 236 } // namespace speech_input
OLDNEW
« no previous file with comments | « content/browser/speech/speech_input_dispatcher_host.h ('k') | content/browser/speech/speech_input_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698