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

Unified Diff: chrome/browser/speech/speech_input_dispatcher_host.cc

Issue 3035035: Adds chromium side plumbing to pass speech input calls back and forth with WebKit. (Closed)
Patch Set: Addressed all comments. Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/speech/speech_input_dispatcher_host.cc
diff --git a/chrome/browser/speech/speech_input_dispatcher_host.cc b/chrome/browser/speech/speech_input_dispatcher_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8346cbe47a9f05ea432bd39f975a22d8ddbcea55
--- /dev/null
+++ b/chrome/browser/speech/speech_input_dispatcher_host.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/speech/speech_input_dispatcher_host.h"
+
+#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/renderer_host/render_view_host_notification_task.h"
+#include "chrome/browser/renderer_host/resource_message_filter.h"
+#include "chrome/common/render_messages.h"
+
+namespace speech_input {
+
+SpeechInputManager::FactoryMethod*
+ SpeechInputDispatcherHost::manager_factory_ = &SpeechInputManager::Create;
+
+SpeechInputDispatcherHost::SpeechInputDispatcherHost(
+ int resource_message_filter_process_id)
+ : resource_message_filter_process_id_(resource_message_filter_process_id) {
+ // This is initialized by ResourceMessageFilter. Do not add any non-trivial
+ // initialization here, instead do it lazily when required (e.g. see the
+ // method |manager()|) or add an Init() method.
+}
+
+SpeechInputDispatcherHost::~SpeechInputDispatcherHost() {
+}
+
+SpeechInputManager* SpeechInputDispatcherHost::manager() {
+ if (!manager_.get()) {
+ manager_.reset((*manager_factory_)(this));
+ DCHECK(manager_.get());
+ }
+ return manager_.get();
+}
+
+bool SpeechInputDispatcherHost::OnMessageReceived(
+ const IPC::Message& msg, bool* msg_was_ok) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, msg, *msg_was_ok)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition,
+ OnStartRecognition)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition,
+ OnCancelRecognition)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording,
+ OnStopRecording)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void SpeechInputDispatcherHost::OnStartRecognition(int render_view_id) {
+ LOG(INFO) << "SpeechInputDispatcherHost: start recognition"
+ << render_view_id;
+ manager()->StartRecognition(render_view_id);
+}
+
+void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id) {
+ LOG(INFO) << "SpeechInputDispatcherHost: cancel recognition"
+ << render_view_id;
+ manager()->CancelRecognition(render_view_id);
+}
+
+void SpeechInputDispatcherHost::OnStopRecording(int render_view_id) {
+ LOG(INFO) << "SpeechInputDispatcherHost: stop recording"
+ << render_view_id;
+ manager()->StopRecording(render_view_id);
+}
+
+void SpeechInputDispatcherHost::SendMessageToRenderView(IPC::Message* message,
+ int render_view_id) {
+ CallRenderViewHost(
+ resource_message_filter_process_id_, render_view_id,
+ &RenderViewHost::Send, message);
+}
+
+
+void SpeechInputDispatcherHost::SetRecognitionResult(int render_view_id,
+ const string16& result) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ SendMessageToRenderView(
+ new ViewMsg_SpeechInput_SetRecognitionResult(render_view_id, result),
+ render_view_id);
+}
+
+void SpeechInputDispatcherHost::DidCompleteRecording(int render_view_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ SendMessageToRenderView(
+ new ViewMsg_SpeechInput_RecordingComplete(render_view_id),
+ render_view_id);
+}
+
+void SpeechInputDispatcherHost::DidCompleteRecognition(int render_view_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ SendMessageToRenderView(
+ new ViewMsg_SpeechInput_RecognitionComplete(render_view_id),
+ render_view_id);
+}
+
+} // namespace speech_input

Powered by Google App Engine
This is Rietveld 408576698