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

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

Issue 7729001: Get rid of link dependency from content to chrome. Make it get the SpeechInputManager through the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 "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/content_browser_client.h"
8 #include "content/common/speech_input_messages.h" 9 #include "content/common/speech_input_messages.h"
9 10
10 namespace speech_input { 11 namespace speech_input {
11 12
12 //----------------------------- SpeechInputCallers ----------------------------- 13 //----------------------------- SpeechInputCallers -----------------------------
13 14
14 // A singleton class to map the tuple 15 // A singleton class to map the tuple
15 // (render-process-id, render-view-id, requestid) to a single ID which is passed 16 // (render-process-id, render-view-id, requestid) to a single ID which is passed
16 // through rest of the speech code. 17 // through rest of the speech code.
17 class SpeechInputDispatcherHost::SpeechInputCallers { 18 class SpeechInputDispatcherHost::SpeechInputCallers {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int SpeechInputDispatcherHost::SpeechInputCallers::render_view_id(int id) { 95 int SpeechInputDispatcherHost::SpeechInputCallers::render_view_id(int id) {
95 return callers_[id].render_view_id; 96 return callers_[id].render_view_id;
96 } 97 }
97 98
98 int SpeechInputDispatcherHost::SpeechInputCallers::request_id(int id) { 99 int SpeechInputDispatcherHost::SpeechInputCallers::request_id(int id) {
99 return callers_[id].request_id; 100 return callers_[id].request_id;
100 } 101 }
101 102
102 //-------------------------- SpeechInputDispatcherHost ------------------------- 103 //-------------------------- SpeechInputDispatcherHost -------------------------
103 104
104 SpeechInputManager::AccessorMethod* 105 SpeechInputManager* SpeechInputDispatcherHost::manager_;
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 may_have_pending_requests_(false) {
110 // This is initialized by Browser. Do not add any non-trivial 110 // This is initialized by Browser. Do not add any non-trivial
111 // 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
112 // method |manager()|) or add an Init() method. 112 // method |manager()|) or add an Init() method.
113 } 113 }
114 114
115 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { 115 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() {
116 // If the renderer crashed for some reason or if we didn't receive a proper 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. 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 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 119 // we don't end up creating the speech input manager for web pages which don't
120 // use speech input. 120 // use speech input.
121 if (may_have_pending_requests_) 121 if (may_have_pending_requests_)
122 manager()->CancelAllRequestsWithDelegate(this); 122 manager()->CancelAllRequestsWithDelegate(this);
123 } 123 }
124 124
125 SpeechInputManager* SpeechInputDispatcherHost::manager() { 125 SpeechInputManager* SpeechInputDispatcherHost::manager() {
126 return (*manager_accessor_)(); 126 if (manager_)
127 return manager_;
128 return content::GetContentClient()->browser()->GetSpeechInputManager();
127 } 129 }
128 130
129 bool SpeechInputDispatcherHost::OnMessageReceived( 131 bool SpeechInputDispatcherHost::OnMessageReceived(
130 const IPC::Message& message, bool* message_was_ok) { 132 const IPC::Message& message, bool* message_was_ok) {
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
132 bool handled = true; 134 bool handled = true;
133 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, 135 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message,
134 *message_was_ok) 136 *message_was_ok)
135 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StartRecognition, 137 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StartRecognition,
136 OnStartRecognition) 138 OnStartRecognition)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 g_speech_input_callers.Get().render_view_id(caller_id); 208 g_speech_input_callers.Get().render_view_id(caller_id);
207 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); 209 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id);
208 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, 210 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id,
209 caller_request_id)); 211 caller_request_id));
210 // Request sequence ended, so remove mapping. 212 // Request sequence ended, so remove mapping.
211 g_speech_input_callers.Get().RemoveId(caller_id); 213 g_speech_input_callers.Get().RemoveId(caller_id);
212 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; 214 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit";
213 } 215 }
214 216
215 } // namespace speech_input 217 } // namespace speech_input
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698