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

Side by Side Diff: chrome/browser/speech/extension_api/tts_engine_extension_api.cc

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and review changes. Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" 5 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 const Extension* extension, 181 const Extension* extension,
182 size_t voice_index) { 182 size_t voice_index) {
183 // See if the engine supports the "end" event; if so, we can keep the 183 // See if the engine supports the "end" event; if so, we can keep the
184 // utterance around and track it. If not, we're finished with this 184 // utterance around and track it. If not, we're finished with this
185 // utterance now. 185 // utterance now.
186 const std::set<std::string> event_types = 186 const std::set<std::string> event_types =
187 extension->tts_voices()[voice_index].event_types; 187 extension->tts_voices()[voice_index].event_types;
188 bool sends_end_event = 188 bool sends_end_event =
189 (event_types.find(constants::kEventTypeEnd) != event_types.end()); 189 (event_types.find(constants::kEventTypeEnd) != event_types.end());
190 190
191 ListValue args; 191 ListValue* args = new ListValue();
192 args.Set(0, Value::CreateStringValue(utterance->text())); 192 args->Set(0, Value::CreateStringValue(utterance->text()));
193 193
194 // Pass through most options to the speech engine, but remove some 194 // Pass through most options to the speech engine, but remove some
195 // that are handled internally. 195 // that are handled internally.
196 DictionaryValue* options = static_cast<DictionaryValue*>( 196 DictionaryValue* options = static_cast<DictionaryValue*>(
197 utterance->options()->DeepCopy()); 197 utterance->options()->DeepCopy());
198 if (options->HasKey(constants::kRequiredEventTypesKey)) 198 if (options->HasKey(constants::kRequiredEventTypesKey))
199 options->Remove(constants::kRequiredEventTypesKey, NULL); 199 options->Remove(constants::kRequiredEventTypesKey, NULL);
200 if (options->HasKey(constants::kDesiredEventTypesKey)) 200 if (options->HasKey(constants::kDesiredEventTypesKey))
201 options->Remove(constants::kDesiredEventTypesKey, NULL); 201 options->Remove(constants::kDesiredEventTypesKey, NULL);
202 if (sends_end_event && options->HasKey(constants::kEnqueueKey)) 202 if (sends_end_event && options->HasKey(constants::kEnqueueKey))
203 options->Remove(constants::kEnqueueKey, NULL); 203 options->Remove(constants::kEnqueueKey, NULL);
204 if (options->HasKey(constants::kSrcIdKey)) 204 if (options->HasKey(constants::kSrcIdKey))
205 options->Remove(constants::kSrcIdKey, NULL); 205 options->Remove(constants::kSrcIdKey, NULL);
206 if (options->HasKey(constants::kIsFinalEventKey)) 206 if (options->HasKey(constants::kIsFinalEventKey))
207 options->Remove(constants::kIsFinalEventKey, NULL); 207 options->Remove(constants::kIsFinalEventKey, NULL);
208 if (options->HasKey(constants::kOnEventKey)) 208 if (options->HasKey(constants::kOnEventKey))
209 options->Remove(constants::kOnEventKey, NULL); 209 options->Remove(constants::kOnEventKey, NULL);
210 210
211 args.Set(1, options); 211 args->Set(1, options);
212 args.Set(2, Value::CreateIntegerValue(utterance->id())); 212 args->Set(2, Value::CreateIntegerValue(utterance->id()));
213 std::string json_args;
214 base::JSONWriter::Write(&args, &json_args);
215 213
216 utterance->profile()->GetExtensionEventRouter()->DispatchEventToExtension( 214 utterance->profile()->GetExtensionEventRouter()->DispatchEventToExtension(
217 extension->id(), 215 extension->id(),
218 events::kOnSpeak, 216 events::kOnSpeak,
219 json_args, 217 args,
220 utterance->profile(), 218 utterance->profile(),
221 GURL()); 219 GURL());
222 } 220 }
223 221
224 void ExtensionTtsEngineStop(Utterance* utterance) { 222 void ExtensionTtsEngineStop(Utterance* utterance) {
225 utterance->profile()->GetExtensionEventRouter()->DispatchEventToExtension( 223 utterance->profile()->GetExtensionEventRouter()->DispatchEventToExtension(
226 utterance->extension_id(), 224 utterance->extension_id(),
227 events::kOnStop, 225 events::kOnStop,
228 "[]", 226 NULL,
229 utterance->profile(), 227 utterance->profile(),
230 GURL()); 228 GURL());
231 } 229 }
232 230
233 bool ExtensionTtsEngineSendTtsEventFunction::RunImpl() { 231 bool ExtensionTtsEngineSendTtsEventFunction::RunImpl() {
234 int utterance_id; 232 int utterance_id;
235 std::string error_message; 233 std::string error_message;
236 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &utterance_id)); 234 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &utterance_id));
237 235
238 DictionaryValue* event; 236 DictionaryValue* event;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 std::string error_message; 281 std::string error_message;
284 event->GetString(constants::kErrorMessageKey, &error_message); 282 event->GetString(constants::kErrorMessageKey, &error_message);
285 controller->OnTtsEvent( 283 controller->OnTtsEvent(
286 utterance_id, TTS_EVENT_ERROR, char_index, error_message); 284 utterance_id, TTS_EVENT_ERROR, char_index, error_message);
287 } else { 285 } else {
288 EXTENSION_FUNCTION_VALIDATE(false); 286 EXTENSION_FUNCTION_VALIDATE(false);
289 } 287 }
290 288
291 return true; 289 return true;
292 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698