| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ |
| 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ | 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/ref_counted.h" | |
| 10 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "chrome/browser/browser_message_filter.h" |
| 11 #include "chrome/browser/speech/speech_input_manager.h" | 10 #include "chrome/browser/speech/speech_input_manager.h" |
| 12 #include "ipc/ipc_message.h" | |
| 13 | 11 |
| 14 namespace speech_input { | 12 namespace speech_input { |
| 15 | 13 |
| 16 // SpeechInputDispatcherHost is a delegate for Speech API messages used by | 14 // SpeechInputDispatcherHost is a delegate for Speech API messages used by |
| 17 // ResourceMessageFilter. | 15 // ResourceMessageFilter. |
| 18 // It's the complement of SpeechInputDispatcher (owned by RenderView). | 16 // It's the complement of SpeechInputDispatcher (owned by RenderView). |
| 19 class SpeechInputDispatcherHost | 17 class SpeechInputDispatcherHost : public BrowserMessageFilter, |
| 20 : public base::RefCountedThreadSafe<SpeechInputDispatcherHost>, | 18 public SpeechInputManager::Delegate { |
| 21 public SpeechInputManager::Delegate { | |
| 22 public: | 19 public: |
| 23 class SpeechInputCallers; | 20 class SpeechInputCallers; |
| 24 | 21 |
| 25 explicit SpeechInputDispatcherHost(int resource_message_filter_process_id); | 22 explicit SpeechInputDispatcherHost(int render_process_id); |
| 26 | 23 |
| 27 // SpeechInputManager::Delegate methods. | 24 // SpeechInputManager::Delegate methods. |
| 28 virtual void SetRecognitionResult(int caller_id, | 25 virtual void SetRecognitionResult(int caller_id, |
| 29 const SpeechInputResultArray& result); | 26 const SpeechInputResultArray& result); |
| 30 virtual void DidCompleteRecording(int caller_id); | 27 virtual void DidCompleteRecording(int caller_id); |
| 31 virtual void DidCompleteRecognition(int caller_id); | 28 virtual void DidCompleteRecognition(int caller_id); |
| 32 | 29 |
| 33 // Called to possibly handle the incoming IPC message. Returns true if | 30 // BrowserMessageFilter implementation. |
| 34 // handled. | 31 virtual bool OnMessageReceived(const IPC::Message& message, |
| 35 bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); | 32 bool* message_was_ok); |
| 36 | 33 |
| 37 // Singleton accessor setter useful for tests. | 34 // Singleton accessor setter useful for tests. |
| 38 static void set_manager_accessor(SpeechInputManager::AccessorMethod* method) { | 35 static void set_manager_accessor(SpeechInputManager::AccessorMethod* method) { |
| 39 manager_accessor_ = method; | 36 manager_accessor_ = method; |
| 40 } | 37 } |
| 41 | 38 |
| 42 private: | 39 private: |
| 43 friend class base::RefCountedThreadSafe<SpeechInputDispatcherHost>; | |
| 44 | |
| 45 virtual ~SpeechInputDispatcherHost(); | 40 virtual ~SpeechInputDispatcherHost(); |
| 46 void SendMessageToRenderView(IPC::Message* message, int render_view_id); | |
| 47 | 41 |
| 48 void OnStartRecognition(int render_view_id, int request_id, | 42 void OnStartRecognition(int render_view_id, int request_id, |
| 49 const gfx::Rect& element_rect, | 43 const gfx::Rect& element_rect, |
| 50 const std::string& language, | 44 const std::string& language, |
| 51 const std::string& grammar); | 45 const std::string& grammar); |
| 52 void OnCancelRecognition(int render_view_id, int request_id); | 46 void OnCancelRecognition(int render_view_id, int request_id); |
| 53 void OnStopRecording(int render_view_id, int request_id); | 47 void OnStopRecording(int render_view_id, int request_id); |
| 54 | 48 |
| 55 // Returns the speech input manager to forward events to, creating one if | 49 // Returns the speech input manager to forward events to, creating one if |
| 56 // needed. | 50 // needed. |
| 57 SpeechInputManager* manager(); | 51 SpeechInputManager* manager(); |
| 58 | 52 |
| 59 int resource_message_filter_process_id_; | 53 int render_process_id_; |
| 60 | 54 |
| 61 static SpeechInputManager::AccessorMethod* manager_accessor_; | 55 static SpeechInputManager::AccessorMethod* manager_accessor_; |
| 62 | 56 |
| 63 DISALLOW_COPY_AND_ASSIGN(SpeechInputDispatcherHost); | 57 DISALLOW_COPY_AND_ASSIGN(SpeechInputDispatcherHost); |
| 64 }; | 58 }; |
| 65 | 59 |
| 66 } // namespace speech_input | 60 } // namespace speech_input |
| 67 | 61 |
| 68 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ | 62 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ |
| OLD | NEW |