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

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: Fixing memory leak in a test. Created 8 years, 4 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 scoped_ptr<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.Pass(),
220 utterance->profile(), 218 utterance->profile(),
221 GURL()); 219 GURL());
222 } 220 }
223 221
224 void ExtensionTtsEngineStop(Utterance* utterance) { 222 void ExtensionTtsEngineStop(Utterance* utterance) {
223 scoped_ptr<ListValue> args(new ListValue());
225 utterance->profile()->GetExtensionEventRouter()->DispatchEventToExtension( 224 utterance->profile()->GetExtensionEventRouter()->DispatchEventToExtension(
226 utterance->extension_id(), 225 utterance->extension_id(),
227 events::kOnStop, 226 events::kOnStop,
228 "[]", 227 args.Pass(),
229 utterance->profile(), 228 utterance->profile(),
230 GURL()); 229 GURL());
231 } 230 }
232 231
233 bool ExtensionTtsEngineSendTtsEventFunction::RunImpl() { 232 bool ExtensionTtsEngineSendTtsEventFunction::RunImpl() {
234 int utterance_id; 233 int utterance_id;
235 std::string error_message; 234 std::string error_message;
236 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &utterance_id)); 235 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &utterance_id));
237 236
238 DictionaryValue* event; 237 DictionaryValue* event;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 std::string error_message; 282 std::string error_message;
284 event->GetString(constants::kErrorMessageKey, &error_message); 283 event->GetString(constants::kErrorMessageKey, &error_message);
285 controller->OnTtsEvent( 284 controller->OnTtsEvent(
286 utterance_id, TTS_EVENT_ERROR, char_index, error_message); 285 utterance_id, TTS_EVENT_ERROR, char_index, error_message);
287 } else { 286 } else {
288 EXTENSION_FUNCTION_VALIDATE(false); 287 EXTENSION_FUNCTION_VALIDATE(false);
289 } 288 }
290 289
291 return true; 290 return true;
292 } 291 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_extension_api.cc ('k') | chrome/browser/speech/extension_api/tts_extension_api_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698