Chromium Code Reviews

Side by Side 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, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/speech/speech_input_dispatcher_host.h"
6
7 #include "chrome/browser/renderer_host/render_process_host.h"
8 #include "chrome/browser/renderer_host/render_view_host.h"
9 #include "chrome/browser/renderer_host/render_view_host_notification_task.h"
10 #include "chrome/browser/renderer_host/resource_message_filter.h"
11 #include "chrome/common/render_messages.h"
12
13 namespace speech_input {
14
15 SpeechInputManager::FactoryMethod*
16 SpeechInputDispatcherHost::manager_factory_ = &SpeechInputManager::Create;
17
18 SpeechInputDispatcherHost::SpeechInputDispatcherHost(
19 int resource_message_filter_process_id)
20 : resource_message_filter_process_id_(resource_message_filter_process_id) {
21 // This is initialized by ResourceMessageFilter. Do not add any non-trivial
22 // initialization here, instead do it lazily when required (e.g. see the
23 // method |manager()|) or add an Init() method.
24 }
25
26 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() {
27 }
28
29 SpeechInputManager* SpeechInputDispatcherHost::manager() {
30 if (!manager_.get()) {
31 manager_.reset((*manager_factory_)(this));
32 DCHECK(manager_.get());
33 }
34 return manager_.get();
35 }
36
37 bool SpeechInputDispatcherHost::OnMessageReceived(
38 const IPC::Message& msg, bool* msg_was_ok) {
39 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
40 bool handled = true;
41 IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, msg, *msg_was_ok)
42 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition,
43 OnStartRecognition)
44 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition,
45 OnCancelRecognition)
46 IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording,
47 OnStopRecording)
48 IPC_MESSAGE_UNHANDLED(handled = false)
49 IPC_END_MESSAGE_MAP()
50 return handled;
51 }
52
53 void SpeechInputDispatcherHost::OnStartRecognition(int render_view_id) {
54 LOG(INFO) << "SpeechInputDispatcherHost: start recognition"
55 << render_view_id;
56 manager()->StartRecognition(render_view_id);
57 }
58
59 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id) {
60 LOG(INFO) << "SpeechInputDispatcherHost: cancel recognition"
61 << render_view_id;
62 manager()->CancelRecognition(render_view_id);
63 }
64
65 void SpeechInputDispatcherHost::OnStopRecording(int render_view_id) {
66 LOG(INFO) << "SpeechInputDispatcherHost: stop recording"
67 << render_view_id;
68 manager()->StopRecording(render_view_id);
69 }
70
71 void SpeechInputDispatcherHost::SendMessageToRenderView(IPC::Message* message,
72 int render_view_id) {
73 CallRenderViewHost(
74 resource_message_filter_process_id_, render_view_id,
75 &RenderViewHost::Send, message);
76 }
77
78
79 void SpeechInputDispatcherHost::SetRecognitionResult(int render_view_id,
80 const string16& result) {
81 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
82 SendMessageToRenderView(
83 new ViewMsg_SpeechInput_SetRecognitionResult(render_view_id, result),
84 render_view_id);
85 }
86
87 void SpeechInputDispatcherHost::DidCompleteRecording(int render_view_id) {
88 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
89 SendMessageToRenderView(
90 new ViewMsg_SpeechInput_RecordingComplete(render_view_id),
91 render_view_id);
92 }
93
94 void SpeechInputDispatcherHost::DidCompleteRecognition(int render_view_id) {
95 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
96 SendMessageToRenderView(
97 new ViewMsg_SpeechInput_RecognitionComplete(render_view_id),
98 render_view_id);
99 }
100
101 } // namespace speech_input
OLDNEW

Powered by Google App Engine