Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ | |
| 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/ref_counted.h" | |
| 10 #include "base/scoped_ptr.h" | |
| 11 #include "ipc/ipc_message.h" | |
| 12 #include "speech_input_manager.h" | |
| 13 | |
| 14 namespace speech_input { | |
| 15 | |
| 16 // SpeechInputDispatcherHost is a delegate for Speech API messages used by | |
| 17 // ResourceMessageFilter. | |
| 18 // It's the complement of SpeechInputDispatcher (owned by RenderView). | |
| 19 class SpeechInputDispatcherHost | |
| 20 : public base::RefCountedThreadSafe<SpeechInputDispatcherHost>, | |
| 21 public SpeechInputManager::Listener { | |
| 22 public: | |
| 23 explicit SpeechInputDispatcherHost(int resource_message_filter_process_id); | |
| 24 | |
| 25 // SpeechInputManager::Listener methods. | |
| 26 void SetRecognitionResult(int render_view_id, const string16& result); | |
| 27 void DidCompleteRecording(int render_view_id); | |
| 28 void DidCompleteRecognition(int render_view_id); | |
| 29 | |
| 30 // Called to possibly handle the incoming IPC message. Returns true if | |
| 31 // handled. | |
| 32 bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); | |
| 33 | |
| 34 // Factory setter useful for tests. | |
| 35 static void set_manager_factory(SpeechInputManager::FactoryMethod* factory) { | |
| 36 manager_factory_ = factory; | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 friend class base::RefCountedThreadSafe<SpeechInputDispatcherHost>; | |
| 41 virtual ~SpeechInputDispatcherHost(); | |
| 42 void SendMessageToRenderView(IPC::Message* message, int render_view_id); | |
| 43 | |
| 44 void OnStartRecognition(int render_view_id); | |
| 45 void OnCancelRecognition(int render_view_id); | |
| 46 void OnStopRecording(int render_view_id); | |
| 47 | |
| 48 // Returns the speech input manager to forward events to, creating one if | |
| 49 // needed. | |
| 50 SpeechInputManager* manager(); | |
| 51 | |
| 52 int resource_message_filter_process_id_; | |
| 53 | |
| 54 scoped_ptr<SpeechInputManager> manager_; | |
| 55 | |
| 56 // Set to non-NULL if overridden in tests, in which case this is used in | |
| 57 // place of the default factory method. | |
|
bulach
2010/08/04 19:29:05
obsolete comment?
| |
| 58 static SpeechInputManager::FactoryMethod* manager_factory_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(SpeechInputDispatcherHost); | |
| 61 }; | |
| 62 | |
| 63 } // namespace speech_input | |
| 64 | |
| 65 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ | |
| OLD | NEW |