Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 "content/browser/speech/tts_dispatcher_host_impl.h" | |
| 6 | |
| 7 #include "content/public/browser/content_browser_client.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 TtsDispatcherHostImpl::TtsDispatcherHostImpl( | |
| 12 int render_process_id, | |
| 13 BrowserContext* browser_context) | |
| 14 : render_process_id_(render_process_id), | |
| 15 browser_context_(browser_context), | |
| 16 delegate_( | |
| 17 GetContentClient()->browser()->GetTtsDispatcherHostDelegate()) { | |
| 18 } | |
| 19 | |
| 20 TtsDispatcherHostImpl::~TtsDispatcherHostImpl() { | |
| 21 } | |
| 22 | |
| 23 BrowserContext* TtsDispatcherHostImpl::GetBrowserContext() { | |
| 24 return browser_context_; | |
| 25 } | |
| 26 | |
| 27 bool TtsDispatcherHostImpl::OnMessageReceived( | |
| 28 const IPC::Message& message, bool* message_was_ok) { | |
| 29 bool handled = true; | |
| 30 IPC_BEGIN_MESSAGE_MAP_EX(TtsDispatcherHostImpl, message, | |
| 31 *message_was_ok) | |
| 32 IPC_MESSAGE_HANDLER(TtsHostMsg_InitializeVoiceList, OnInitializeVoiceList) | |
| 33 IPC_MESSAGE_HANDLER(TtsHostMsg_Speak, OnSpeak) | |
| 34 IPC_MESSAGE_HANDLER(TtsHostMsg_Pause, OnPause) | |
| 35 IPC_MESSAGE_HANDLER(TtsHostMsg_Resume, OnResume) | |
| 36 IPC_MESSAGE_HANDLER(TtsHostMsg_Cancel, OnCancel) | |
| 37 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 38 IPC_END_MESSAGE_MAP() | |
| 39 return handled; | |
| 40 } | |
| 41 | |
| 42 void TtsDispatcherHostImpl::OnInitializeVoiceList(int routing_id) { | |
| 43 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 44 BrowserThread::PostTask( | |
| 45 BrowserThread::UI, FROM_HERE, | |
|
tommi (sloooow) - chröme
2013/03/07 13:04:46
out of curiosity, why do we do this on the ui thre
dmazzoni
2013/03/19 17:30:22
Currently TtsController is implemented on the UI t
tommi (sloooow) - chröme
2013/03/21 14:34:02
As is I can't tell if it's a good idea or not :)
L
| |
| 46 base::Bind(&TtsDispatcherHostImpl::OnInitializeVoiceList, | |
| 47 this, | |
| 48 routing_id)); | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 if (delegate_) | |
| 53 delegate_->OnInitializeVoiceList(this, routing_id); | |
| 54 } | |
| 55 | |
| 56 void TtsDispatcherHostImpl::OnSpeak(int routing_id, | |
| 57 const TtsUtteranceRequest& utterance) { | |
| 58 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 59 BrowserThread::PostTask( | |
| 60 BrowserThread::UI, FROM_HERE, | |
| 61 base::Bind(&TtsDispatcherHostImpl::OnSpeak, | |
| 62 this, | |
| 63 routing_id, | |
| 64 utterance)); | |
| 65 return; | |
| 66 } | |
| 67 | |
| 68 if (delegate_) | |
| 69 delegate_->OnSpeak(this, routing_id, utterance); | |
| 70 } | |
| 71 | |
| 72 void TtsDispatcherHostImpl::OnPause() { | |
| 73 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 74 BrowserThread::PostTask( | |
| 75 BrowserThread::UI, FROM_HERE, | |
| 76 base::Bind(&TtsDispatcherHostImpl::OnPause, this)); | |
| 77 return; | |
| 78 } | |
| 79 | |
| 80 if (delegate_) | |
| 81 delegate_->OnPause(this); | |
| 82 } | |
| 83 | |
| 84 void TtsDispatcherHostImpl::OnResume() { | |
| 85 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 86 BrowserThread::PostTask( | |
| 87 BrowserThread::UI, FROM_HERE, | |
| 88 base::Bind(&TtsDispatcherHostImpl::OnResume, this)); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 if (delegate_) | |
| 93 delegate_->OnResume(this); | |
| 94 } | |
| 95 | |
| 96 void TtsDispatcherHostImpl::OnCancel() { | |
| 97 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 98 BrowserThread::PostTask( | |
| 99 BrowserThread::UI, FROM_HERE, | |
| 100 base::Bind(&TtsDispatcherHostImpl::OnCancel, this)); | |
| 101 return; | |
| 102 } | |
| 103 | |
| 104 if (delegate_) | |
| 105 delegate_->OnCancel(this); | |
| 106 } | |
| 107 | |
| 108 void TtsDispatcherHostImpl::DidStartSpeaking(int routing_id, int utterance_id) { | |
| 109 Send(new TtsMsg_DidStartSpeaking(routing_id, utterance_id)); | |
| 110 } | |
| 111 | |
| 112 void TtsDispatcherHostImpl::DidFinishSpeaking( | |
| 113 int routing_id, int utterance_id) { | |
| 114 Send(new TtsMsg_DidFinishSpeaking(routing_id, utterance_id)); | |
| 115 } | |
| 116 | |
| 117 void TtsDispatcherHostImpl::DidPauseSpeaking( | |
| 118 int routing_id, int utterance_id) { | |
| 119 Send(new TtsMsg_DidPauseSpeaking(routing_id, utterance_id)); | |
| 120 } | |
| 121 | |
| 122 void TtsDispatcherHostImpl::DidResumeSpeaking( | |
| 123 int routing_id, int utterance_id) { | |
| 124 Send(new TtsMsg_DidResumeSpeaking(routing_id, utterance_id)); | |
| 125 } | |
| 126 | |
| 127 void TtsDispatcherHostImpl::WordBoundary( | |
| 128 int routing_id, int utterance_id, int char_index) { | |
| 129 Send(new TtsMsg_WordBoundary(routing_id, utterance_id, char_index)); | |
| 130 } | |
| 131 | |
| 132 void TtsDispatcherHostImpl::SentenceBoundary( | |
| 133 int routing_id, int utterance_id, int char_index) { | |
| 134 Send(new TtsMsg_SentenceBoundary(routing_id, utterance_id, char_index)); | |
| 135 } | |
| 136 | |
| 137 void TtsDispatcherHostImpl::MarkerEvent( | |
| 138 int routing_id, int utterance_id, int char_index) { | |
| 139 Send(new TtsMsg_MarkerEvent(routing_id, utterance_id, char_index)); | |
| 140 } | |
| 141 | |
| 142 void TtsDispatcherHostImpl::WasInterrupted(int routing_id, int utterance_id) { | |
| 143 Send(new TtsMsg_WasInterrupted(routing_id, utterance_id)); | |
| 144 } | |
| 145 | |
| 146 void TtsDispatcherHostImpl::WasCancelled(int routing_id, int utterance_id) { | |
| 147 Send(new TtsMsg_WasCancelled(routing_id, utterance_id)); | |
| 148 } | |
| 149 | |
| 150 void TtsDispatcherHostImpl::SpeakingErrorOccurred( | |
| 151 int routing_id, int utterance_id, const std::string& error_message) { | |
| 152 Send(new TtsMsg_SpeakingErrorOccurred( | |
| 153 routing_id, utterance_id, error_message)); | |
| 154 } | |
| 155 | |
| 156 void TtsDispatcherHostImpl::SendVoiceList( | |
| 157 int routing_id, | |
| 158 const std::vector<content::TtsVoice>& voices) { | |
| 159 Send(new TtsMsg_SetVoiceList(routing_id, voices)); | |
| 160 } | |
| 161 | |
| 162 } // namespace content | |
| OLD | NEW |